Search in sources :

Example 16 with BearerTokenAuthentication

use of org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication in project spring-security by spring-projects.

the class BearerTokenAuthenticationTests method getNameWhenConfiguredInConstructorThenReturnsName.

@Test
public void getNameWhenConfiguredInConstructorThenReturnsName() {
    OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(this.name, this.attributesMap, this.authorities);
    BearerTokenAuthentication authenticated = new BearerTokenAuthentication(principal, this.token, this.authorities);
    assertThat(authenticated.getName()).isEqualTo(this.name);
}
Also used : OAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) DefaultOAuth2AuthenticatedPrincipal(org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal) Test(org.junit.jupiter.api.Test)

Example 17 with BearerTokenAuthentication

use of org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication in project spring-security by spring-projects.

the class OpaqueTokenAuthenticationProvider method convert.

private AbstractAuthenticationToken convert(OAuth2AuthenticatedPrincipal principal, String token) {
    Instant iat = principal.getAttribute(OAuth2TokenIntrospectionClaimNames.IAT);
    Instant exp = principal.getAttribute(OAuth2TokenIntrospectionClaimNames.EXP);
    OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, token, iat, exp);
    return new BearerTokenAuthentication(principal, accessToken, principal.getAuthorities());
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.core.OAuth2AccessToken) Instant(java.time.Instant)

Aggregations

Test (org.junit.jupiter.api.Test)14 OAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal)10 DefaultOAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal)7 BearerTokenAuthentication (org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication)6 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)4 GrantedAuthority (org.springframework.security.core.GrantedAuthority)4 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)4 SecurityContext (org.springframework.security.core.context.SecurityContext)4 OAuth2AccessToken (org.springframework.security.oauth2.core.OAuth2AccessToken)3 Jwt (org.springframework.security.oauth2.jwt.Jwt)3 List (java.util.List)2 JSONObject (net.minidev.json.JSONObject)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)2 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)2 HttpHeaders (org.springframework.http.HttpHeaders)2 MediaType (org.springframework.http.MediaType)2 OAuth2TokenIntrospectionClaimNames (org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames)2 TestOAuth2AuthenticatedPrincipals (org.springframework.security.oauth2.core.TestOAuth2AuthenticatedPrincipals)2