Search in sources :

Example 1 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestResource method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (request.getQueryFilter() == null) {
        return new NotSupportedException("Only query filter is supported.").asPromise();
    }
    try {
        List<ResourceResponse> values = new ArrayList<>();
        // Filter items based on query filter.
        for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
            if (request.getQueryFilter().accept(QUERY_VISITOR, pendingRequest.asJson())) {
                values.add(newResourceResponse(pendingRequest.getId(), null, pendingRequest.asJson()));
            }
        }
        // Sort and Page for presentation
        QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
        return QueryResponsePresentation.perform(handler, request, values);
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 2 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    try {
        if (APPROVE_ACTION_ID.equalsIgnoreCase(request.getAction())) {
            List<Promise<Void, ResourceException>> promises = new ArrayList<>();
            JsonValue content = request.getContent();
            for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
                promises.add(service.approvePendingRequest(context, pendingRequest.getId(), content.get(pendingRequest.getId()), ServerContextUtils.getRealm(context)));
            }
            return handlePendingRequestApproval(promises);
        } else if (DENY_ACTION_ID.equalsIgnoreCase(request.getAction())) {
            for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
                service.denyPendingRequest(pendingRequest.getId(), ServerContextUtils.getRealm(context));
            }
            return newResultPromise(newActionResponse((json(object()))));
        } else {
            return new NotSupportedException("Action, " + request.getAction() + ", is not supported.").asPromise();
        }
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : Promise(org.forgerock.util.promise.Promise) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 3 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsService method denyPendingRequest.

/**
     * Denies the pending request with the specified {@literal id}.
     *
     * @param id The pending request id.
     * @param realm The current realm.
     * @throws ResourceException If the pending request is not found or could not be marked as denied.
     */
public void denyPendingRequest(String id, String realm) throws ResourceException {
    try {
        UmaPendingRequest request = store.read(id);
        store.delete(id);
        AMIdentity resourceOwner = coreWrapper.getIdentity(request.getResourceOwnerId(), realm);
        auditLogger.log(request.getResourceSetId(), request.getResourceSetName(), resourceOwner, UmaAuditType.REQUEST_DENIED, request.getRequestingPartyId());
    } catch (NotFoundException e) {
        throw new org.forgerock.json.resource.NotFoundException("Pending request, " + id + ", not found", e);
    } catch (ServerException e) {
        throw new InternalServerErrorException("Failed to mark pending request, " + id + ", as denied", e);
    }
}
Also used : ServerException(org.forgerock.openam.sm.datalayer.store.ServerException) AMIdentity(com.sun.identity.idm.AMIdentity) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) NotFoundException(org.forgerock.openam.sm.datalayer.store.NotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException)

Example 4 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsService method createPendingRequest.

/**
     * Creates a pending request.
     *
     * @param httpRequest The {@code HttpServletRequest}.
     * @param resourceSetId The resource set id.
     * @param resourceSetName The resource set name.
     * @param resourceOwnerId The resource owner id.
     * @param requestingPartyId The requesting party id.
     * @param realm The realm.
     * @param scopes The requested scopes.
     * @throws ServerException If the pending request
     * could not be created.
     */
public void createPendingRequest(HttpServletRequest httpRequest, String resourceSetId, String resourceSetName, String resourceOwnerId, String requestingPartyId, String realm, Set<String> scopes) throws ServerException {
    UmaPendingRequest pendingRequest = new UmaPendingRequest(resourceSetId, resourceSetName, resourceOwnerId, realm, requestingPartyId, scopes);
    store.create(pendingRequest);
    if (isEmailResourceOwnerOnPendingRequestCreationEnabled(realm)) {
        Pair<String, String> template = pendingRequestEmailTemplate.getCreationTemplate(resourceOwnerId, realm);
        try {
            String scopesString = pendingRequestEmailTemplate.buildScopeString(scopes, resourceOwnerId, realm);
            String baseUrl = baseURLProviderFactory.get(realm).getRootURL(httpRequest);
            emailService.email(realm, resourceOwnerId, template.getFirst(), MessageFormat.format(template.getSecond(), requestingPartyId, resourceSetName, scopesString, baseUrl, pendingRequest.getId()));
        } catch (MessagingException e) {
            debug.warning("Pending Request Creation email could not be sent", e);
        }
    }
}
Also used : MessagingException(javax.mail.MessagingException) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)

Example 5 with UmaPendingRequest

use of org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest in project OpenAM by OpenRock.

the class PendingRequestsService method approvePendingRequest.

/**
     * Approves the pending request with the specified {@literal id}.
     *
     * @param context The request context.
     * @param id The pending request id.
     * @param content The content of the approval request.
     * @param realm The current realm.  @return {@code Promise} which is completed successfully or
     *              failed with a {@code ResourceException}.
     */
public Promise<Void, ResourceException> approvePendingRequest(Context context, String id, JsonValue content, String realm) {
    try {
        final UmaPendingRequest request = store.read(id);
        Collection<String> scopes = getScopes(request, content);
        return createUmaPolicy(context, request, scopes).thenAsync(approvePendingRequest(request, scopes, id, realm));
    } catch (NotFoundException e) {
        return new org.forgerock.json.resource.NotFoundException("Pending request, " + id + ", not found", e).asPromise();
    } catch (ServerException e) {
        return new InternalServerErrorException("Failed to mark pending request, " + id + ", as approved", e).asPromise();
    }
}
Also used : ServerException(org.forgerock.openam.sm.datalayer.store.ServerException) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) NotFoundException(org.forgerock.openam.sm.datalayer.store.NotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException)

Aggregations

UmaPendingRequest (org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)11 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 NotSupportedException (org.forgerock.json.resource.NotSupportedException)2 ResourceException (org.forgerock.json.resource.ResourceException)2 NotFoundException (org.forgerock.openam.sm.datalayer.store.NotFoundException)2 ServerException (org.forgerock.openam.sm.datalayer.store.ServerException)2 Test (org.testng.annotations.Test)2 AMIdentity (com.sun.identity.idm.AMIdentity)1 HashSet (java.util.HashSet)1 MessagingException (javax.mail.MessagingException)1 JsonValue (org.forgerock.json.JsonValue)1 ResourceResponse (org.forgerock.json.resource.ResourceResponse)1 RealmContext (org.forgerock.openam.rest.RealmContext)1 Context (org.forgerock.services.context.Context)1 Promise (org.forgerock.util.promise.Promise)1