use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.
the class BearerTokenAuthenticationTests method constructorWhenPassingAllAttributesThenTokenIsAuthenticated.
@Test
public void constructorWhenPassingAllAttributesThenTokenIsAuthenticated() {
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal("harris", Collections.singletonMap("claim", "value"), null);
BearerTokenAuthentication authenticated = new BearerTokenAuthentication(principal, this.token, null);
assertThat(authenticated.isAuthenticated()).isTrue();
}
use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.
the class JwtBearerTokenAuthenticationConverter method convert.
@Override
public AbstractAuthenticationToken convert(Jwt jwt) {
OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, jwt.getTokenValue(), jwt.getIssuedAt(), jwt.getExpiresAt());
Map<String, Object> attributes = jwt.getClaims();
AbstractAuthenticationToken token = this.jwtAuthenticationConverter.convert(jwt);
Collection<GrantedAuthority> authorities = token.getAuthorities();
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(attributes, authorities);
return new BearerTokenAuthentication(principal, accessToken, authorities);
}
use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.
the class TestBearerTokenAuthentications method bearer.
public static BearerTokenAuthentication bearer() {
Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("SCOPE_USER");
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(Collections.singletonMap("sub", "user"), authorities);
OAuth2AccessToken token = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "token", Instant.now(), Instant.now().plusSeconds(86400), new HashSet<>(Arrays.asList("USER")));
return new BearerTokenAuthentication(principal, token, authorities);
}
use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.
the class BearerTokenAuthenticationTests method getNameWhenHasNoSubjectThenReturnsNull.
@Test
public void getNameWhenHasNoSubjectThenReturnsNull() {
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(Collections.singletonMap("claim", "value"), null);
BearerTokenAuthentication authenticated = new BearerTokenAuthentication(principal, this.token, null);
assertThat(authenticated.getName()).isNull();
}
use of org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal in project spring-security by spring-projects.
the class BearerTokenAuthenticationTests method constructorWhenDefaultParametersThenSetsPrincipalToAttributesCopy.
// gh-6843
@Test
public void constructorWhenDefaultParametersThenSetsPrincipalToAttributesCopy() {
JSONObject attributes = new JSONObject();
attributes.put("active", true);
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(attributes, null);
BearerTokenAuthentication token = new BearerTokenAuthentication(principal, this.token, null);
assertThat(token.getPrincipal()).isNotSameAs(attributes);
assertThat(token.getTokenAttributes()).isNotSameAs(attributes);
}
Aggregations