Search in sources :

Example 1 with DefaultClaims

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;
}
Also used : DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) Date(java.util.Date)

Example 2 with DefaultClaims

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));
}
Also used : Claims(io.jsonwebtoken.Claims) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) Date(java.util.Date) Test(org.junit.Test)

Example 3 with DefaultClaims

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();
}
Also used : DefaultJwsHeader(io.jsonwebtoken.impl.DefaultJwsHeader) Claims(io.jsonwebtoken.Claims) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) PublicKey(java.security.PublicKey) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) Test(org.junit.Test)

Example 4 with DefaultClaims

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);
}
Also used : DefaultJwsHeader(io.jsonwebtoken.impl.DefaultJwsHeader) Claims(io.jsonwebtoken.Claims) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) Test(org.junit.Test)

Example 5 with DefaultClaims

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);
}
Also used : DefaultClaims(io.jsonwebtoken.impl.DefaultClaims) Test(org.junit.Test)

Aggregations

DefaultClaims (io.jsonwebtoken.impl.DefaultClaims)6 Test (org.junit.Test)5 Claims (io.jsonwebtoken.Claims)4 DefaultJwsHeader (io.jsonwebtoken.impl.DefaultJwsHeader)3 PublicKey (java.security.PublicKey)2 Date (java.util.Date)2