Search in sources :

Example 36 with OidcUser

use of org.springframework.security.oauth2.core.oidc.user.OidcUser in project spring-security by spring-projects.

the class OidcReactiveOAuth2UserServiceTests method loadUserWhenTokenDoesNotContainScopesThenNoScopeAuthorities.

@Test
public void loadUserWhenTokenDoesNotContainScopesThenNoScopeAuthorities() {
    OidcReactiveOAuth2UserService userService = new OidcReactiveOAuth2UserService();
    OidcUserRequest request = new OidcUserRequest(TestClientRegistrations.clientRegistration().build(), TestOAuth2AccessTokens.noScopes(), TestOidcIdTokens.idToken().build());
    OidcUser user = userService.loadUser(request).block();
    assertThat(user.getAuthorities()).hasSize(1);
    Iterator<? extends GrantedAuthority> authorities = user.getAuthorities().iterator();
    assertThat(authorities.next()).isInstanceOf(OAuth2UserAuthority.class);
}
Also used : OidcUser(org.springframework.security.oauth2.core.oidc.user.OidcUser) Test(org.junit.jupiter.api.Test)

Aggregations

OidcUser (org.springframework.security.oauth2.core.oidc.user.OidcUser)30 Test (org.junit.jupiter.api.Test)24 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)14 GrantedAuthority (org.springframework.security.core.GrantedAuthority)8 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)8 OAuth2AuthenticationToken (org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken)8 DefaultOidcUser (org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser)8 OidcUserRequest (org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest)7 OAuth2AccessToken (org.springframework.security.oauth2.core.OAuth2AccessToken)6 OAuth2AuthenticationException (org.springframework.security.oauth2.core.OAuth2AuthenticationException)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 AuthorityUtils (org.springframework.security.core.authority.AuthorityUtils)5 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)5 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)5 OAuth2AuthorizationResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse)5 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 GrantedAuthoritiesMapper (org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper)4