Java Code Examples for org.springframework.security.oauth2.client.registration.ClientRegistrationRepository#findByRegistrationId()
The following examples show how to use
org.springframework.security.oauth2.client.registration.ClientRegistrationRepository#findByRegistrationId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CredHubRestTemplateFactory.java From spring-credhub with Apache License 2.0 | 5 votes |
private static ClientRegistration getClientRegistration(ClientRegistrationRepository clientRegistrationRepository, String clientId) { ClientRegistration clientRegistration = clientRegistrationRepository.findByRegistrationId(clientId); if (clientRegistration == null) { throw new IllegalStateException("The CredHub OAuth2 client registration ID '" + clientId + "' is not a valid Spring Security OAuth2 client registration"); } return clientRegistration; }
Example 2
Source File: LogoutResource.java From java-microservices-examples with Apache License 2.0 | 4 votes |
public LogoutResource(ClientRegistrationRepository registrations) { this.registration = registrations.findByRegistrationId("oidc"); }
Example 3
Source File: DataFlowConfiguration.java From composed-task-runner with Apache License 2.0 | 4 votes |
/** * @param clientRegistrations Can be null. Only required for Client Credentials Grant authentication * @param clientCredentialsTokenResponseClient Can be null. Only required for Client Credentials Grant authentication * @return DataFlowOperations */ @Bean public DataFlowOperations dataFlowOperations( @Autowired(required = false) ClientRegistrationRepository clientRegistrations, @Autowired(required = false) OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) { final RestTemplate restTemplate = DataFlowTemplate.getDefaultDataflowRestTemplate(); validateUsernamePassword(this.properties.getDataflowServerUsername(), this.properties.getDataflowServerPassword()); HttpClientConfigurer clientHttpRequestFactoryBuilder = null; if (this.properties.getOauth2ClientCredentialsClientId() != null || StringUtils.hasText(this.properties.getDataflowServerAccessToken()) || (StringUtils.hasText(this.properties.getDataflowServerUsername()) && StringUtils.hasText(this.properties.getDataflowServerPassword()))) { clientHttpRequestFactoryBuilder = HttpClientConfigurer.create(this.properties.getDataflowServerUri()); } String accessTokenValue = null; if (this.properties.getOauth2ClientCredentialsClientId() != null) { final ClientRegistration clientRegistration = clientRegistrations.findByRegistrationId("default"); final OAuth2ClientCredentialsGrantRequest grantRequest = new OAuth2ClientCredentialsGrantRequest(clientRegistration); final OAuth2AccessTokenResponse res = clientCredentialsTokenResponseClient.getTokenResponse(grantRequest); accessTokenValue = res.getAccessToken().getTokenValue(); logger.debug("Configured OAuth2 Client Credentials for accessing the Data Flow Server"); } else if (StringUtils.hasText(this.properties.getDataflowServerAccessToken())) { accessTokenValue = this.properties.getDataflowServerAccessToken(); logger.debug("Configured OAuth2 Access Token for accessing the Data Flow Server"); } else if (StringUtils.hasText(this.properties.getDataflowServerUsername()) && StringUtils.hasText(this.properties.getDataflowServerPassword())) { accessTokenValue = null; clientHttpRequestFactoryBuilder.basicAuthCredentials(properties.getDataflowServerUsername(), properties.getDataflowServerPassword()); logger.debug("Configured basic security for accessing the Data Flow Server"); } else { logger.debug("Not configuring basic security for accessing the Data Flow Server"); } if (accessTokenValue != null) { restTemplate.getInterceptors().add(new OAuth2AccessTokenProvidingClientHttpRequestInterceptor(accessTokenValue)); } if (clientHttpRequestFactoryBuilder != null) { restTemplate.setRequestFactory(clientHttpRequestFactoryBuilder.buildClientHttpRequestFactory()); } return new DataFlowTemplate(this.properties.getDataflowServerUri(), restTemplate); }
Example 4
Source File: LogoutResource.java From jhipster-registry with Apache License 2.0 | 4 votes |
public LogoutResource(ClientRegistrationRepository registrations) { this.registration = registrations.findByRegistrationId("oidc"); }
Example 5
Source File: DataFlowConfiguration.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
/** * @param clientRegistrations Can be null. Only required for Client Credentials Grant authentication * @param clientCredentialsTokenResponseClient Can be null. Only required for Client Credentials Grant authentication * @return DataFlowOperations */ @Bean public DataFlowOperations dataFlowOperations( @Autowired(required = false) ClientRegistrationRepository clientRegistrations, @Autowired(required = false) OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) { final RestTemplate restTemplate = DataFlowTemplate.getDefaultDataflowRestTemplate(); validateUsernamePassword(this.properties.getDataflowServerUsername(), this.properties.getDataflowServerPassword()); HttpClientConfigurer clientHttpRequestFactoryBuilder = null; if (this.properties.getOauth2ClientCredentialsClientId() != null || StringUtils.hasText(this.properties.getDataflowServerAccessToken()) || (StringUtils.hasText(this.properties.getDataflowServerUsername()) && StringUtils.hasText(this.properties.getDataflowServerPassword()))) { clientHttpRequestFactoryBuilder = HttpClientConfigurer.create(this.properties.getDataflowServerUri()); } String accessTokenValue = null; if (this.properties.getOauth2ClientCredentialsClientId() != null) { final ClientRegistration clientRegistration = clientRegistrations.findByRegistrationId("default"); final OAuth2ClientCredentialsGrantRequest grantRequest = new OAuth2ClientCredentialsGrantRequest(clientRegistration); final OAuth2AccessTokenResponse res = clientCredentialsTokenResponseClient.getTokenResponse(grantRequest); accessTokenValue = res.getAccessToken().getTokenValue(); logger.debug("Configured OAuth2 Client Credentials for accessing the Data Flow Server"); } else if (StringUtils.hasText(this.properties.getDataflowServerAccessToken())) { accessTokenValue = this.properties.getDataflowServerAccessToken(); logger.debug("Configured OAuth2 Access Token for accessing the Data Flow Server"); } else if (StringUtils.hasText(this.properties.getDataflowServerUsername()) && StringUtils.hasText(this.properties.getDataflowServerPassword())) { accessTokenValue = null; clientHttpRequestFactoryBuilder.basicAuthCredentials(properties.getDataflowServerUsername(), properties.getDataflowServerPassword()); logger.debug("Configured basic security for accessing the Data Flow Server"); } else { logger.debug("Not configuring basic security for accessing the Data Flow Server"); } if (accessTokenValue != null) { restTemplate.getInterceptors().add(new OAuth2AccessTokenProvidingClientHttpRequestInterceptor(accessTokenValue)); } if (clientHttpRequestFactoryBuilder != null) { restTemplate.setRequestFactory(clientHttpRequestFactoryBuilder.buildClientHttpRequestFactory()); } return new DataFlowTemplate(this.properties.getDataflowServerUri(), restTemplate); }