List of usage examples for org.springframework.http HttpHeaders setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
From source file:org.apache.fineract.restwebservice.PlatformRestClient.java
/** * Creates a new {@link HttpEntity} object for the HTTP request * // ww w . j a v a 2s.co m * @param entityBody * @param basicAuthenticationCredentials * @param contentMediaType * @param acceptedResponseMediaTypes * @return {@link HttpEntity} object */ public HttpEntity<String> getHttpRequestEntity(final String entityBody, final MediaType contentMediaType, final List<MediaType> acceptedResponseMediaTypes) { final HttpHeaders entityHeaders = new HttpHeaders(); entityHeaders.setContentType(contentMediaType); entityHeaders.setAccept(acceptedResponseMediaTypes); if (StringUtils.isNotEmpty(basicAuthenticationCredentials)) { entityHeaders.add("Authorization", "Basic " + this.basicAuthenticationCredentials); } return new HttpEntity<String>(entityBody, entityHeaders); }
From source file:org.apache.geode.management.internal.web.http.support.HttpRequester.java
void addHeaderValues(HttpHeaders headers) { // update the headers headers.add(HttpHeaders.USER_AGENT, USER_AGENT_HTTP_REQUEST_HEADER_VALUE); headers.setAccept(acceptableMediaTypes); if (this.securityProperties != null) { for (String key : securityProperties.stringPropertyNames()) { headers.add(key, securityProperties.getProperty(key)); }/*from w w w .ja v a2 s . c om*/ } }
From source file:org.cloudfoundry.identity.client.UaaContextFactory.java
protected UaaContext fetchTokenFromCode(final TokenRequest request) { String clientBasicAuth = getClientBasicAuthHeader(request); RestTemplate template = new RestTemplate(); if (request.isSkipSslValidation()) { template.setRequestFactory(getNoValidatingClientHttpRequestFactory()); }// w ww. j a v a 2 s.c o m HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.AUTHORIZATION, clientBasicAuth); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); form.add(OAuth2Utils.GRANT_TYPE, "authorization_code"); form.add(OAuth2Utils.REDIRECT_URI, request.getRedirectUri().toString()); String responseType = "token"; if (request.wantsIdToken()) { responseType += " id_token"; } form.add(OAuth2Utils.RESPONSE_TYPE, responseType); form.add("code", request.getAuthorizationCode()); ResponseEntity<CompositeAccessToken> token = template.exchange(request.getTokenEndpoint(), HttpMethod.POST, new HttpEntity<>(form, headers), CompositeAccessToken.class); return new UaaContextImpl(request, null, token.getBody()); }
From source file:org.cloudfoundry.identity.client.UaaContextFactory.java
protected UaaContext authenticateSaml2BearerAssertion(final TokenRequest request) { RestTemplate template = new RestTemplate(); if (request.isSkipSslValidation()) { template.setRequestFactory(getNoValidatingClientHttpRequestFactory()); }/*w w w .ja v a2 s. c om*/ HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); form.add(OAuth2Utils.CLIENT_ID, request.getClientId()); form.add("client_secret", request.getClientSecret()); form.add(OAuth2Utils.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:saml2-bearer"); form.add("assertion", request.getAuthCodeAPIToken()); ResponseEntity<CompositeAccessToken> token = template.exchange(request.getTokenEndpoint(), HttpMethod.POST, new HttpEntity<>(form, headers), CompositeAccessToken.class); return new UaaContextImpl(request, null, token.getBody()); }
From source file:org.cloudfoundry.identity.uaa.authentication.manager.RestAuthenticationManager.java
protected HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); return headers; }
From source file:org.cloudfoundry.identity.uaa.integration.CheckTokenEndpointIntegrationTests.java
@Test public void testTokenKey() { HttpHeaders headers = new HttpHeaders(); ClientCredentialsResourceDetails resource = testAccounts.getClientCredentialsResource("app", null, "app", "appclientsecret"); headers.set("Authorization", testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret())); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/token_key", Map.class, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> map = response.getBody(); assertNotNull(map.get("alg")); assertNotNull(map.get("value")); }
From source file:org.cloudfoundry.identity.uaa.integration.CheckTokenEndpointIntegrationTests.java
@Test public void testUnauthorized() { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("token", "FOO"); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/check_token", formData, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> map = response.getBody(); assertTrue(map.containsKey("error")); }
From source file:org.cloudfoundry.identity.uaa.integration.CheckTokenEndpointIntegrationTests.java
@Test public void testForbidden() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("token", "FOO"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode("cf:".getBytes("UTF-8")))); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/check_token", formData, headers); assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> map = response.getBody(); assertTrue(map.containsKey("error")); }
From source file:org.cloudfoundry.identity.uaa.integration.CheckTokenEndpointIntegrationTests.java
@Test public void testInvalidScope() { OAuth2AccessToken accessToken = getAdminToken(); String requestBody = String.format("token=%s&scopes=%s", accessToken.getValue(), "uaa.resource%"); HttpHeaders headers = new HttpHeaders(); ClientCredentialsResourceDetails resource = testAccounts.getClientCredentialsResource("app", null, "app", "appclientsecret"); headers.set("Authorization", testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret())); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/check_token", requestBody, headers); System.out.println(response.getBody()); assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> map = response.getBody(); assertEquals("parameter_parsing_error", map.get("error")); assertTrue(map.containsKey("error_description")); }
From source file:org.cloudfoundry.identity.uaa.integration.CheckTokenEndpointIntegrationTests.java
@SuppressWarnings("unchecked") private OAuth2AccessToken getAdminToken() { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.set("client_id", testAccounts.getAdminClientId()); formData.set("client_secret", testAccounts.getAdminClientSecret()); formData.set("response_type", "token"); formData.set("grant_type", "client_credentials"); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/oauth/token", formData, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); return DefaultOAuth2AccessToken.valueOf(response.getBody()); }