Skip to content

Commit c38b9d7

Browse files
author
Tomasz Borowiec
committed
added PlainJWT and EncryptedJWT support + tests
1 parent fcb119f commit c38b9d7

File tree

2 files changed

+484
-3
lines changed

2 files changed

+484
-3
lines changed

openid-connect-server/src/main/java/org/mitre/openid/connect/assertion/JWTBearerAuthenticationProvider.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.nimbusds.jose.JWSAlgorithm;
4747
import com.nimbusds.jwt.JWT;
4848
import com.nimbusds.jwt.JWTClaimsSet;
49+
import com.nimbusds.jwt.PlainJWT;
4950
import com.nimbusds.jwt.SignedJWT;
5051

5152
/**
@@ -91,15 +92,20 @@ public Authentication authenticate(Authentication authentication) throws Authent
9192
JWT jwt = jwtAuth.getJwt();
9293
JWTClaimsSet jwtClaims = jwt.getJWTClaimsSet();
9394

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
96101
SignedJWT jws = (SignedJWT)jwt;
97102

98103
JWSAlgorithm alg = jws.getHeader().getAlgorithm();
99104

100105
if (client.getTokenEndpointAuthSigningAlg() != null &&
101106
!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() + ")");
103109
}
104110

105111
if (client.getTokenEndpointAuthMethod() == null ||
@@ -142,6 +148,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
142148
} else {
143149
throw new AuthenticationServiceException("Unable to create signature validator for method " + client.getTokenEndpointAuthMethod() + " and algorithm " + alg);
144150
}
151+
} else {
152+
throw new AuthenticationServiceException("Unsupported JWT type: " + jwt.getClass().getName());
145153
}
146154

147155
// check the issuer

0 commit comments

Comments
 (0)