use of org.springframework.security.oauth2.common.exceptions.InvalidClientException in project spring-security-oauth by spring-projects.
the class DefaultOAuth2RequestFactory method createTokenRequest.
public TokenRequest createTokenRequest(Map<String, String> requestParameters, ClientDetails authenticatedClient) {
String clientId = requestParameters.get(OAuth2Utils.CLIENT_ID);
if (clientId == null) {
// if the clientId wasn't passed in in the map, we add pull it from the authenticated client object
clientId = authenticatedClient.getClientId();
} else {
// otherwise, make sure that they match
if (!clientId.equals(authenticatedClient.getClientId())) {
throw new InvalidClientException("Given client ID does not match authenticated client");
}
}
String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE);
Set<String> scopes = extractScopes(requestParameters, clientId);
TokenRequest tokenRequest = new TokenRequest(requestParameters, clientId, scopes, grantType);
return tokenRequest;
}
use of org.springframework.security.oauth2.common.exceptions.InvalidClientException in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetErrorFromJson.
@Test
public void testGetErrorFromJson() throws Exception {
final InvalidClientException exception = new InvalidClientException("FOO");
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, new ObjectMapper().writeValueAsString(exception));
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
expected.expect(OAuth2AccessDeniedException.class);
expected.expect(hasCause(instanceOf(InvalidClientException.class)));
setUpRestTemplate();
provider.obtainAccessToken(resource, request);
}
use of org.springframework.security.oauth2.common.exceptions.InvalidClientException in project spring-security-oauth by spring-projects.
the class DefaultOAuth2SerializationServiceTests method testExceptionDeserialization.
@Test
public void testExceptionDeserialization() throws Exception {
Map<String, String> exception = MapBuilder.create("error", "invalid_client").add("error_description", "FOO").build();
OAuth2Exception result = OAuth2Exception.valueOf(exception);
// System.err.println(result);
assertEquals("FOO", result.getMessage());
assertEquals("invalid_client", result.getOAuth2ErrorCode());
assertTrue(result instanceof InvalidClientException);
}
use of org.springframework.security.oauth2.common.exceptions.InvalidClientException in project spring-security-oauth by spring-projects.
the class JsonSerializationTests method testExceptionDeserialization.
@Test
public void testExceptionDeserialization() throws Exception {
String exception = "{\"error\": \"invalid_client\", \"error_description\": \"FOO\", \"foo\": \"bar\"}";
OAuth2Exception result = new ObjectMapper().readValue(exception, OAuth2Exception.class);
// System.err.println(result);
assertEquals("FOO", result.getMessage());
assertEquals("invalid_client", result.getOAuth2ErrorCode());
assertEquals("{foo=bar}", result.getAdditionalInformation().toString());
assertTrue(result instanceof InvalidClientException);
}
use of org.springframework.security.oauth2.common.exceptions.InvalidClientException in project spring-security-oauth by spring-projects.
the class WhitelabelErrorEndpointTests method testErrorPage.
@Test
public void testErrorPage() throws Exception {
request.setContextPath("/foo");
request.setAttribute("error", new InvalidClientException("FOO"));
ModelAndView result = endpoint.handleError(request);
result.getView().render(result.getModel(), request, response);
String content = response.getContentAsString();
assertTrue("Wrong content: " + content, content.contains("OAuth Error"));
assertTrue("Wrong content: " + content, content.contains("invalid_client"));
}
Aggregations