use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasEmptyScpAttributeThenTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyScpAttributeThenTranslatedToNoAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList()).build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
assertThat(authorities).containsExactly();
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationConverterTests method convertWhenPrincipalClaimNameSet.
@Test
public void convertWhenPrincipalClaimNameSet() {
this.jwtAuthenticationConverter.setPrincipalClaimName("user_id");
Jwt jwt = TestJwts.jwt().claim("user_id", "100").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
assertThat(authentication.getName()).isEqualTo("100");
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationConverterTests method convertWithOverriddenGrantedAuthoritiesConverter.
@Test
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Arrays.asList(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("blah"));
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class JwtAuthenticationConverterTests method convertWhenPrincipalClaimNameSetAndClaimValueIsNotString.
@Test
public void convertWhenPrincipalClaimNameSetAndClaimValueIsNotString() {
this.jwtAuthenticationConverter.setPrincipalClaimName("user_id");
Jwt jwt = TestJwts.jwt().claim("user_id", 100).build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
assertThat(authentication.getName()).isEqualTo("100");
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class JwtBearerTokenAuthenticationConverterTests method convertWhenJwtThenBearerTokenAuthentication.
@Test
public void convertWhenJwtThenBearerTokenAuthentication() {
// @formatter:off
Jwt jwt = Jwt.withTokenValue("token-value").claim("claim", "value").header("header", "value").build();
// @formatter:on
AbstractAuthenticationToken token = this.converter.convert(jwt);
assertThat(token).isInstanceOf(BearerTokenAuthentication.class);
BearerTokenAuthentication bearerToken = (BearerTokenAuthentication) token;
assertThat(bearerToken.getToken().getTokenValue()).isEqualTo("token-value");
assertThat(bearerToken.getTokenAttributes()).containsOnlyKeys("claim");
assertThat(bearerToken.getAuthorities()).isEmpty();
}
Aggregations