Search in sources :

Example 36 with InvalidClientException

use of org.forgerock.oauth2.core.exceptions.InvalidClientException 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
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 37 with InvalidClientException

use of org.forgerock.oauth2.core.exceptions.InvalidClientException in project OpenAM by OpenRock.

the class SubjectTypeValidatorTest method shouldValidateRequest.

@Test
public void shouldValidateRequest() throws InvalidClientException, NotFoundException, ServerException {
    //given
    OAuth2ProviderSettings mockProviderSettings = mock(OAuth2ProviderSettings.class);
    OAuth2Request mockRequest = mock(OAuth2Request.class);
    OpenIdConnectClientRegistration mockClientRegistration = mock(OpenIdConnectClientRegistration.class);
    Set<String> subjectTypesSupported = new HashSet<String>();
    subjectTypesSupported.add("public");
    given(mockProviderSettingsFactory.get(mockRequest)).willReturn(mockProviderSettings);
    given(mockProviderSettings.getSupportedSubjectTypes()).willReturn(subjectTypesSupported);
    given(mockRequest.getParameter(OAuth2Constants.Params.CLIENT_ID)).willReturn("CLIENT_ID");
    given(mockClientRegistrationStore.get("CLIENT_ID", mockRequest)).willReturn(mockClientRegistration);
    given(mockClientRegistration.getSubjectType()).willReturn("public");
    //when
    subjectTypeValidator.validateRequest(mockRequest);
//then
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 38 with InvalidClientException

use of org.forgerock.oauth2.core.exceptions.InvalidClientException in project OpenAM by OpenRock.

the class SubjectTypeValidatorTest method shouldFailSubjectTypeNotSupported.

@Test(expectedExceptions = InvalidClientException.class)
public void shouldFailSubjectTypeNotSupported() throws InvalidClientException, NotFoundException, ServerException {
    //given
    OAuth2ProviderSettings mockProviderSettings = mock(OAuth2ProviderSettings.class);
    OAuth2Request mockRequest = mock(OAuth2Request.class);
    OpenIdConnectClientRegistration mockClientRegistration = mock(OpenIdConnectClientRegistration.class);
    Set<String> subjectTypesSupported = new HashSet<String>();
    subjectTypesSupported.add("public");
    given(mockProviderSettingsFactory.get(mockRequest)).willReturn(mockProviderSettings);
    given(mockProviderSettings.getSupportedSubjectTypes()).willReturn(subjectTypesSupported);
    given(mockRequest.getParameter(OAuth2Constants.Params.CLIENT_ID)).willReturn("CLIENT_ID");
    given(mockClientRegistrationStore.get("CLIENT_ID", mockRequest)).willReturn(mockClientRegistration);
    given(mockClientRegistration.getSubjectType()).willReturn("pairwise");
    //when
    subjectTypeValidator.validateRequest(mockRequest);
//then
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)14 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)13 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)12 ClientRegistration (org.forgerock.oauth2.core.ClientRegistration)11 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)8 Test (org.testng.annotations.Test)6 HashSet (java.util.HashSet)5 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)5 OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)5 BeforeTest (org.testng.annotations.BeforeTest)5 JsonValue (org.forgerock.json.JsonValue)4 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)4 RedirectUriMismatchException (org.forgerock.oauth2.core.exceptions.RedirectUriMismatchException)4 JSONObject (org.json.JSONObject)4 Request (org.restlet.Request)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AccessToken (org.forgerock.oauth2.core.AccessToken)3 ClientRegistrationStore (org.forgerock.oauth2.core.ClientRegistrationStore)3