use of com.nimbusds.jwt.JWT in project ddf by codice.
the class OidcTokenValidatorTest method testValidateUserInfoIdTokenInvalidSignature.
@Test(expected = OidcValidationException.class)
public void testValidateUserInfoIdTokenInvalidSignature() throws Exception {
String stringJwt = getIdTokenBuilder().sign(invalidAlgorithm);
JWT jwt = SignedJWT.parse(stringJwt);
OidcTokenValidator.validateUserInfoIdToken(jwt, resourceRetriever, oidcProviderMetadata);
}
use of com.nimbusds.jwt.JWT in project ddf by codice.
the class OidcTokenValidatorTest method testValidateIdTokensExpiredToken.
@Test(expected = OidcValidationException.class)
public void testValidateIdTokensExpiredToken() throws Exception {
WebContext context = getWebContext();
String stringJwt = getIdTokenBuilder().withClaim("nonce", "myNonce").withExpiresAt(new Date(Instant.now().minus(Duration.ofDays(3)).toEpochMilli())).sign(invalidAlgorithm);
JWT jwt = SignedJWT.parse(stringJwt);
OidcTokenValidator.validateIdTokens(jwt, context, configuration, oidcClient);
}
use of com.nimbusds.jwt.JWT in project ddf by codice.
the class OidcTokenValidatorTest method testValidateIdTokensInvalidSignature.
@Test(expected = OidcValidationException.class)
public void testValidateIdTokensInvalidSignature() throws Exception {
WebContext context = getWebContext();
String stringJwt = getIdTokenBuilder().withClaim("nonce", "myNonce").sign(invalidAlgorithm);
JWT jwt = SignedJWT.parse(stringJwt);
OidcTokenValidator.validateIdTokens(jwt, context, configuration, oidcClient);
}
use of com.nimbusds.jwt.JWT in project ddf by codice.
the class OidcTokenValidatorTest method testValidateAccessToken.
@Test
public void testValidateAccessToken() throws Exception {
String accessTokenString = getAccessTokenBuilder().sign(validAlgorithm);
AccessToken accessToken = new BearerAccessToken(accessTokenString);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(accessTokenString.getBytes(Charset.forName("US-ASCII")));
byte[] hash = messageDigest.digest();
byte[] firstHalf = Arrays.copyOf(hash, hash.length / 2);
String idToken = getIdTokenBuilder().withClaim("nonce", "myNonce").withClaim("at_hash", Base64URL.encode(firstHalf).toString()).sign(validAlgorithm);
JWT jwt = SignedJWT.parse(idToken);
OidcTokenValidator.validateAccessToken(accessToken, jwt, resourceRetriever, oidcProviderMetadata, configuration);
}
use of com.nimbusds.jwt.JWT in project ddf by codice.
the class OidcTokenValidatorTest method testValidateAccessTokenInvalidAtHash.
@Test(expected = OidcValidationException.class)
public void testValidateAccessTokenInvalidAtHash() throws Exception {
String accessTokenString = getAccessTokenBuilder().sign(validAlgorithm);
AccessToken accessToken = new BearerAccessToken(accessTokenString);
String idToken = getIdTokenBuilder().withClaim("nonce", "myNonce").withClaim("at_hash", "WRONG").sign(validAlgorithm);
JWT jwt = SignedJWT.parse(idToken);
OidcTokenValidator.validateAccessToken(accessToken, jwt, resourceRetriever, oidcProviderMetadata, configuration);
}
Aggregations