-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of JSON Web Token #743
Conversation
@yegor256 please, pay attention to this pull request |
Job |
+15 points just awarded to @semantosoph, total is +15. |
Codecov Report
@@ Coverage Diff @@
## master #743 +/- ##
============================================
- Coverage 77.55% 76.72% -0.83%
- Complexity 900 912 +12
============================================
Files 205 208 +3
Lines 4245 4348 +103
Branches 323 330 +7
============================================
+ Hits 3292 3336 +44
- Misses 823 881 +58
- Partials 130 131 +1
Continue to review full report at Codecov.
|
/** | ||
* JSON Web Token. | ||
*/ | ||
@SuppressWarnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semantosoph you can remove that and just initialize all attributes in the constructor, it's a good practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 Yep, will do.
try { | ||
bytes = new Base64().encode(this.jwto.toString()); | ||
} catch (final IOException ignore) { | ||
bytes = new byte[] {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semantosoph this looks a bit weird. Why so? Can't you just throw an unchecked exception here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 Yeah, I don't like declaring throws
on interface methods. But as of now, it looks like there will always be a reason to throw an IOException, so we can predeclare it anyway.
* @throws IOException | ||
* for all unexpected exceptions | ||
*/ | ||
@SuppressWarnings("resource") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semantosoph what's the point of this suppression? Can't you do what Java wants you to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 This is kinda silly. Constructing the Formatter without parameters forces it to use an internal StringBuilder which is totally OK for our use. But that StringBuilder is not closable, so calling close() on the Formatter is useless in terms of saving resources. Eclipse doesn't know this and warns anyway. That's why I suppressed it. I'll close it, if you like it better that way.
@semantosoph looks cool, thanks for your contribution! I made a few minor comments above |
@yegor256 There you go, I made the requested changes. I would appreciate it, if you could add me to the contributors list this time. |
final String jwt = head.trim().split(" ", 2)[1].trim(); | ||
final byte[] jwtheader = jwt.split(dot)[0].getBytes(); | ||
final byte[] jwtpayload = jwt.split(dot)[1].getBytes(); | ||
final byte[] jwtsign = jwt.split(dot)[2].getBytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semantosoph this code looks a bit weird. Why can't you do:
final String[] parts = jwt.split(dot);
final byte[] jwtheader = parts[0].getBytes();
final byte[] jwtpayload = parts[1].getBytes();
final byte[] jwtsign = parts[2].getBytes();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do.
* for all unexpected exceptions | ||
*/ | ||
private byte[] encrypt(final byte[] bytes) throws IOException { | ||
final byte[] encrypted; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semantosoph why do you need this variable? Can't you just do
return formatter.toString().getBytes();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I can.
@semantosoph a few more comments above. Of course, we can add you to the list, but we don't have that list now :) Feel free to add it to README, just like it's done in github.com/yegor256/cactoos |
@yegor256 Changes done. I'll compile the contributors list once I've got a little spare time. |
@rultor merge |
@semantosoph when you want me to release a new version, say it here, not in Twitter :) |
@rultor release, tag is |
@caarlos0 this job was assigned to you 8 days ago. |
Oops! Job |
2 similar comments
Oops! Job |
Oops! Job |
These commits introduce the following things in order to make JSON Web Token (JWT, see https://jwt.io/) usable in takes: