Search in sources :

Example 6 with ClaimTypeConverter

use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.

the class OidcReactiveOAuth2UserServiceTests method loadUserWhenCustomClaimTypeConverterFactorySetThenApplied.

@Test
public void loadUserWhenCustomClaimTypeConverterFactorySetThenApplied() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(StandardClaimNames.SUB, "subject");
    attributes.put("user", "rob");
    OAuth2User oauth2User = new DefaultOAuth2User(AuthorityUtils.createAuthorityList("ROLE_USER"), attributes, "user");
    given(this.oauth2UserService.loadUser(any())).willReturn(Mono.just(oauth2User));
    OidcUserRequest userRequest = userRequest();
    Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> customClaimTypeConverterFactory = mock(Function.class);
    this.userService.setClaimTypeConverterFactory(customClaimTypeConverterFactory);
    given(customClaimTypeConverterFactory.apply(same(userRequest.getClientRegistration()))).willReturn(new ClaimTypeConverter(OidcReactiveOAuth2UserService.createDefaultClaimTypeConverters()));
    this.userService.loadUser(userRequest).block().getUserInfo();
    verify(customClaimTypeConverterFactory).apply(same(userRequest.getClientRegistration()));
}
Also used : DefaultOAuth2User(org.springframework.security.oauth2.core.user.DefaultOAuth2User) OAuth2User(org.springframework.security.oauth2.core.user.OAuth2User) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) HashMap(java.util.HashMap) ClaimTypeConverter(org.springframework.security.oauth2.core.converter.ClaimTypeConverter) Converter(org.springframework.core.convert.converter.Converter) DefaultOAuth2User(org.springframework.security.oauth2.core.user.DefaultOAuth2User) ClaimTypeConverter(org.springframework.security.oauth2.core.converter.ClaimTypeConverter) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 Converter (org.springframework.core.convert.converter.Converter)4 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)4 ClaimTypeConverter (org.springframework.security.oauth2.core.converter.ClaimTypeConverter)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DefaultOAuth2User (org.springframework.security.oauth2.core.user.DefaultOAuth2User)1 OAuth2User (org.springframework.security.oauth2.core.user.OAuth2User)1 NimbusJwtDecoder (org.springframework.security.oauth2.jwt.NimbusJwtDecoder)1 NimbusReactiveJwtDecoder (org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder)1