Search in sources :

Example 56 with InternalServerErrorException

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

the class SitesResourceProvider method updateInstance.

@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
    JsonValue content = request.getContent();
    try {
        validWriteOperation(content, id);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    ResourceResponse site;
    SSOToken token;
    try {
        token = getSsoToken(context);
        site = getSite(token, id);
    } catch (SMSException | SSOException | ConfigurationException e) {
        debug.error("Could not read site {}", id, e);
        return new InternalServerErrorException("Could not read site").asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
    try {
        if (!site.getRevision().equals(request.getRevision())) {
            return new PreconditionFailedException("Revision did not match").asPromise();
        }
        SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
        SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
        return newResultPromise(getSite(token, id));
    } catch (SSOException | SMSException | ConfigurationException e) {
        debug.error("Could not update site {}", id, e);
        return new InternalServerErrorException("Could not update site").asPromise();
    } catch (NotFoundException e) {
        return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) PreconditionFailedException(org.forgerock.json.resource.PreconditionFailedException)

Example 57 with InternalServerErrorException

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

the class SmsCollectionProvider method createInstance.

/**
     * Creates a new child instance of config. The parent config referenced by the request path is found, and
     * new config is created using the provided name property.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
    JsonValue content = request.getContent();
    final String realm = realmFor(context);
    try {
        Map<String, Set<String>> attrs = converter.fromJson(realm, content);
        ServiceConfigManager scm = getServiceConfigManager(context);
        ServiceConfig config = parentSubConfigFor(context, scm);
        String name = content.get("_id").asString();
        if (name == null) {
            name = request.getNewResourceId();
        } else if (request.getNewResourceId() != null && !name.equals(request.getNewResourceId())) {
            return new BadRequestException("name and URI's resource ID do not match").asPromise();
        }
        if (name == null) {
            return new BadRequestException("Invalid name").asPromise();
        }
        config.addSubConfig(name, lastSchemaNodeName(), 0, attrs);
        final ServiceConfig created = checkedInstanceSubConfig(context, name, config);
        return awaitCreation(context, name).then(new Function<Void, ResourceResponse, ResourceException>() {

            @Override
            public ResourceResponse apply(Void aVoid) {
                JsonValue result = getJsonValue(realm, created);
                return newResourceResponse(created.getName(), String.valueOf(result.hashCode()), result);
            }
        });
    } catch (ServiceAlreadyExistsException e) {
        debug.warning("::SmsCollectionProvider:: ServiceAlreadyExistsException on create", e);
        return new ConflictException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) ConflictException(org.forgerock.json.resource.ConflictException) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 58 with InternalServerErrorException

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

the class AuthenticationChainsFilter method transformRequestBody.

private JsonValue transformRequestBody(JsonValue body) throws InternalServerErrorException {
    if (body.isDefined("authChainConfiguration")) {
        try {
            List<AuthConfigurationEntry> entries = new ArrayList<>();
            for (JsonValue entry : body.get("authChainConfiguration")) {
                String module = entry.get("module").asString();
                String criteria = entry.get("criteria").asString();
                String options = getOptions(entry);
                entries.add(new AuthConfigurationEntry(module, criteria, options));
            }
            body.put("authChainConfiguration", AMAuthConfigUtils.authConfigurationEntryToXMLString(entries));
        } catch (AMConfigurationException e) {
            throw new InternalServerErrorException("Failed to parse authChainConfiguration", e);
        }
    }
    return body;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) AuthConfigurationEntry(com.sun.identity.authentication.config.AuthConfigurationEntry)

Example 59 with InternalServerErrorException

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

the class AuthenticationModuleCollectionHandler method handleQuery.

/**
     * Returns the list of configured authentication module instances for the current realm.
     *
     * {@inheritDoc}
     */
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    String searchForId;
    try {
        searchForId = request.getQueryFilter().accept(new AuthenticationModuleQueryFilterVisitor(), null);
    } catch (UnsupportedOperationException e) {
        return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
    }
    if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
        return new NotSupportedException("Query paging not currently supported").asPromise();
    }
    try {
        SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
        String realm = context.asContext(RealmContext.class).getResolvedRealm();
        AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
        Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
        List<ResourceResponse> resourceResponses = new ArrayList<>();
        for (AMAuthenticationInstance instance : moduleInstances) {
            String name = instance.getName();
            if (searchForId == null || searchForId.equalsIgnoreCase(name)) {
                try {
                    ServiceSchemaManager schemaManager = getSchemaManager(instance.getType());
                    String type = schemaManager.getResourceName();
                    String typeDescription = getI18NValue(schemaManager, instance.getType(), debug);
                    JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, name), field("typeDescription", typeDescription), field("type", type)));
                    resourceResponses.add(newResourceResponse(name, String.valueOf(result.hashCode()), result));
                } catch (AMConfigurationException ex) {
                    debug.error("AuthenticationModuleCollectionHandler.handleQuery(): Invalid auth module " + "instance configuration: {}", name);
                    if (debug.messageEnabled()) {
                        debug.message("AuthenticationModuleCollectionHandler.handleQuery(): Configuration exception: {}", name, ex);
                    }
                }
            }
        }
        return QueryResponsePresentation.perform(handler, request, resourceResponses);
    } catch (AMConfigurationException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) RealmContext(org.forgerock.openam.rest.RealmContext) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) NotSupportedException(org.forgerock.json.resource.NotSupportedException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 60 with InternalServerErrorException

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

the class ClientResourceManager method getIdentity.

private AMIdentity getIdentity(String uName, String realm) throws InternalServerErrorException {
    AMIdentity theID = null;
    AMIdentityRepository amIdRepo = null;
    amIdRepo = new AMIdentityRepository(realm, getAdminToken());
    IdSearchControl idsc = new IdSearchControl();
    idsc.setRecursive(true);
    idsc.setAllReturnAttributes(true);
    // search for the identity
    Set<AMIdentity> results = Collections.EMPTY_SET;
    try {
        idsc.setMaxResults(0);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.AGENTONLY, uName, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results == null || results.size() != 1) {
            throw new InternalServerErrorException("Too many results or not enough");
        }
        theID = results.iterator().next();
    } catch (IdRepoException e) {
        throw new InternalServerErrorException("Unable to get search results", e);
    } catch (SSOException e) {
        throw new InternalServerErrorException("Unable to get search results", e);
    }
    return theID;
}
Also used : IdSearchResults(com.sun.identity.idm.IdSearchResults) AMIdentity(com.sun.identity.idm.AMIdentity) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdSearchControl(com.sun.identity.idm.IdSearchControl) IdRepoException(com.sun.identity.idm.IdRepoException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException)

Aggregations

InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)70 SSOException (com.iplanet.sso.SSOException)39 JsonValue (org.forgerock.json.JsonValue)33 SMSException (com.sun.identity.sm.SMSException)29 BadRequestException (org.forgerock.json.resource.BadRequestException)27 NotFoundException (org.forgerock.json.resource.NotFoundException)25 ResourceException (org.forgerock.json.resource.ResourceException)24 SSOToken (com.iplanet.sso.SSOToken)19 IdRepoException (com.sun.identity.idm.IdRepoException)18 Set (java.util.Set)15 ResourceResponse (org.forgerock.json.resource.ResourceResponse)15 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)14 AMIdentity (com.sun.identity.idm.AMIdentity)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 ForbiddenException (org.forgerock.json.resource.ForbiddenException)11 ServiceConfig (com.sun.identity.sm.ServiceConfig)10 NotSupportedException (org.forgerock.json.resource.NotSupportedException)10 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)10 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)9