use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class ClaimsParameterValidatorTest method shouldErrorValidatingJson.
@Test(expectedExceptions = BadRequestException.class)
public void shouldErrorValidatingJson() throws NotFoundException, BadRequestException, RedirectUriMismatchException, InvalidScopeException, InvalidRequestException, InvalidClientException, ServerException, UnsupportedResponseTypeException {
//given
OAuth2Request mockRequest = mock(OAuth2Request.class);
OAuth2ProviderSettings mockProviderSettings = mock(OAuth2ProviderSettings.class);
String responseTypes = "id_token";
given(mockProviderSettingsFactory.get(mockRequest)).willReturn(mockProviderSettings);
given(mockProviderSettings.getClaimsParameterSupported()).willReturn(true);
given(mockRequest.getParameter(OAuth2Constants.Custom.CLAIMS)).willReturn(invalidClaimsString);
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 ClaimsParameterValidatorTest method shouldErrorValidatingResponseType.
@Test(expectedExceptions = BadRequestException.class)
public void shouldErrorValidatingResponseType() throws NotFoundException, BadRequestException, RedirectUriMismatchException, InvalidScopeException, InvalidRequestException, InvalidClientException, ServerException, UnsupportedResponseTypeException {
//given
OAuth2Request mockRequest = mock(OAuth2Request.class);
OAuth2ProviderSettings mockProviderSettings = mock(OAuth2ProviderSettings.class);
String responseTypes = "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 validateShouldFailWithInvalidRequestExceptionAndQueryParameters.
@Test
public void validateShouldFailWithInvalidRequestExceptionAndQueryParameters() 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("code");
//When
try {
requestValidator.validateRequest(request);
fail();
} catch (InvalidRequestException e) {
//Then
assertEquals(e.getParameterLocation(), OAuth2Constants.UrlLocation.QUERY);
}
}
use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class AuthorizationCodeGrantTypeHandler method checkCodeVerifier.
private void checkCodeVerifier(AuthorizationCode authorizationCode, String codeVerifier) throws InvalidGrantException, InvalidRequestException {
final String codeChallenge = authorizationCode.getCodeChallenge();
final String codeChallengeMethod = authorizationCode.getCodeChallengeMethod();
if (OAuth2Constants.Custom.CODE_CHALLENGE_METHOD_PLAIN.equals(codeChallengeMethod)) {
checkCodeChallenge(codeChallenge, codeVerifier);
} else if (OAuth2Constants.Custom.CODE_CHALLENGE_METHOD_S_256.equals(codeChallengeMethod)) {
String encodedCodeVerifier = null;
try {
encodedCodeVerifier = Base64url.encode(MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII)));
checkCodeChallenge(codeChallenge, encodedCodeVerifier);
} catch (NoSuchAlgorithmException e) {
logger.error("Error encoding code verifier.");
throw new InvalidGrantException();
}
} else {
throw new InvalidRequestException("Invalid code challenge method specified.");
}
}
use of org.forgerock.oauth2.core.exceptions.InvalidRequestException in project OpenAM by OpenRock.
the class OAuth2FlowFinder method create.
/**
* Creates a new instance of the handler for the correct OAuth2 endpoint based from the grant type specified in
* the requests query parameters.
*
* @param request {@inheritDoc}
* @param response {@inheritDoc}
* @return {@inheritDoc}
*/
public ServerResource create(Request request, Response response) {
final OAuth2Request oAuth2Request = requestFactory.create(request);
final String grantType = oAuth2Request.getParameter("grant_type");
if (isEmpty(grantType)) {
logger.error("Type is not set");
return new ErrorResource(exceptionHandler, new InvalidRequestException("Grant type is not set"));
}
Finder finder = endpointClasses.get(grantType);
if (finder == null) {
logger.error("Unsupported grant type: Type is not supported: " + grantType);
return new ErrorResource(exceptionHandler, new UnsupportedGrantTypeException("Grant type is not supported: " + grantType));
}
try {
return finder.create(request, response);
} catch (Exception e) {
logger.warn("Exception while instantiating the target server resource.", e);
return new ErrorResource(exceptionHandler, new ServerException(e.getMessage()));
}
}
Aggregations