use of io.jsonwebtoken.impl.DefaultClaims in project sonarqube by SonarSource.
the class JwtHttpHandlerTest method createToken.
private Claims createToken(String userLogin, long createdAt, long expiredAt) {
DefaultClaims claims = new DefaultClaims();
claims.setId("ID");
claims.setSubject(userLogin);
claims.setIssuedAt(new Date(createdAt));
claims.setExpiration(new Date(expiredAt));
claims.put("lastRefreshTime", createdAt);
return claims;
}
use of io.jsonwebtoken.impl.DefaultClaims in project sonarqube by SonarSource.
the class JwtSerializerTest method refresh_token.
@Test
public void refresh_token() throws Exception {
setSecretKey(A_SECRET_KEY);
underTest.start();
Date now = new Date();
Date createdAt = DateUtils.parseDate("2016-01-01");
// Expired in 10 minutes
Date expiredAt = new Date(now.getTime() + 10 * 60 * 1000);
Claims token = new DefaultClaims().setId("id").setSubject("subject").setIssuer("sonarqube").setIssuedAt(createdAt).setExpiration(expiredAt);
token.put("key", "value");
// Refresh the token with a higher expiration time
String encodedToken = underTest.refresh(token, 20 * 60);
Claims result = underTest.decode(encodedToken).get();
assertThat(result.getId()).isEqualTo("id");
assertThat(result.getSubject()).isEqualTo("subject");
assertThat(result.getIssuer()).isEqualTo("sonarqube");
assertThat(result.getIssuedAt()).isEqualTo(createdAt);
assertThat(result.get("key")).isEqualTo("value");
// Expiration date has been changed
assertThat(result.getExpiration()).isNotEqualTo(expiredAt).isAfterOrEqualsTo(new Date(now.getTime() + 19 * 1000));
}
use of io.jsonwebtoken.impl.DefaultClaims in project cf-java-client by cloudfoundry.
the class UaaSigningKeyResolverTest method resolveRefreshedKey.
@Test
public void resolveRefreshedKey() throws NoSuchAlgorithmException {
PublicKey publicKey = getKeyPair().getPublic();
when(this.tokens.listKeys(ListTokenKeysRequest.builder().build())).thenReturn(Mono.just(ListTokenKeysResponse.builder().key(TokenKey.builder().algorithm(publicKey.getAlgorithm()).e("").id("test-key-id").keyType(KeyType.RSA).n("").use("").value(getEncoded(publicKey)).build()).build()));
JwsHeader<?> header = new DefaultJwsHeader().setKeyId("test-key-id");
Claims claims = new DefaultClaims();
assertThat(this.signingKeyResolver.resolveSigningKey(header, claims)).isNotNull();
}
use of io.jsonwebtoken.impl.DefaultClaims in project cf-java-client by cloudfoundry.
the class UaaSigningKeyResolverTest method resolveUnknownKey.
@Test(expected = IllegalStateException.class)
public void resolveUnknownKey() {
when(this.tokens.listKeys(ListTokenKeysRequest.builder().build())).thenReturn(Mono.just(ListTokenKeysResponse.builder().build()));
JwsHeader<?> header = new DefaultJwsHeader().setKeyId("test-key-id");
Claims claims = new DefaultClaims();
this.signingKeyResolver.resolveSigningKey(header, claims);
}
use of io.jsonwebtoken.impl.DefaultClaims in project sonarqube by SonarSource.
the class JwtSerializerTest method refresh_fail_when_not_started.
@Test
public void refresh_fail_when_not_started() throws Exception {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("org.sonar.server.authentication.JwtSerializer not started");
underTest.refresh(new DefaultClaims(), 10);
}
Aggregations