use of org.springframework.security.authentication.AbstractAuthenticationToken in project spring-security by spring-projects.
the class ReactiveJwtAuthenticationConverterTests method convertWithOverriddenGrantedAuthoritiesConverter.
@Test
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Flux<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Flux.just(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
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 ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasEmptyScopeAttributeThenTranslatedToNoAuthorities.
@Test
public void convertWhenTokenHasEmptyScopeAttributeThenTranslatedToNoAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scope", "").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 ReactiveJwtAuthenticationConverterAdapterTests method convertWhenTokenHasScpAttributeThenTranslatedToAuthorities.
@Test
public void convertWhenTokenHasScpAttributeThenTranslatedToAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList("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 JwtAuthenticationConverterTests method convertWhenDefaultGrantedAuthoritiesConverterSet.
@Test
public void convertWhenDefaultGrantedAuthoritiesConverterSet() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
assertThat(authorities).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 OpaqueTokenAuthenticationProvider method authenticate.
/**
* Introspect and validate the opaque
* <a href="https://tools.ietf.org/html/rfc6750#section-1.2" target="_blank">Bearer
* Token</a>.
* @param authentication the authentication request object.
* @return A successful authentication
* @throws AuthenticationException if authentication failed for some reason
*/
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (!(authentication instanceof BearerTokenAuthenticationToken)) {
return null;
}
BearerTokenAuthenticationToken bearer = (BearerTokenAuthenticationToken) authentication;
OAuth2AuthenticatedPrincipal principal = getOAuth2AuthenticatedPrincipal(bearer);
AbstractAuthenticationToken result = convert(principal, bearer.getToken());
result.setDetails(bearer.getDetails());
this.logger.debug("Authenticated token");
return result;
}
Aggregations