Search in sources :

Example 51 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException 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 52 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException 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 53 with ServerException

use of org.forgerock.oauth2.core.exceptions.ServerException 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)

Example 54 with ServerException

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

the class OpenAMResourceSetStore method create.

@Override
public void create(OAuth2Request request, ResourceSetDescription resourceSetDescription) throws ServerException, BadRequestException, NotFoundException {
    resourceSetDescription.setId(idGenerator.generateTokenId(null));
    String policyEndpoint = oauth2UrisFactory.get(request).getResourceSetRegistrationPolicyEndpoint(resourceSetDescription.getId());
    resourceSetDescription.setPolicyUri(policyEndpoint);
    resourceSetDescription.setRealm(realm);
    try {
        delegate.create(resourceSetDescription);
    } catch (org.forgerock.openam.sm.datalayer.store.ServerException e) {
        throw new ServerException(e);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException)

Example 55 with ServerException

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

the class OpenAMResourceSetStore method update.

@Override
public void update(ResourceSetDescription resourceSetDescription) throws NotFoundException, ServerException {
    try {
        if (!realm.equals(resourceSetDescription.getRealm())) {
            throw new ServerException("Could not read token with id, " + resourceSetDescription.getId() + ", in realm, " + realm);
        }
        read(resourceSetDescription.getId(), resourceSetDescription.getResourceOwnerId());
        delegate.update(resourceSetDescription);
    } catch (org.forgerock.openam.sm.datalayer.store.NotFoundException e) {
        throw new NotFoundException("Resource set does not exist with id " + resourceSetDescription.getId());
    } catch (org.forgerock.openam.sm.datalayer.store.ServerException e) {
        throw new ServerException(e);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)60 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)31 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)25 JsonValue (org.forgerock.json.JsonValue)18 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)18 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)14 HashMap (java.util.HashMap)13 AccessToken (org.forgerock.oauth2.core.AccessToken)13 HashSet (java.util.HashSet)12 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 SSOException (com.iplanet.sso.SSOException)9 Request (org.restlet.Request)9 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8 Map (java.util.Map)7 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)7 JSONObject (org.json.JSONObject)7 SMSException (com.sun.identity.sm.SMSException)6 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)6