use of org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal in project spring-security by spring-projects.
the class OAuth2IntrospectionAuthenticatedPrincipalTests method getAttributeWhenGivenKeyThenReturnsValue.
@Test
public void getAttributeWhenGivenKeyThenReturnsValue() {
OAuth2AuthenticatedPrincipal principal = new OAuth2IntrospectionAuthenticatedPrincipal(CLAIMS, AUTHORITIES);
assertHasEqualAttribute(principal, ACTIVE_CLAIM, ACTIVE_VALUE);
assertHasEqualAttribute(principal, CLIENT_ID_CLAIM, CLIENT_ID_VALUE);
assertHasEqualAttribute(principal, USERNAME_CLAIM, USERNAME_VALUE);
assertHasEqualAttribute(principal, TOKEN_TYPE_CLAIM, TOKEN_TYPE_VALUE);
assertHasEqualAttribute(principal, EXP_CLAIM, EXP_VALUE);
assertHasEqualAttribute(principal, IAT_CLAIM, IAT_VALUE);
assertHasEqualAttribute(principal, NBF_CLAIM, NBF_VALUE);
assertHasEqualAttribute(principal, SUB_CLAIM, SUB_VALUE);
assertHasEqualAttribute(principal, AUD_CLAIM, AUD_VALUE);
assertHasEqualAttribute(principal, ISS_CLAIM, ISS_VALUE);
assertHasEqualAttribute(principal, JTI_CLAIM, JTI_VALUE);
}
use of org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal in project spring-security by spring-projects.
the class OpaqueTokenAuthenticationProviderTests method authenticateWhenMissingScopeAttributeThenNoAuthorities.
@Test
public void authenticateWhenMissingScopeAttributeThenNoAuthorities() {
OAuth2AuthenticatedPrincipal principal = new OAuth2IntrospectionAuthenticatedPrincipal(Collections.singletonMap("claim", "value"), null);
OpaqueTokenIntrospector introspector = mock(OpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(principal);
OpaqueTokenAuthenticationProvider provider = new OpaqueTokenAuthenticationProvider(introspector);
Authentication result = provider.authenticate(new BearerTokenAuthenticationToken("token"));
assertThat(result.getPrincipal()).isInstanceOf(OAuth2AuthenticatedPrincipal.class);
Map<String, Object> attributes = ((OAuth2AuthenticatedPrincipal) result.getPrincipal()).getAttributes();
// @formatter:off
assertThat(attributes).isNotNull().doesNotContainKey(OAuth2TokenIntrospectionClaimNames.SCOPE);
// @formatter:on
assertThat(result.getAuthorities()).isEmpty();
}
use of org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal in project spring-security by spring-projects.
the class OpaqueTokenReactiveAuthenticationManagerTests method authenticateWhenMissingScopeAttributeThenNoAuthorities.
@Test
public void authenticateWhenMissingScopeAttributeThenNoAuthorities() {
OAuth2AuthenticatedPrincipal authority = new OAuth2IntrospectionAuthenticatedPrincipal(Collections.singletonMap("claim", "value"), null);
ReactiveOpaqueTokenIntrospector introspector = mock(ReactiveOpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(Mono.just(authority));
OpaqueTokenReactiveAuthenticationManager provider = new OpaqueTokenReactiveAuthenticationManager(introspector);
Authentication result = provider.authenticate(new BearerTokenAuthenticationToken("token")).block();
assertThat(result.getPrincipal()).isInstanceOf(OAuth2IntrospectionAuthenticatedPrincipal.class);
Map<String, Object> attributes = ((OAuth2AuthenticatedPrincipal) result.getPrincipal()).getAttributes();
assertThat(attributes).isNotNull().doesNotContainKey(OAuth2TokenIntrospectionClaimNames.SCOPE);
assertThat(result.getAuthorities()).isEmpty();
}
use of org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal in project spring-security by spring-projects.
the class OAuth2IntrospectionAuthenticatedPrincipalTests method getNameWhenInConstructorThenReturns.
@Test
public void getNameWhenInConstructorThenReturns() {
OAuth2AuthenticatedPrincipal principal = new OAuth2IntrospectionAuthenticatedPrincipal(SUB_VALUE, CLAIMS, AUTHORITIES);
assertThat(principal.getName()).isEqualTo(SUB_VALUE);
}
use of org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal in project spring-security by spring-projects.
the class OAuth2IntrospectionAuthenticatedPrincipalTests method constructorWhenNameIsNullThenFallsbackToSubAttribute.
@Test
public void constructorWhenNameIsNullThenFallsbackToSubAttribute() {
OAuth2AuthenticatedPrincipal principal = new OAuth2IntrospectionAuthenticatedPrincipal(null, CLAIMS, AUTHORITIES);
assertThat(principal.getName()).isEqualTo(CLAIMS.get(SUB_CLAIM));
}
Aggregations