use of org.springframework.http.HttpHeaders in project spring-security-oauth by spring-projects.
the class ResourceOwnerPasswordProviderTests method testUnauthenticatedErrorMessage.
@Test
public void testUnauthenticatedErrorMessage() throws Exception {
HttpHeaders headers = new HttpHeaders();
ResponseEntity<Void> response = serverRunning.getForResponse("/sparklr2/photos?format=json", headers);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
String authenticate = response.getHeaders().getFirst("WWW-Authenticate");
assertTrue("Wrong header: " + authenticate, authenticate.contains("error=\"unauthorized\""));
}
use of org.springframework.http.HttpHeaders in project spring-security-oauth by spring-projects.
the class ServerRunning method postForString.
public ResponseEntity<String> postForString(String path, HttpHeaders headers, MultiValueMap<String, String> formData) {
HttpHeaders actualHeaders = new HttpHeaders();
actualHeaders.putAll(headers);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, actualHeaders), String.class);
}
use of org.springframework.http.HttpHeaders in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testHardCodedAuthenticationWrongClient.
@Test
public void testHardCodedAuthenticationWrongClient() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "my-trusted-client");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RequestEntity<MultiValueMap<String, String>> req = new RequestEntity<MultiValueMap<String, String>>(params, headers, HttpMethod.POST, tokenUri);
try {
restTemplate.exchange(req, Map.class);
fail("Expected HTTP 401");
} catch (HttpStatusCodeException e) {
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
}
}
use of org.springframework.http.HttpHeaders in project spring-security-oauth by spring-projects.
the class CustomProviderTests method invalidGrant.
@Test
public void invalidGrant() throws Exception {
LinkedMultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("grant_type", "foo");
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Basic " + new String(Base64.encode(("my-trusted-client:").getBytes())));
@SuppressWarnings("rawtypes") ResponseEntity<Map> response = http.postForMap("/oauth/token", headers, form);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
use of org.springframework.http.HttpHeaders in project spring-security-oauth by spring-projects.
the class DefaultOAuth2ExceptionRenderer method handleHttpEntityResponse.
public void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
if (responseEntity == null) {
return;
}
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
}
HttpHeaders entityHeaders = responseEntity.getHeaders();
if (!entityHeaders.isEmpty()) {
outputMessage.getHeaders().putAll(entityHeaders);
}
Object body = responseEntity.getBody();
if (body != null) {
writeWithMessageConverters(body, inputMessage, outputMessage);
} else {
// flush headers
outputMessage.getBody();
}
}
Aggregations