use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class JwtBearerTokenAuthenticationConverterTests method convertWhenJwtWithScpAttributeThenBearerTokenAuthentication.
@Test
public void convertWhenJwtWithScpAttributeThenBearerTokenAuthentication() {
// @formatter:off
Jwt jwt = Jwt.withTokenValue("token-value").claim("scp", Arrays.asList("message:read", "message:write")).header("header", "value").build();
// @formatter:on
AbstractAuthenticationToken token = this.converter.convert(jwt);
assertThat(token).isInstanceOf(BearerTokenAuthentication.class);
BearerTokenAuthentication bearerToken = (BearerTokenAuthentication) token;
assertThat(bearerToken.getAuthorities()).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), new SimpleGrantedAuthority("SCOPE_message:write"));
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasBothScopeAndScpThenScopeAttributeIsTranslatedToAuthorities.
@Test
public void convertWhenTokenHasBothScopeAndScpThenScopeAttributeIsTranslatedToAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList("message:read", "message:write")).claim("scope", "missive:read missive:write").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
// @formatter:off
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_missive:read"), new SimpleGrantedAuthority("SCOPE_missive:write"));
// @formatter:on
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasEmptyScopeAndNonEmptyScpThenScopeAttributeIsTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyScopeAndNonEmptyScpThenScopeAttributeIsTranslatedToNoAuthorities() {
// @formatter:off
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList("message:read", "message:write")).claim("scope", "").build();
// @formatter:on
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 ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasScopeAttributeThenTranslatedToAuthorities.
@Test
public void convertWhenTokenHasScopeAttributeThenTranslatedToAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
// @formatter:off
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), new SimpleGrantedAuthority("SCOPE_message:write"));
// @formatter:on
}
use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class ReactiveJwtAuthenticationConverterTests method convertWhenDefaultGrantedAuthoritiesConverterSet.
@Test
public void convertWhenDefaultGrantedAuthoritiesConverterSet() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"), new SimpleGrantedAuthority("SCOPE_message:write"));
}
Aggregations