List of usage examples for org.springframework.security.oauth2.client OAuth2RestTemplate setAccessTokenProvider
public void setAccessTokenProvider(AccessTokenProvider accessTokenProvider)
From source file:org.trustedanalytics.servicecatalog.service.ServiceConfig.java
@Bean @Scope(value = SCOPE_REQUEST, proxyMode = TARGET_CLASS) public OAuth2RestTemplate clientRestTemplate(OAuth2ClientContext clientContext, ClientCredentialsResourceDetails clientCredentials) { OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentials, clientContext); ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider(); template.setAccessTokenProvider(provider); return template; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.ApplicationConfiguration.java
@Bean public OAuth2RestTemplate oAuth2RestTemplate(OAuth2ProtectedResourceDetails clientCredentials, OAuth2ClientContext clientContext) { OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentials, clientContext); ClientCredentialsAccessTokenProvider tokenProvider = new ClientCredentialsAccessTokenProvider(); template.setAccessTokenProvider(tokenProvider); return template; }
From source file:org.trustedanalytics.user.common.RestTemplatesConfiguration.java
@Bean public OAuth2RestTemplate clientRestTemplate(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails clientCredentials) { OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentials, oauth2ClientContext); ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider(); template.setAccessTokenProvider(provider); return template; }
From source file:org.trustedanalytics.platformoperations.ApplicationConfiguration.java
@Bean public OAuth2RestTemplate clientRestTemplate() { OAuth2RestTemplate template = new OAuth2RestTemplate(clientCredentials()); ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider(); template.setAccessTokenProvider(provider); return template; }
From source file:org.openmhealth.shim.OAuth2ShimBase.java
protected OAuth2RestOperations restTemplate(String stateKey, String code) { DefaultAccessTokenRequest existingRequest = stateKey != null && authorizationRequestParametersRepo.findByStateKey(stateKey) != null ? (DefaultAccessTokenRequest) SerializationUtils.deserialize( authorizationRequestParametersRepo.findByStateKey(stateKey).getSerializedRequest()) : null;//www. jav a 2s . co m if (existingRequest != null && code != null) { existingRequest.set("code", code); } DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext( existingRequest != null ? existingRequest : new DefaultAccessTokenRequest()); if (existingRequest != null) { context.setPreservedState(stateKey, "NONE"); } OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(getResource(), context); AccessTokenProviderChain tokenProviderChain = new AccessTokenProviderChain( new ArrayList<>(Arrays.asList(getAuthorizationCodeAccessTokenProvider()))); tokenProviderChain.setClientTokenServices(new AccessParameterClientTokenServices(accessParametersRepo)); restTemplate.setAccessTokenProvider(tokenProviderChain); return restTemplate; }
From source file:org.cloudfoundry.identity.client.UaaContextFactory.java
/** * If the {@link TokenRequest#isSkipSslValidation()} returns true, the rest template * will be configured/*from w ww . ja v a2s . c o m*/ * @param tokenRequest * @param template */ protected void skipSslValidation(TokenRequest tokenRequest, OAuth2RestTemplate template, List<OAuth2AccessTokenSupport> existingProviders) { ClientHttpRequestFactory requestFactory = null; if (tokenRequest.isSkipSslValidation()) { requestFactory = getNoValidatingClientHttpRequestFactory(); } List<OAuth2AccessTokenSupport> accessTokenProviders = existingProviders != null ? existingProviders : Arrays.<OAuth2AccessTokenSupport>asList(new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(), new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()); List<AccessTokenProvider> providers = new ArrayList<>(); for (OAuth2AccessTokenSupport provider : accessTokenProviders) { if (requestFactory != null) { provider.setRequestFactory(requestFactory); } providers.add((AccessTokenProvider) provider); } AccessTokenProviderChain chain = new AccessTokenProviderChain(providers); template.setAccessTokenProvider(chain); }
From source file:org.springframework.security.oauth2.client.test.OAuth2ContextSetup.java
private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) {// w ww.ja va 2 s . co m OAuth2ClientContext context = new DefaultOAuth2ClientContext(request); OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context); client.setRequestFactory(new SimpleClientHttpRequestFactory() { @Override protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { super.prepareConnection(connection, httpMethod); connection.setInstanceFollowRedirects(false); } }); client.setErrorHandler(new ResponseErrorHandler() { // Pass errors through in response entity for status code analysis public boolean hasError(ClientHttpResponse response) throws IOException { return false; } public void handleError(ClientHttpResponse response) throws IOException { } }); if (accessTokenProvider != null) { client.setAccessTokenProvider(accessTokenProvider); } return client; }