use of com.auth0.json.mgmt.Token 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.json.mgmt.Token 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.json.mgmt.Token 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());
}
use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndIssuerAndConfiguredRequiredIssuer.
@Test
void validTokenWithKeyIdAndIssuerAndConfiguredRequiredIssuer() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, 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());
}
use of com.auth0.json.mgmt.Token in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndIssuerAndWillExpire.
@Test
void validTokenWithKeyIdAndIssuerAndWillExpire() throws InterruptedException {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 2);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, 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());
TimeUnit.SECONDS.sleep(3);
assertThatThrownBy(() -> this.service.auth(token)).isInstanceOf(JwtAuthException.class);
}
Aggregations