use of com.auth0.jwt.Claim in project sda-dropwizard-commons by SDA-SE.
the class AuthBuilderTest method shouldAddIntArrayClaim.
@Test
public void shouldAddIntArrayClaim() {
String token = authBuilder.addClaim("testKey", new Integer[] { 1, 2 }).buildToken();
Claim claim = JWT.decode(token).getClaim("testKey");
assertThat(claim.asList(Integer.class)).containsExactly(1, 2);
}
use of com.auth0.jwt.Claim in project sda-dropwizard-commons by SDA-SE.
the class SecureEndPoint method returnClaims.
@GET
@Produces(APPLICATION_JSON)
public Response returnClaims() {
JwtPrincipal jwtPrincipal = (JwtPrincipal) securityContext.getUserPrincipal();
Map<String, Claim> claims = jwtPrincipal.getClaims();
Map<String, String> claimsAsString = claims.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().asString()));
return Response.ok(claimsAsString).build();
}
use of com.auth0.jwt.Claim in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndNoIssuerButConfiguredRequiredIssuer.
@Test
void validTokenWithKeyIdAndNoIssuerButConfiguredRequiredIssuer() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, null, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), null, KEY_ID));
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER)).isNull();
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
use of com.auth0.jwt.Claim in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndIssuerAndAndFutureNotBeforeFailed.
@Test
void validTokenWithKeyIdAndIssuerAndAndFutureNotBeforeFailed() throws InterruptedException {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 2, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), ISSUER, KEY_ID));
assertThatThrownBy(() -> this.service.auth(token)).isInstanceOf(JwtAuthException.class);
TimeUnit.SECONDS.sleep(2);
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER).asString()).isEqualTo(ISSUER);
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
use of com.auth0.jwt.Claim in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndNoIssuerAndRequiredIssuerButJwks.
@Test
void validTokenWithKeyIdAndNoIssuerAndRequiredIssuerButJwks() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(null, keyPair.getRight(), ISSUER, KEY_ID));
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER).asString()).isEqualTo(ISSUER);
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
Aggregations