Search in sources :

Example 36 with NotFoundException

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

the class AuthorizationRequestEndpoint method getAuthorisationApiToken.

protected AccessToken getAuthorisationApiToken() throws ServerException {
    Request req = getRequest();
    ChallengeResponse challengeResponse = req.getChallengeResponse();
    try {
        return oauth2TokenStore.readAccessToken(requestFactory.create(req), challengeResponse.getRawValue());
    } catch (InvalidGrantException e) {
        throw new ServerException("Unable to verify client identity.");
    } catch (NotFoundException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Request(org.restlet.Request) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) InvalidGrantException(org.forgerock.oauth2.core.exceptions.InvalidGrantException) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 37 with NotFoundException

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

the class AuthorizationRequestEndpoint method isEntitled.

private boolean isEntitled(UmaProviderSettings umaProviderSettings, OAuth2ProviderSettings oauth2ProviderSettings, PermissionTicket permissionTicket, String requestingPartyId) throws EntitlementException, ServerException, UmaException {
    String realm = permissionTicket.getRealm();
    String resourceSetId = permissionTicket.getResourceSetId();
    String resourceName = UmaConstants.UMA_POLICY_SCHEME;
    Subject resourceOwnerSubject;
    try {
        ResourceSetStore store = oauth2ProviderSettings.getResourceSetStore();
        Set<ResourceSetDescription> results = store.query(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, resourceSetId));
        if (results.size() != 1) {
            throw new NotFoundException("Could not find Resource Set, " + resourceSetId);
        }
        resourceName += results.iterator().next().getId();
        resourceOwnerSubject = UmaUtils.createSubject(createIdentity(results.iterator().next().getResourceOwnerId(), realm));
    } catch (NotFoundException e) {
        debug.message("Couldn't find resource that permission ticket is registered for", e);
        throw new ServerException("Couldn't find resource that permission ticket is registered for");
    }
    Subject requestingPartySubject = UmaUtils.createSubject(createIdentity(requestingPartyId, realm));
    beforeAuthorization(permissionTicket, requestingPartySubject, resourceOwnerSubject);
    // Implicitly grant access to the resource owner
    if (isRequestingPartyResourceOwner(requestingPartySubject, resourceOwnerSubject)) {
        afterAuthorization(true, permissionTicket, requestingPartySubject, resourceOwnerSubject);
        return true;
    }
    List<Entitlement> entitlements = umaProviderSettings.getPolicyEvaluator(requestingPartySubject, permissionTicket.getResourceServerClientId().toLowerCase()).evaluate(realm, requestingPartySubject, resourceName, null, false);
    Set<String> requestedScopes = permissionTicket.getScopes();
    Set<String> requiredScopes = new HashSet<>(requestedScopes);
    for (Entitlement entitlement : entitlements) {
        for (String requestedScope : requestedScopes) {
            final Boolean actionValue = entitlement.getActionValue(requestedScope);
            if (actionValue != null && actionValue) {
                requiredScopes.remove(requestedScope);
            }
        }
    }
    boolean isAuthorized = requiredScopes.isEmpty();
    afterAuthorization(isAuthorized, permissionTicket, requestingPartySubject, resourceOwnerSubject);
    return isAuthorized;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Subject(javax.security.auth.Subject) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Example 38 with NotFoundException

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

the class UmaProviderSettingsFactory method get.

/**
     * <p>Gets the instance of the UmaProviderSettings.</p>
     *
     * <p>Cache each provider settings on the realm it was created for.</p>
     *
     * @param realm The realm.
     * @return The OAuth2ProviderSettings instance.
     */
public UmaProviderSettings get(String realm) throws NotFoundException {
    synchronized (providerSettingsMap) {
        UmaProviderSettingsImpl providerSettings = providerSettingsMap.get(realm);
        if (providerSettings == null) {
            OAuth2ProviderSettings oAuth2ProviderSettings = oAuth2ProviderSettingsFactory.get(realm);
            providerSettings = getUmaProviderSettings(realm, oAuth2ProviderSettings);
        }
        return providerSettings;
    }
}
Also used : OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings)

Example 39 with NotFoundException

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

the class UmaTokenStore method deletePermissionTicket.

public void deletePermissionTicket(String id) throws NotFoundException, ServerException {
    try {
        // check token is permission ticket
        readPermissionTicket(id);
        cts.delete(id);
    } catch (CoreTokenException e) {
        throw new ServerException("Could not delete token: " + id);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 40 with NotFoundException

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

the class ResourceSetRegistrationEndpointTest method setup.

@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws ServerException, InvalidGrantException, NotFoundException {
    store = mock(ResourceSetStore.class);
    validator = mock(ResourceSetDescriptionValidator.class);
    OAuth2RequestFactory<?, Request> requestFactory = mock(OAuth2RequestFactory.class);
    Set<ResourceSetRegistrationHook> hooks = new HashSet<>();
    hook = mock(ResourceSetRegistrationHook.class);
    hooks.add(hook);
    labelRegistration = mock(ResourceSetLabelRegistration.class);
    ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
    resourceRegistrationFilter = mock(ResourceRegistrationFilter.class);
    given(extensionFilterManager.getFilters(ResourceRegistrationFilter.class)).willReturn(Collections.singletonList(resourceRegistrationFilter));
    OAuth2ProviderSettingsFactory providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    OAuth2ProviderSettings providerSettings = mock(OAuth2ProviderSettings.class);
    given(providerSettingsFactory.get(Matchers.<OAuth2Request>anyObject())).willReturn(providerSettings);
    given(providerSettings.getResourceSetStore()).willReturn(store);
    ExceptionHandler exceptionHandler = mock(ExceptionHandler.class);
    UmaLabelsStore umaLabelsStore = mock(UmaLabelsStore.class);
    endpoint = spy(new ResourceSetRegistrationEndpoint(providerSettingsFactory, validator, requestFactory, hooks, labelRegistration, extensionFilterManager, exceptionHandler, umaLabelsStore, jacksonRepresentationFactory));
    Request request = mock(Request.class);
    ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_BASIC);
    challengeResponse.setRawValue("PAT");
    given(request.getChallengeResponse()).willReturn(challengeResponse);
    given(endpoint.getRequest()).willReturn(request);
    AccessToken accessToken = mock(AccessToken.class);
    given(accessToken.getClientId()).willReturn("CLIENT_ID");
    given(accessToken.getResourceOwnerId()).willReturn("RESOURCE_OWNER_ID");
    response = mock(Response.class);
    given(endpoint.getResponse()).willReturn(response);
    OAuth2Request oAuth2Request = mock(OAuth2Request.class);
    given(requestFactory.create(Matchers.<Request>anyObject())).willReturn(oAuth2Request);
    given(oAuth2Request.getToken(AccessToken.class)).willReturn(accessToken);
}
Also used : ResourceSetRegistrationHook(org.forgerock.oauth2.restlet.resources.ResourceSetRegistrationHook) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Request(org.restlet.Request) ResourceRegistrationFilter(org.forgerock.openam.oauth2.extensions.ResourceRegistrationFilter) ResourceSetDescriptionValidator(org.forgerock.oauth2.restlet.resources.ResourceSetDescriptionValidator) ChallengeResponse(org.restlet.data.ChallengeResponse) ExceptionHandler(org.forgerock.oauth2.restlet.ExceptionHandler) ChallengeResponse(org.restlet.data.ChallengeResponse) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) AccessToken(org.forgerock.oauth2.core.AccessToken) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) UmaLabelsStore(org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) HashSet(java.util.HashSet) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)44 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)34 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)28 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)24 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)21 JsonValue (org.forgerock.json.JsonValue)20 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)13 AccessToken (org.forgerock.oauth2.core.AccessToken)12 ClientRegistration (org.forgerock.oauth2.core.ClientRegistration)11 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 Request (org.restlet.Request)11 SSOException (com.iplanet.sso.SSOException)10 HashSet (java.util.HashSet)10 AMIdentity (com.sun.identity.idm.AMIdentity)9 HashMap (java.util.HashMap)9 IdRepoException (com.sun.identity.idm.IdRepoException)8 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)8 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)8