use of org.forgerock.json.jose.jwt.JwtClaimsSet in project OpenAM by OpenRock.
the class OAuth2JwtTest method getJwtClaimsSet.
private JwtClaimsSet getJwtClaimsSet(long notBeforeTimeOffset, long expirationTimeOffset) {
JwtClaimsSet claims = new JwtClaimsSet();
final long currentTimeMillis = TimeService.SYSTEM.now();
claims.setNotBeforeTime(new Date(currentTimeMillis + notBeforeTimeOffset));
claims.setExpirationTime(new Date(currentTimeMillis + expirationTimeOffset));
claims.setIssuedAtTime(new Date(currentTimeMillis));
claims.setIssuer("TEST_ISSUER");
claims.setSubject("TEST_SUBJECT");
claims.addAudience("TEST_AUDIENCE");
return claims;
}
use of org.forgerock.json.jose.jwt.JwtClaimsSet in project OpenAM by OpenRock.
the class OAuth2JwtTest method expirationTimeSetInPastJWTShouldBeInvalid.
@Test
public void expirationTimeSetInPastJWTShouldBeInvalid() {
JwsHeader header = new JwsHeader(Collections.<String, Object>emptyMap());
JwtClaimsSet claims = getJwtClaimsSet(VALID_NOT_BEFORE_TIME, INVALID_EXPIRATION_TIME);
SigningHandler handler = new NOPSigningHandler();
OAuth2Jwt oAuth2Jwt = getOAuth2Jwt(header, claims, handler);
assertTrue(!oAuth2Jwt.isValid(handler));
}
use of org.forgerock.json.jose.jwt.JwtClaimsSet in project OpenAM by OpenRock.
the class AuthIdHelper method generateAuthId.
/**
* Generates the authentication id JWT.
*
* @param jwtValues A Map of key values to include in the JWT payload. Must not be null.
* @return The authentication id JWT.
* @throws SignatureException If there is a problem signing the JWT.
*/
private String generateAuthId(SecretKey key, Map<String, Object> jwtValues) throws SignatureException, RestAuthException {
String otk = new BigInteger(130, RANDOM).toString(32);
JwtClaimsSet claimsSet = jwtBuilderFactory.claims().claim("otk", otk).claims(jwtValues).build();
final SigningHandler signingHandler = signingManager.newHmacSigningHandler(key.getEncoded());
String jwt = jwtBuilderFactory.jws(signingHandler).headers().alg(JwsAlgorithm.HS256).done().claims(claimsSet).build();
return jwt;
}
use of org.forgerock.json.jose.jwt.JwtClaimsSet in project OpenAM by OpenRock.
the class AuthIdHelperTest method setUp.
@BeforeMethod
public void setUp() {
coreServicesWrapper = mock(CoreServicesWrapper.class);
jwtBuilderFactory = mock(JwtBuilderFactory.class);
signingManager = mock(SigningManager.class);
authIdHelper = new AuthIdHelper(coreServicesWrapper, jwtBuilderFactory, signingManager);
jwsHeaderBuilder = mock(JwsHeaderBuilder.class);
claimsSetBuilder = mock(JwtClaimsSetBuilder.class);
JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
SignedJwtBuilderImpl signedJwtBuilder = mock(SignedJwtBuilderImpl.class);
given(jwtBuilderFactory.claims()).willReturn(claimsSetBuilder);
given(claimsSetBuilder.claim(anyString(), anyObject())).willReturn(claimsSetBuilder);
given(claimsSetBuilder.claims(anyMap())).willReturn(claimsSetBuilder);
given(claimsSetBuilder.build()).willReturn(claimsSet);
given(jwtBuilderFactory.jws(Matchers.<SigningHandler>anyObject())).willReturn(signedJwtBuilder);
given(signedJwtBuilder.headers()).willReturn(jwsHeaderBuilder);
given(jwsHeaderBuilder.alg(Matchers.<Algorithm>anyObject())).willReturn(jwsHeaderBuilder);
given(jwsHeaderBuilder.done()).willReturn(signedJwtBuilder);
given(signedJwtBuilder.claims(claimsSet)).willReturn(signedJwtBuilder);
given(signedJwtBuilder.build()).willReturn("JWT_STRING");
}
use of org.forgerock.json.jose.jwt.JwtClaimsSet in project OpenAM by OpenRock.
the class EndSession method validateRedirect.
private void validateRedirect(OAuth2Request request, String idToken, String redirectUri) throws InvalidClientException, RedirectUriMismatchException, RelativeRedirectUriException, NotFoundException {
SignedJwt jwt = new JwtReconstruction().reconstructJwt(idToken, SignedJwt.class);
JwtClaimsSet claims = jwt.getClaimsSet();
String clientId = (String) claims.getClaim(OAuth2Constants.JWTTokenParams.AZP);
ClientRegistration client = clientRegistrationStore.get(clientId, request);
URI requestedUri = URI.create(redirectUri);
if (!requestedUri.isAbsolute()) {
throw new RelativeRedirectUriException();
}
if (!client.getPostLogoutRedirectUris().contains(requestedUri)) {
throw new RedirectUriMismatchException();
}
}
Aggregations