Validate HMAC-signed ID tokens
parent
5773fe195b
commit
1dc204f975
|
@ -444,6 +444,16 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
||||||
|
|
||||||
// check the signature
|
// check the signature
|
||||||
JwtSigningAndValidationService jwtValidator = validationServices.getValidator(serverConfig.getJwksUri());
|
JwtSigningAndValidationService jwtValidator = validationServices.getValidator(serverConfig.getJwksUri());
|
||||||
|
if (jwtValidator == null) {
|
||||||
|
JWSAlgorithm alg = idToken.getHeader().getAlgorithm();
|
||||||
|
if (alg.equals(JWSAlgorithm.HS256)
|
||||||
|
|| alg.equals(JWSAlgorithm.HS384)
|
||||||
|
|| alg.equals(JWSAlgorithm.HS512)) {
|
||||||
|
|
||||||
|
// generate one based on client secret
|
||||||
|
jwtValidator = symmetricCacheService.getSymmetricValidtor(clientConfig.getClient());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (jwtValidator != null) {
|
if (jwtValidator != null) {
|
||||||
if(!jwtValidator.validateSignature(idToken)) {
|
if(!jwtValidator.validateSignature(idToken)) {
|
||||||
throw new AuthenticationServiceException("Signature validation failed");
|
throw new AuthenticationServiceException("Signature validation failed");
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class SymmetricCacheService {
|
||||||
|
|
||||||
String id = "SYMMETRIC-KEY";
|
String id = "SYMMETRIC-KEY";
|
||||||
|
|
||||||
JWK jwk = new OctetSequenceKey(Base64URL.encode(key), Use.SIGNATURE, null, id, null, null, null);
|
JWK jwk = new OctetSequenceKey(new Base64URL(key), Use.SIGNATURE, null, id, null, null, null);
|
||||||
Map<String, JWK> keys = ImmutableMap.of(id, jwk);
|
Map<String, JWK> keys = ImmutableMap.of(id, jwk);
|
||||||
JwtSigningAndValidationService service = new DefaultJwtSigningAndValidationService(keys);
|
JwtSigningAndValidationService service = new DefaultJwtSigningAndValidationService(keys);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue