use of org.springframework.security.oauth2.client.registration.ClientRegistration.Builder in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapter method getBuilder.
private static Builder getBuilder(String registrationId, String configuredProviderId, Map<String, Provider> providers) {
String providerId = (configuredProviderId != null) ? configuredProviderId : registrationId;
CommonOAuth2Provider provider = getCommonProvider(providerId);
if (provider == null && !providers.containsKey(providerId)) {
throw new IllegalStateException(getErrorMessage(configuredProviderId, registrationId));
}
Builder builder = (provider != null) ? provider.getBuilder(registrationId) : ClientRegistration.withRegistrationId(registrationId);
if (providers.containsKey(providerId)) {
return getBuilder(builder, providers.get(providerId));
}
return builder;
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.Builder in project spring-boot by spring-projects.
the class OAuth2ClientPropertiesRegistrationAdapter method getBuilderFromIssuerIfPossible.
private static Builder getBuilderFromIssuerIfPossible(String registrationId, String configuredProviderId, Map<String, Provider> providers) {
String providerId = (configuredProviderId != null) ? configuredProviderId : registrationId;
if (providers.containsKey(providerId)) {
Provider provider = providers.get(providerId);
String issuer = provider.getIssuerUri();
if (issuer != null) {
Builder builder = ClientRegistrations.fromIssuerLocation(issuer).registrationId(registrationId);
return getBuilder(builder, provider);
}
}
return null;
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.Builder in project books by aidanwhiteley.
the class UserServiceTest method configureOauth.
private void configureOauth(String clientId, String name) {
Map<String, Object> details = new LinkedHashMap<>();
details.put("name", name);
details.put(name, name);
Set<GrantedAuthority> authorities = new HashSet<>();
authorities.add(new SimpleGrantedAuthority("USER"));
OAuth2User oauth2User = new DefaultOAuth2User(authorities, details, name);
when(oauthToken.getName()).thenReturn(DUMMY);
when(oauthToken.getAuthorizedClientRegistrationId()).thenReturn(DUMMY);
when(oauthToken.getPrincipal()).thenReturn(oauth2User);
OAuth2AuthorizedClient client = Mockito.mock(OAuth2AuthorizedClient.class);
ClientRegistration.Builder builder = ClientRegistration.withRegistrationId(DUMMY);
builder.clientId(clientId).authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE).clientSecret(DUMMY).redirectUri(DUMMY).scope(DUMMY).authorizationUri(DUMMY).tokenUri(DUMMY).clientName(DUMMY);
ClientRegistration clientReg = builder.build();
when(client.getClientRegistration()).thenReturn(clientReg);
when(authorisedClientService.loadAuthorizedClient(any(String.class), any(String.class))).thenReturn(client);
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.Builder in project service-authorization by reportportal.
the class WebMvcConfig method configureHandlerExceptionResolvers.
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
RestErrorDefinition<Exception> authErrorDefinition = new RestErrorDefinition<>(HttpStatus.BAD_REQUEST, ErrorType.ACCESS_DENIED, new DefaultExceptionMessageBuilder());
Map<Class<? extends Throwable>, RestErrorDefinition> errorMappings = ImmutableMap.<Class<? extends Throwable>, RestErrorDefinition>builder().put(OAuth2Exception.class, authErrorDefinition).put(AuthenticationException.class, authErrorDefinition).put(UsernameNotFoundException.class, authErrorDefinition).putAll(ExceptionMappings.DEFAULT_MAPPING).build();
RestExceptionHandler handler = new RestExceptionHandler();
handler.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
handler.setErrorResolver(new ReportPortalExceptionResolver(new DefaultErrorResolver(errorMappings)));
handler.setMessageConverters(messageConverters.getConverters());
exceptionResolvers.add(handler);
}
use of org.springframework.security.oauth2.client.registration.ClientRegistration.Builder in project spring-security by spring-projects.
the class CommonOAuth2ProviderTests method getBuilderWhenOktaShouldHaveOktaSettings.
@Test
public void getBuilderWhenOktaShouldHaveOktaSettings() {
ClientRegistration registration = builder(CommonOAuth2Provider.OKTA).authorizationUri("https://example.com/auth").tokenUri("https://example.com/token").userInfoUri("https://example.com/info").jwkSetUri("https://example.com/jwkset").build();
ProviderDetails providerDetails = registration.getProviderDetails();
assertThat(providerDetails.getAuthorizationUri()).isEqualTo("https://example.com/auth");
assertThat(providerDetails.getTokenUri()).isEqualTo("https://example.com/token");
assertThat(providerDetails.getUserInfoEndpoint().getUri()).isEqualTo("https://example.com/info");
assertThat(providerDetails.getUserInfoEndpoint().getUserNameAttributeName()).isEqualTo(IdTokenClaimNames.SUB);
assertThat(providerDetails.getJwkSetUri()).isEqualTo("https://example.com/jwkset");
assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
assertThat(registration.getRedirectUri()).isEqualTo(DEFAULT_REDIRECT_URL);
assertThat(registration.getScopes()).containsOnly("openid", "profile", "email");
assertThat(registration.getClientName()).isEqualTo("Okta");
assertThat(registration.getRegistrationId()).isEqualTo("123");
}
Aggregations