Search in sources :

Example 46 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class SoapSTSPublishServiceRequestHandler method handleUpdate.

/*
     * A PUT to the url composed of the publish endpont + the sts instance id with a payload corresponding to a
     * SoapSTSInstanceId (wrapped in invocation context information) will result in republishing the existing instance
     * (which is a delete followed by a create).
     */
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest request) {
    String stsId = request.getResourcePath();
    String realm = getRealmFromResourceName(request.getResourcePath());
    if (!realmValidator.isRealm(realm)) {
        logger.warn("Update of soap STS instance state for instance " + stsId + " in realm " + realm + " rejected because realm does not exist");
        return new NotFoundException("The specified realm does not exist.").asPromise();
    }
    /*
        Insure that the instance is published before performing an update.
         */
    final boolean publishedToSMS;
    try {
        publishedToSMS = (publisher.getPublishedInstance(stsId, realm) != null);
    } catch (STSPublishException e) {
        logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught determining whether " + "instance persisted in SMS. Instance not updated. Exception: " + e, e);
        return e.asPromise();
    }
    if (publishedToSMS) {
        SoapSTSInstanceConfig instanceConfig;
        try {
            instanceConfig = marshalInstanceConfigFromInvocation(request.getContent());
        } catch (BadRequestException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught marshalling " + "invocation state to SoapSTSInstanceConfig. Instance not updated. The state: " + request.getContent() + "Exception: " + e, e);
            return e.asPromise();
        }
        try {
            publisher.removeInstance(stsId, realm);
        } catch (STSPublishException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught removing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, and has not been updated. The instance config: " + instanceConfig + "; Exception: " + e, e);
            return e.asPromise();
        }
        try {
            ResourceResponse response = publishInstance(instanceConfig);
            logger.info("Soap STS instance " + instanceConfig.getDeploymentSubPath() + " updated to state " + instanceConfig.toJson());
            return newResultPromise(response);
        } catch (ResourceException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught publishing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, having been removed, but not successfully published with updated " + "state. The instance config: " + instanceConfig + "; Exception: " + e, e);
            return e.asPromise();
        }
    } else {
        //404 - realm and id not found in SMS
        return new NotFoundException("No soap sts instance with id " + stsId + " in realm " + realm).asPromise();
    }
}
Also used : SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) STSPublishException(org.forgerock.openam.sts.STSPublishException) NotFoundException(org.forgerock.json.resource.NotFoundException) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException)

Example 47 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class TokenGenerationService method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(final Context serverContext, final QueryRequest queryRequest, final QueryResourceHandler queryResultHandler) {
    QueryFilter<JsonPointer> queryFilter = queryRequest.getQueryFilter();
    if (queryFilter == null) {
        return new BadRequestException(getUsageString()).asPromise();
    }
    try {
        final QueryFilter<CoreTokenField> coreTokenFieldQueryFilter = convertToCoreTokenFieldQueryFilter(queryFilter);
        final List<STSIssuedTokenState> issuedTokens = ctsTokenPersistence.listTokens(coreTokenFieldQueryFilter);
        for (STSIssuedTokenState tokenState : issuedTokens) {
            queryResultHandler.handleResource(newResourceResponse(tokenState.getTokenId(), EMPTY_STRING, tokenState.toJson()));
        }
        return newResultPromise(newQueryResponse());
    } catch (CTSTokenPersistenceException e) {
        logger.error("Exception caught obtaining list of sts-issued tokens: " + e, e);
        return e.asPromise();
    }
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException) STSIssuedTokenState(org.forgerock.openam.sts.user.invocation.STSIssuedTokenState) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) JsonPointer(org.forgerock.json.JsonPointer) CTSTokenPersistenceException(org.forgerock.openam.sts.CTSTokenPersistenceException)

Example 48 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class UmaLabelResource method createInstance.

@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context serverContext, CreateRequest createRequest) {
    final JsonValue umaLabel = createRequest.getContent();
    try {
        validate(umaLabel);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    final String realm = getRealm(serverContext);
    final String userName = getUserName(serverContext);
    final String labelName = umaLabel.get(NAME_LABEL).asString();
    final String labelType = umaLabel.get(TYPE_LABEL).asString();
    final ResourceSetLabel label;
    try {
        label = labelStore.create(realm, userName, new ResourceSetLabel(null, labelName, LabelType.valueOf(labelType), Collections.EMPTY_SET));
        return newResultPromise(newResourceResponse(label.getId(), String.valueOf(label.hashCode()), label.asJson()));
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Example 49 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class UmaLabelResource method deleteInstance.

@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String labelId, DeleteRequest deleteRequest) {
    try {
        ResourceSetLabel resourceSetLabel = labelStore.read(getRealm(serverContext), getUserName(serverContext), labelId);
        if (!isSameRevision(deleteRequest, resourceSetLabel)) {
            throw new BadRequestException("Revision number doesn't match latest revision.");
        }
        labelStore.delete(getRealm(serverContext), getUserName(serverContext), labelId);
        return newResultPromise(newResourceResponse(labelId, null, resourceSetLabel.asJson()));
    } catch (ResourceException e) {
        return new BadRequestException("Error deleting label.").asPromise();
    }
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Example 50 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class PolicyV1Filter method retrieveResourceType.

/**
     * Retrieves the resource type Id from the containing application
     * and sets it within the policies' JSON representation.
     *
     * @param jsonValue
     *         the policies' JSON representation
     * @param callingSubject
     *         the calling subject
     * @param realm
     *         the realm
     *
     * @throws EntitlementException
     *         should some policy error occur
     * @throws ResourceException
     *         should some violation occur that doesn't satisfy policy v1.0
     */
private void retrieveResourceType(JsonValue jsonValue, Subject callingSubject, String realm) throws EntitlementException, ResourceException {
    final String applicationName = jsonValue.get("applicationName").asString();
    if (applicationName == null) {
        throw new BadRequestException("Invalid application name defined in request");
    }
    final ApplicationService applicationService = applicationServiceFactory.create(callingSubject, realm);
    final Application application = applicationService.getApplication(applicationName);
    if (application == null) {
        throw new NotFoundException("Unable to find application " + applicationName);
    }
    if (application.getResourceTypeUuids().size() != 1) {
        throw new BadRequestException("Cannot create policy under an application with more than " + "one resource type using version 1.0 of this endpoint");
    }
    // Retrieve the resource type from the applications single resource type.
    final String resourceTypeUuid = application.getResourceTypeUuids().iterator().next();
    jsonValue.put(RESOURCE_TYPE_UUID, resourceTypeUuid);
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException) NotFoundException(org.forgerock.json.resource.NotFoundException) Application(com.sun.identity.entitlement.Application) ApplicationService(org.forgerock.openam.entitlement.service.ApplicationService)

Aggregations

BadRequestException (org.forgerock.json.resource.BadRequestException)82 JsonValue (org.forgerock.json.JsonValue)44 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)40 ResourceException (org.forgerock.json.resource.ResourceException)39 SSOException (com.iplanet.sso.SSOException)37 NotFoundException (org.forgerock.json.resource.NotFoundException)37 SMSException (com.sun.identity.sm.SMSException)31 ForbiddenException (org.forgerock.json.resource.ForbiddenException)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)25 IdRepoException (com.sun.identity.idm.IdRepoException)23 PermanentException (org.forgerock.json.resource.PermanentException)22 ConflictException (org.forgerock.json.resource.ConflictException)21 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)20 SSOToken (com.iplanet.sso.SSOToken)19 NotSupportedException (org.forgerock.json.resource.NotSupportedException)17 RealmContext (org.forgerock.openam.rest.RealmContext)17 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)16 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)16 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)14 MessagingException (javax.mail.MessagingException)13