use of org.springframework.http.client.ClientHttpResponse in project spring-security-oauth by spring-projects.
the class OAuth2ErrorHandlerTests method testHandleGeneric403Error.
@Test
public void testHandleGeneric403Error() throws Exception {
HttpHeaders headers = new HttpHeaders();
ClientHttpResponse response = new TestClientHttpResponse(headers, 403);
expected.expect(HttpClientErrorException.class);
handler.handleError(response);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-security-oauth by spring-projects.
the class OAuth2ErrorHandlerTests method testHandleErrorWithInvalidToken.
@Test
public void testHandleErrorWithInvalidToken() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.set("www-authenticate", "Bearer error=\"invalid_token\", description=\"foo\"");
ClientHttpResponse response = new TestClientHttpResponse(headers, 401);
expected.expect(AccessTokenRequiredException.class);
expected.expectMessage("OAuth2 access denied");
handler.handleError(response);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-security-oauth by spring-projects.
the class AbstractResourceOwnerPasswordProviderTests method createAccessTokenProvider.
@Override
protected ResourceOwnerPasswordAccessTokenProvider createAccessTokenProvider() {
ResourceOwnerPasswordAccessTokenProvider accessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
final ResponseErrorHandler errorHandler = super.getResponseErrorHandler();
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
response.getHeaders();
response.getStatusCode();
tokenEndpointResponse = response;
errorHandler.handleError(response);
}
};
}
@Override
protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
final ResponseExtractor<OAuth2AccessToken> extractor = super.getResponseExtractor();
return new ResponseExtractor<OAuth2AccessToken>() {
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
response.getHeaders();
response.getStatusCode();
tokenEndpointResponse = response;
return extractor.extractData(response);
}
};
}
};
return accessTokenProvider;
}
use of org.springframework.http.client.ClientHttpResponse in project spring-security-oauth by spring-projects.
the class AbstractClientCredentialsProviderTests method createAccessTokenProvider.
@Override
protected AccessTokenProvider createAccessTokenProvider() {
return new ClientCredentialsAccessTokenProvider() {
@Override
protected ResponseErrorHandler getResponseErrorHandler() {
final ResponseErrorHandler delegate = super.getResponseErrorHandler();
return new DefaultResponseErrorHandler() {
public void handleError(ClientHttpResponse response) throws IOException {
responseHeaders = response.getHeaders();
responseStatus = response.getStatusCode();
delegate.handleError(response);
}
};
}
};
}
use of org.springframework.http.client.ClientHttpResponse in project spring-security-oauth by spring-projects.
the class AbstractEmptyAuthorizationCodeProviderTests method verifyAuthorizationPage.
private void verifyAuthorizationPage(OAuth2RestTemplate restTemplate, String location) {
final AtomicReference<String> confirmationPage = new AtomicReference<String>();
AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider() {
@Override
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);
}
Aggregations