use of org.pac4j.jwt.profile.JwtProfile in project pac4j by pac4j.
the class JwtTests method testGenerateAuthenticateClaims.
@Test
public void testGenerateAuthenticateClaims() {
final JwtGenerator<JwtProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
final Map<String, Object> claims = new HashMap<>();
claims.put(JwtClaims.SUBJECT, VALUE);
final Date tomorrow = tomorrow();
claims.put(JwtClaims.EXPIRATION_TIME, tomorrow);
final String token = generator.generate(claims);
final JwtAuthenticator jwtAuthenticator = new JwtAuthenticator(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
final JwtProfile profile = (JwtProfile) jwtAuthenticator.validateToken(token);
assertEquals(VALUE, profile.getSubject());
assertEquals(tomorrow.getTime() / 1000, profile.getExpirationDate().getTime() / 1000);
final Map<String, Object> claims2 = jwtAuthenticator.validateTokenAndGetClaims(token);
assertEquals(VALUE, claims2.get(JwtClaims.SUBJECT));
assertEquals(tomorrow.getTime() / 1000, ((Date) claims2.get(JwtClaims.EXPIRATION_TIME)).getTime() / 1000);
}
Aggregations