private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private OAuth2AccessToken createAccessToken() { OAuth2AccessToken accessToken = new OAuth2AccessToken( OAuth2AccessToken.TokenType.BEARER, "access-token-1234", Instant.now(), Instant.now().plusSeconds(3600), new LinkedHashSet<>(Arrays.asList("read", "write"))); return accessToken; } }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private Jwt jwt(Map<String, Object> claims) { Map<String, Object> headers = new HashMap<>(); headers.put("alg", JwsAlgorithms.RS256); return new Jwt("token", Instant.now(), Instant.now().plusSeconds(3600), headers, claims); } }
private static OidcIdToken idToken() { Map<String, Object> claims = new HashMap<>(); claims.put(IdTokenClaimNames.SUB, "subject"); claims.put(IdTokenClaimNames.ISS, "http://localhost/issuer"); claims.put(IdTokenClaimNames.AUD, Collections.singletonList("client")); claims.put(IdTokenClaimNames.AZP, "client"); return new OidcIdToken("id-token", Instant.now(), Instant.now().plusSeconds(3600), claims); } }
private ReactiveJwtDecoder getJwtDecoder() { return token -> { Map<String, Object> claims = new HashMap<>(); claims.put(IdTokenClaimNames.SUB, "subject"); claims.put(IdTokenClaimNames.ISS, "http://localhost/issuer"); claims.put(IdTokenClaimNames.AUD, Collections.singletonList("client")); claims.put(IdTokenClaimNames.AZP, "client"); Jwt jwt = new Jwt("id-token", Instant.now(), Instant.now().plusSeconds(3600), Collections.singletonMap("header1", "value1"), claims); return Mono.just(jwt); }; } }
private void setUpIdToken(Map<String, Object> claims) { Instant issuedAt = Instant.now(); Instant expiresAt = Instant.from(issuedAt).plusSeconds(3600); this.setUpIdToken(claims, issuedAt, expiresAt); }
@Test public void getClaimAsInstantWhenDoubleTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "doubleSeconds"; this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).doubleValue()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test public void getClaimAsInstantWhenIntegerTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "integerSeconds"; this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).intValue()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test public void getClaimAsInstantWhenLongTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "longSeconds"; this.claims.put(claimName, expectedClaimValue.getEpochSecond()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
private static OAuth2UserService<OidcUserRequest, OidcUser> createOidcUserService() { OidcIdToken idToken = new OidcIdToken("token123", Instant.now(), Instant.now().plusSeconds(3600), Collections.singletonMap(IdTokenClaimNames.SUB, "sub123")); return request -> new DefaultOidcUser( Collections.singleton(new OidcUserAuthority(idToken)), idToken); }
@Test public void getClaimAsInstantWhenDateTypeThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "date"; this.claims.put(claimName, Date.from(expectedClaimValue)); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test public void getClaimAsInstantWhenInstantTypeThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "instant"; this.claims.put(claimName, expectedClaimValue); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Before public void setup() { this.manager = new JwtReactiveAuthenticationManager(this.jwtDecoder); Map<String, Object> claims = new HashMap<>(); claims.put("scope", "message:read message:write"); Instant issuedAt = Instant.now(); Instant expiresAt = Instant.from(issuedAt).plusSeconds(3600); this.jwt = new Jwt("jwt", issuedAt, expiresAt, claims, claims); }
@Test public void buildWhenExpiresInIsNegativeThenExpiresAtOneSecondAfterIssueAt() { OAuth2AccessTokenResponse tokenResponse = OAuth2AccessTokenResponse .withToken(TOKEN_VALUE) .tokenType(OAuth2AccessToken.TokenType.BEARER) .expiresIn(-1L) .build(); assertThat(tokenResponse.getAccessToken().getExpiresAt()).isEqualTo( tokenResponse.getAccessToken().getIssuedAt().plusSeconds(1)); }
@Test public void buildWhenExpiresInIsZeroThenExpiresAtOneSecondAfterIssueAt() { OAuth2AccessTokenResponse tokenResponse = OAuth2AccessTokenResponse .withToken(TOKEN_VALUE) .tokenType(OAuth2AccessToken.TokenType.BEARER) .expiresIn(0) .build(); assertThat(tokenResponse.getAccessToken().getExpiresAt()).isEqualTo( tokenResponse.getAccessToken().getIssuedAt().plusSeconds(1)); }