-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Introduce JwtEncoder with JWS implementation #96
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
Conversation
@krajcsovszkig-ms @anoopgarlapati @jzheaux Here is the initial draft of You can run the integration test Feedback would be great. NOTE: Tests and javadoc have not been done yet. |
bd1cc6c
to
854176e
Compare
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.
Seems good so far!
Thanks!
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T getKey() { |
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.
I'd prefer returning a Key
here and let the caller cast it explicitly to what they think it is, or having separate getPrivateKey()
and getSymmetricKey()
methods that return null or throw an exception if the key
field is not the correct type.
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.
This was updated to:
public <T extends Key> T getKey() {
return (T) this.key;
}
To enforce a Key
type
* @author Joe Grandja | ||
* @since 0.0.1 | ||
*/ | ||
public final class StaticKeyGeneratingKeyManager implements KeyManager { |
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.
I'd call this DefaultKeyManager
and document that it generates HMAC and RSA keys. Or alternatively make the generated keys configurable.
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.
This implementation is strictly for development/testing and I've javadoc'd it. This is good for now but it will likely go away later on when a new implementation is provided.
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T getHeader(String name) { |
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.
If this is public, I'd prefer returning an Object
and having the caller cast it explicitly. Perhaps have a separate private one that auto-casts to make the specific getters neater.
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.
I think this is cleaner than casting:
JwsAlgorithm jwsAlgorithm = joseHeader.getHeader(JoseHeaderNames.ALG)
vs.
JwsAlgorithm jwsAlgorithm = (JwsAlgorithm) joseHeader.getHeader(JoseHeaderNames.ALG)
The caller will know the type.
JWSHeader jwsHeader = convert(headers); | ||
|
||
claims = JwtClaimsSet.from(claims) | ||
.id(UUID.randomUUID().toString()) // TODO Is this unique enough? |
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.
It seems to be using secureRandom()
so it's as good as it gets IMO.
Hi @jgrandja , Do you have an approximate ETA on this? Do you expect the interfaces to change much? If not, I might start building on them in a week or two. Thanks! |
I'm planning on getting back to this PR this week @krajcsovszkig-ms and merging it later this week or early next week. As an FYI, this won't make it into Spring Security 5.4 (Sep 2 release) but will be the first priority for 5.5, which will be released approx. 6 months after 5.4. I'm not expecting major changes to the current API but likely there will be some minor changes. I'm very interested to see how this works out on client side so please go ahead with your implementation and provide me feedback on how we can improve on the current API. Thanks! |
854176e
to
edefabd
Compare
@krajcsovszkig-ms I just merged this so you're good to go on your end. |
Great, thanks! |
Issue gh-81