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 ClientCredentialsProviderTests method testHardCodedAuthenticationFineClient.
/**
* No Basic authentication provided, only the hard coded client_id.
*/
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testHardCodedAuthenticationFineClient() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "my-client-with-secret");
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);
ResponseEntity<Map> response = restTemplate.exchange(req, Map.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
Map<String, String> body = response.getBody();
String accessToken = body.get("access_token");
assertNotNull(accessToken);
}
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());
}
Aggregations