|
46 | 46 | import com.nimbusds.jose.JWSAlgorithm;
|
47 | 47 | import com.nimbusds.jwt.JWT;
|
48 | 48 | import com.nimbusds.jwt.JWTClaimsSet;
|
| 49 | +import com.nimbusds.jwt.PlainJWT; |
49 | 50 | import com.nimbusds.jwt.SignedJWT;
|
50 | 51 |
|
51 | 52 | /**
|
@@ -91,15 +92,20 @@ public Authentication authenticate(Authentication authentication) throws Authent
|
91 | 92 | JWT jwt = jwtAuth.getJwt();
|
92 | 93 | JWTClaimsSet jwtClaims = jwt.getJWTClaimsSet();
|
93 | 94 |
|
94 |
| -// check the signature with nimbus |
95 |
| -if (jwt instanceof SignedJWT) { |
| 95 | +if (jwt instanceof PlainJWT) { |
| 96 | +if (!AuthMethod.NONE.equals(client.getTokenEndpointAuthMethod())) { |
| 97 | +throw new AuthenticationServiceException("Client does not support this authentication method."); |
| 98 | +} |
| 99 | +} else if (jwt instanceof SignedJWT) { |
| 100 | +// check the signature with nimbus |
96 | 101 | SignedJWT jws = (SignedJWT)jwt;
|
97 | 102 |
|
98 | 103 | JWSAlgorithm alg = jws.getHeader().getAlgorithm();
|
99 | 104 |
|
100 | 105 | if (client.getTokenEndpointAuthSigningAlg() != null &&
|
101 | 106 | !client.getTokenEndpointAuthSigningAlg().equals(alg)) {
|
102 |
| -throw new InvalidClientException("Client's registered request object signing algorithm (" + client.getRequestObjectSigningAlg() + ") does not match request object's actual algorithm (" + alg.getName() + ")"); |
| 107 | +throw new AuthenticationServiceException("Client's registered token endpoint signing algorithm (" + client.getTokenEndpointAuthSigningAlg() |
| 108 | ++ ") does not match token's actual algorithm (" + alg.getName() + ")"); |
103 | 109 | }
|
104 | 110 |
|
105 | 111 | if (client.getTokenEndpointAuthMethod() == null ||
|
@@ -142,6 +148,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
|
142 | 148 | } else {
|
143 | 149 | throw new AuthenticationServiceException("Unable to create signature validator for method " + client.getTokenEndpointAuthMethod() + " and algorithm " + alg);
|
144 | 150 | }
|
| 151 | +} else { |
| 152 | +throw new AuthenticationServiceException("Unsupported JWT type: " + jwt.getClass().getName()); |
145 | 153 | }
|
146 | 154 |
|
147 | 155 | // check the issuer
|
|
0 commit comments