-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Single-key Key Selector #7055
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
Single-key Key Selector #7055
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2002-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.oauth2.jwt; | ||
|
||
import java.security.Key; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.nimbusds.jose.JWSAlgorithm; | ||
import com.nimbusds.jose.JWSHeader; | ||
import com.nimbusds.jose.proc.JWSKeySelector; | ||
import com.nimbusds.jose.proc.SecurityContext; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* An internal implementation of {@link JWSKeySelector} that always returns the same key | ||
* | ||
* @author Josh Cummings | ||
* @since 5.2 | ||
*/ | ||
final class SingleKeyJWSKeySelector<C extends SecurityContext> implements JWSKeySelector<C> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider submitting this to Nimbus? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for checking on this. Yes, I'm planning on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
private final List<Key> keySet; | ||
private final JWSAlgorithm expectedJwsAlgorithm; | ||
|
||
SingleKeyJWSKeySelector(JWSAlgorithm expectedJwsAlgorithm, Key key) { | ||
Assert.notNull(expectedJwsAlgorithm, "expectedJwsAlgorithm cannot be null"); | ||
Assert.notNull(key, "key cannot be null"); | ||
this.keySet = Arrays.asList(key); | ||
this.expectedJwsAlgorithm = expectedJwsAlgorithm; | ||
} | ||
|
||
@Override | ||
public List<? extends Key> selectJWSKeys(JWSHeader header, C context) { | ||
if (!this.expectedJwsAlgorithm.equals(header.getAlgorithm())) { | ||
throw new IllegalArgumentException("Unsupported algorithm of " + header.getAlgorithm()); | ||
} | ||
return this.keySet; | ||
} | ||
} |
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 don't think this should have changed since it's the
SecretKey
builder and the issue raised is forPublicKey
.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.
Makes sense, I've raised #7056 so that this gets articulated.