Search in sources :

Example 1 with ServerException

use of org.forgerock.openam.sm.datalayer.store.ServerException in project OpenAM by OpenRock.

the class AuditHistory method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    AMIdentity identity = getIdentity(context);
    Set<UmaAuditEntry> history;
    try {
        if (request.getQueryFilter().toString().equals("true")) {
            history = auditLogger.getEntireHistory(identity);
        } else {
            history = auditLogger.getHistory(identity, request);
        }
    } catch (ServerException e) {
        return new InternalServerErrorException(e).asPromise();
    }
    List<ResourceResponse> results = new ArrayList<>();
    for (UmaAuditEntry entry : history) {
        JsonValue result = entry.asJson();
        results.add(newResourceResponse(entry.getId(), String.valueOf(result.hashCode()), result));
    }
    QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
    return QueryResponsePresentation.perform(handler, request, results);
}
Also used : ServerException(org.forgerock.openam.sm.datalayer.store.ServerException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) AMIdentity(com.sun.identity.idm.AMIdentity) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) UmaAuditEntry(org.forgerock.openam.sm.datalayer.impl.uma.UmaAuditEntry)

Example 2 with ServerException

use of org.forgerock.openam.sm.datalayer.store.ServerException 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 3 with ServerException

use of org.forgerock.openam.sm.datalayer.store.ServerException in project OpenAM by OpenRock.

the class UmaAuditLogger method log.

public void log(String resourceSetId, String resourceSetName, AMIdentity resourceOwner, UmaAuditType message, String requestingPartyId) {
    final UmaAuditEntry umaAuditEntry;
    try {
        umaAuditEntry = new UmaAuditEntry(resourceSetId, resourceSetName, resourceOwner.getUniversalId(), message.toString(), requestingPartyId);
        delegate.create(umaAuditEntry);
    } catch (ServerException e) {
        logger.warning("Error writing to UMA audit log", e);
    }
}
Also used : ServerException(org.forgerock.openam.sm.datalayer.store.ServerException) UmaAuditEntry(org.forgerock.openam.sm.datalayer.impl.uma.UmaAuditEntry)

Example 4 with ServerException

use of org.forgerock.openam.sm.datalayer.store.ServerException 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)

Example 5 with ServerException

use of org.forgerock.openam.sm.datalayer.store.ServerException in project OpenAM by OpenRock.

the class PendingRequestsService method approvePendingRequest.

private AsyncFunction<UmaPolicy, Void, ResourceException> approvePendingRequest(final UmaPendingRequest request, final Collection<String> scopes, final String id, final String realm) {
    return new AsyncFunction<UmaPolicy, Void, ResourceException>() {

        @Override
        public Promise<Void, ResourceException> apply(UmaPolicy value) {
            try {
                if (isEmailRequestingPartyOnPendingRequestApprovalEnabled(realm)) {
                    Pair<String, String> template = pendingRequestEmailTemplate.getApprovalTemplate(request.getRequestingPartyId(), realm);
                    try {
                        emailService.email(realm, request.getRequestingPartyId(), template.getFirst(), MessageFormat.format(template.getSecond(), request.getResourceOwnerId(), request.getResourceSetName(), pendingRequestEmailTemplate.buildScopeString(scopes, request.getRequestingPartyId(), realm)));
                    } catch (MessagingException e) {
                        debug.warning("Pending Request Approval email could not be sent", e);
                    }
                }
                store.delete(id);
                AMIdentity resourceOwner = coreWrapper.getIdentity(request.getResourceOwnerId(), realm);
                auditLogger.log(request.getResourceSetId(), request.getResourceSetName(), resourceOwner, UmaAuditType.REQUEST_APPROVED, request.getRequestingPartyId());
                return newResultPromise(null);
            } 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) MessagingException(javax.mail.MessagingException) NotFoundException(org.forgerock.openam.sm.datalayer.store.NotFoundException) AsyncFunction(org.forgerock.util.AsyncFunction) AMIdentity(com.sun.identity.idm.AMIdentity) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) UmaPolicy(org.forgerock.openam.uma.UmaConstants.UmaPolicy)

Aggregations

ServerException (org.forgerock.openam.sm.datalayer.store.ServerException)5 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)4 AMIdentity (com.sun.identity.idm.AMIdentity)3 NotFoundException (org.forgerock.openam.sm.datalayer.store.NotFoundException)3 UmaAuditEntry (org.forgerock.openam.sm.datalayer.impl.uma.UmaAuditEntry)2 UmaPendingRequest (org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest)2 ArrayList (java.util.ArrayList)1 MessagingException (javax.mail.MessagingException)1 JsonValue (org.forgerock.json.JsonValue)1 ResourceException (org.forgerock.json.resource.ResourceException)1 ResourceResponse (org.forgerock.json.resource.ResourceResponse)1 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)1 UmaPolicy (org.forgerock.openam.uma.UmaConstants.UmaPolicy)1 AsyncFunction (org.forgerock.util.AsyncFunction)1