List of usage examples for org.springframework.security.oauth2.client OAuth2RestTemplate getResource
@Override
public OAuth2ProtectedResourceDetails getResource()
From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java
public String getClientId() { OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations(); return restOperations.getResource().getClientId(); }
From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java
public String getClientSecret() { OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations(); return restOperations.getResource().getClientSecret(); }
From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java
public void setClientId(String clientId) { OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations(); BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) restOperations .getResource();/*from ww w .j a v a 2 s . co m*/ resource.setClientId(clientId); }
From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java
public void setClientSecret(String clientSecret) { OAuth2RestTemplate restOperations = (OAuth2RestTemplate) getRestOperations(); BaseOAuth2ProtectedResourceDetails resource = (BaseOAuth2ProtectedResourceDetails) restOperations .getResource();/*from www . ja v a 2 s. c o m*/ resource.setClientSecret(clientSecret); }
From source file:sparklr.common.AbstractAuthorizationCodeProviderTests.java
private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) { final AtomicReference<String> confirmationPage = new AtomicReference<String>(); AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() { @Override/*from ww w. ja v a2s . c om*/ protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() { return new ResponseExtractor<ResponseEntity<Void>>() { public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException { confirmationPage .set(StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"))); return new ResponseEntity<Void>(response.getHeaders(), response.getStatusCode()); } }; } }; try { provider.obtainAuthorizationCode(restTemplate.getResource(), restTemplate.getOAuth2ClientContext().getAccessTokenRequest()); } catch (UserApprovalRequiredException e) { // ignore } String page = confirmationPage.get(); verifyAuthorizationPage(page); }
From source file:org.cloudfoundry.identity.uaa.integration.RemoteAuthenticationEndpointTests.java
@SuppressWarnings("rawtypes") ResponseEntity<Map> authenticate(String username, String password, Map<String, Object> additionalParams) { RestTemplate restTemplate = new RestTemplate(); // The default java.net client doesn't allow you to handle 4xx responses restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); if (restTemplate instanceof OAuth2RestTemplate) { OAuth2RestTemplate oAuth2RestTemplate = (OAuth2RestTemplate) restTemplate; oAuth2RestTemplate.setErrorHandler( new UaaOauth2ErrorHandler(oAuth2RestTemplate.getResource(), HttpStatus.Series.SERVER_ERROR)); } else {//from ww w.j a v a2 s .co m restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { @Override protected boolean hasError(HttpStatus statusCode) { return statusCode.series() == HttpStatus.Series.SERVER_ERROR; } }); } HttpHeaders headers = new HttpHeaders(); if (additionalParams != null) { headers.add("Authorization", "Bearer " + getLoginReadBearerToken()); } headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(); parameters.set("username", username); if (password != null) { parameters.set("password", password); } if (additionalParams != null) { parameters.setAll(additionalParams); } ResponseEntity<Map> result = restTemplate.exchange(serverRunning.getUrl("/authenticate"), HttpMethod.POST, new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class); return result; }
From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java
private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource, AccessTokenRequest accessTokenRequest) { OAuth2ClientContext context = new DefaultOAuth2ClientContext(accessTokenRequest); OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context); client.setRequestFactory(new SimpleClientHttpRequestFactory() { @Override//from ww w. j a va 2 s . co m protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { super.prepareConnection(connection, httpMethod); connection.setInstanceFollowRedirects(false); } }); client.setErrorHandler(new OAuth2ErrorHandler(client.getResource()) { // Pass errors through in response entity for status code analysis @Override public boolean hasError(ClientHttpResponse response) throws IOException { return false; } @Override public void handleError(ClientHttpResponse response) throws IOException { } }); List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>(); list.add(new StringHttpMessageConverter()); list.add(new MappingJackson2HttpMessageConverter()); client.setMessageConverters(list); return client; }