use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class OpenAMOAuth2ProviderSettings method validateRequestedClaims.
@Override
public String validateRequestedClaims(String requestedClaims) throws InvalidRequestException, ServerException {
if (!getClaimsParameterSupported()) {
return null;
}
if (StringUtils.isBlank(requestedClaims)) {
return null;
}
final Set<String> claims = new HashSet<String>();
try {
JSONObject json = new JSONObject(requestedClaims);
JSONObject userinfo = json.optJSONObject(OAuth2Constants.UserinfoEndpoint.USERINFO);
JSONObject id_token = json.optJSONObject(OAuth2Constants.JWTTokenParams.ID_TOKEN);
if (userinfo != null) {
Iterator<String> it = userinfo.keys();
while (it.hasNext()) {
claims.add(it.next());
}
}
if (id_token != null) {
Iterator<String> it = id_token.keys();
while (it.hasNext()) {
claims.add(it.next());
}
}
} catch (JSONException e) {
throw new InvalidRequestException("Requested claims must be valid json.");
}
if (!getSupportedClaims().containsAll(claims)) {
throw new InvalidRequestException("Requested claims must be allowed by the client's configuration");
}
return requestedClaims;
}
use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class OpenIdConnectAuthorizeRequestValidator method validateRequest.
/**
* {@inheritDoc}
*/
public void validateRequest(OAuth2Request request) throws BadRequestException, InvalidRequestException, InvalidClientException, InvalidScopeException, NotFoundException {
validateOpenIdScope(request);
try {
OpenIdPrompt prompt = new OpenIdPrompt(request);
Reject.ifFalse(prompt.isValid(), "Prompt parameter " + prompt.getOriginalValue() + " is invalid or unsupported");
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
}
}
use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class ClaimsParameterValidatorTest method shouldValidateClaimsParameter.
@Test
public void shouldValidateClaimsParameter() throws NotFoundException, BadRequestException, RedirectUriMismatchException, InvalidScopeException, InvalidRequestException, InvalidClientException, ServerException, UnsupportedResponseTypeException {
//given
OAuth2Request mockRequest = mock(OAuth2Request.class);
OAuth2ProviderSettings mockProviderSettings = mock(OAuth2ProviderSettings.class);
String responseTypes = "code token id_token";
given(mockProviderSettingsFactory.get(mockRequest)).willReturn(mockProviderSettings);
given(mockProviderSettings.getClaimsParameterSupported()).willReturn(true);
given(mockRequest.getParameter(OAuth2Constants.Custom.CLAIMS)).willReturn(validClaimsString);
given(mockRequest.getParameter(OAuth2Constants.Params.RESPONSE_TYPE)).willReturn(responseTypes);
//when
claimsParameterValidator.validateRequest(mockRequest);
//then
}
use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class OpenIdConnectAuthorizeRequestValidatorTest method validateShouldFailWithInvalidRequestExceptionAndFragmentParameters.
@Test
public void validateShouldFailWithInvalidRequestExceptionAndFragmentParameters() throws Exception {
//Given
OAuth2Request request = mock(OAuth2Request.class);
given(clientRegistration.getAllowedScopes()).willReturn(Collections.singleton("openid"));
given(request.getParameter("client_id")).willReturn("CLIENT_ID");
given(request.getParameter("scope")).willReturn("nothing");
given(request.getParameter("response_type")).willReturn("id_token");
//When
try {
requestValidator.validateRequest(request);
fail();
} catch (InvalidRequestException e) {
//Then
assertEquals(e.getParameterLocation(), OAuth2Constants.UrlLocation.FRAGMENT);
}
}
Aggregations