Search in sources :

Example 31 with OAuth2AuthenticatedPrincipal

use of org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal 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

OAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal)29 Test (org.junit.jupiter.api.Test)26 DefaultOAuth2AuthenticatedPrincipal (org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal)7 HashMap (java.util.HashMap)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 BearerTokenAuthenticationToken (org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken)5 JSONObject (net.minidev.json.JSONObject)4 MockWebServer (okhttp3.mockwebserver.MockWebServer)4 RequestEntity (org.springframework.http.RequestEntity)4 Authentication (org.springframework.security.core.Authentication)4 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)4 RestOperations (org.springframework.web.client.RestOperations)4 URL (java.net.URL)3 OAuth2AccessToken (org.springframework.security.oauth2.core.OAuth2AccessToken)3 OAuth2IntrospectionAuthenticatedPrincipal (org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal)3 OpaqueTokenIntrospector (org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector)3 Collection (java.util.Collection)2 List (java.util.List)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2