use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.
the class ReactiveOidcIdTokenDecoderFactoryTests method createDecoderWhenCustomClaimTypeConverterFactorySetThenApplied.
@Test
public void createDecoderWhenCustomClaimTypeConverterFactorySetThenApplied() {
Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> customClaimTypeConverterFactory = mock(Function.class);
this.idTokenDecoderFactory.setClaimTypeConverterFactory(customClaimTypeConverterFactory);
ClientRegistration clientRegistration = this.registration.build();
given(customClaimTypeConverterFactory.apply(same(clientRegistration))).willReturn(new ClaimTypeConverter(OidcIdTokenDecoderFactory.createDefaultClaimTypeConverters()));
this.idTokenDecoderFactory.createDecoder(clientRegistration);
verify(customClaimTypeConverterFactory).apply(same(clientRegistration));
}
use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.
the class OidcIdTokenDecoderFactory method createDecoder.
@Override
public JwtDecoder createDecoder(ClientRegistration clientRegistration) {
Assert.notNull(clientRegistration, "clientRegistration cannot be null");
return this.jwtDecoders.computeIfAbsent(clientRegistration.getRegistrationId(), (key) -> {
NimbusJwtDecoder jwtDecoder = buildDecoder(clientRegistration);
jwtDecoder.setJwtValidator(this.jwtValidatorFactory.apply(clientRegistration));
Converter<Map<String, Object>, Map<String, Object>> claimTypeConverter = this.claimTypeConverterFactory.apply(clientRegistration);
if (claimTypeConverter != null) {
jwtDecoder.setClaimSetConverter(claimTypeConverter);
}
return jwtDecoder;
});
}
use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.
the class ReactiveOidcIdTokenDecoderFactory method createDecoder.
@Override
public ReactiveJwtDecoder createDecoder(ClientRegistration clientRegistration) {
Assert.notNull(clientRegistration, "clientRegistration cannot be null");
return this.jwtDecoders.computeIfAbsent(clientRegistration.getRegistrationId(), (key) -> {
NimbusReactiveJwtDecoder jwtDecoder = buildDecoder(clientRegistration);
jwtDecoder.setJwtValidator(this.jwtValidatorFactory.apply(clientRegistration));
Converter<Map<String, Object>, Map<String, Object>> claimTypeConverter = this.claimTypeConverterFactory.apply(clientRegistration);
if (claimTypeConverter != null) {
jwtDecoder.setClaimSetConverter(claimTypeConverter);
}
return jwtDecoder;
});
}
use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.
the class OidcUserServiceTests method loadUserWhenCustomClaimTypeConverterFactorySetThenApplied.
@Test
public void loadUserWhenCustomClaimTypeConverterFactorySetThenApplied() {
// @formatter:off
String userInfoResponse = "{\n" + " \"sub\": \"subject1\",\n" + " \"name\": \"first last\",\n" + " \"given_name\": \"first\",\n" + " \"family_name\": \"last\",\n" + " \"preferred_username\": \"user1\",\n" + " \"email\": \"user1@example.com\"\n" + "}\n";
// @formatter:on
this.server.enqueue(jsonResponse(userInfoResponse));
String userInfoUri = this.server.url("/user").toString();
ClientRegistration clientRegistration = this.clientRegistrationBuilder.userInfoUri(userInfoUri).build();
Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> customClaimTypeConverterFactory = mock(Function.class);
this.userService.setClaimTypeConverterFactory(customClaimTypeConverterFactory);
given(customClaimTypeConverterFactory.apply(same(clientRegistration))).willReturn(new ClaimTypeConverter(OidcUserService.createDefaultClaimTypeConverters()));
this.userService.loadUser(new OidcUserRequest(clientRegistration, this.accessToken, this.idToken));
verify(customClaimTypeConverterFactory).apply(same(clientRegistration));
}
use of org.springframework.security.oauth2.core.converter.ClaimTypeConverter in project spring-security by spring-projects.
the class OidcIdTokenDecoderFactoryTests method createDecoderWhenCustomClaimTypeConverterFactorySetThenApplied.
@Test
public void createDecoderWhenCustomClaimTypeConverterFactorySetThenApplied() {
Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> customClaimTypeConverterFactory = mock(Function.class);
this.idTokenDecoderFactory.setClaimTypeConverterFactory(customClaimTypeConverterFactory);
ClientRegistration clientRegistration = this.registration.build();
given(customClaimTypeConverterFactory.apply(same(clientRegistration))).willReturn(new ClaimTypeConverter(OidcIdTokenDecoderFactory.createDefaultClaimTypeConverters()));
this.idTokenDecoderFactory.createDecoder(clientRegistration);
verify(customClaimTypeConverterFactory).apply(same(clientRegistration));
}
Aggregations