Search in sources :

Example 11 with InternalServerErrorException

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

the class UserDevicesDao method getIdentity.

/**
     * Gets the {@code AMIdentity} for the authenticated user.
     *
     * @param userName The user's name.
     * @param realm The user's realm.
     * @return An {@code AMIdentity}.
     * @throws InternalServerErrorException If there is a problem getting the user's identity.
     */
private AMIdentity getIdentity(String userName, String realm) throws InternalServerErrorException {
    final AMIdentity amIdentity;
    final AMIdentityRepository amIdRepo = AuthD.getAuth().getAMIdentityRepository(realm);
    final IdSearchControl idsc = new IdSearchControl();
    idsc.setAllReturnAttributes(true);
    Set<AMIdentity> results = Collections.emptySet();
    try {
        idsc.setMaxResults(NO_LIMIT);
        IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
        if (searchResults != null) {
            results = searchResults.getSearchResults();
        }
        if (results.isEmpty()) {
            throw new IdRepoException("getIdentity : User " + userName + " is not found");
        } else if (results.size() > 1) {
            throw new IdRepoException("getIdentity : More than one user found for the userName " + userName);
        }
        amIdentity = results.iterator().next();
    } catch (IdRepoException | SSOException e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
    return amIdentity;
}
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)

Example 12 with InternalServerErrorException

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

the class UserDevicesResource method deleteInstance.

/**
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) {
    final String userName = contextHelper.getUserId(context);
    try {
        List<JsonValue> devices = userDevicesDao.getDeviceProfiles(userName, getRealm(context));
        JsonValue toDelete = null;
        for (JsonValue device : devices) {
            if (resourceId.equals(device.get(UUID_KEY).asString())) {
                toDelete = device;
                break;
            }
        }
        if (toDelete == null) {
            return new NotFoundException("User device, " + resourceId + ", not found.").asPromise();
        }
        devices.remove(toDelete);
        userDevicesDao.saveDeviceProfiles(userName, getRealm(context), devices);
        return newResultPromise(newResourceResponse(resourceId, toDelete.hashCode() + "", toDelete));
    } catch (InternalServerErrorException e) {
        return e.asPromise();
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) NotFoundException(org.forgerock.json.resource.NotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException)

Example 13 with InternalServerErrorException

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

the class SitesResourceProvider method createInstance.

@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
    JsonValue content = request.getContent();
    String id = request.getNewResourceId();
    try {
        id = validWriteOperation(content, id);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    String url = content.get(PRIMARY_URL).asString();
    try {
        SSOToken token = getSsoToken(context);
        if (SiteConfiguration.isSiteExist(token, id)) {
            return new ConflictException("Site with id already exists: " + id).asPromise();
        }
        SiteConfiguration.createSite(token, id, url, content.get(SECONDARY_URLS).asSet());
        debug.message("Site created: {}", id);
        return newResultPromise(getSite(token, id));
    } catch (SMSException | SSOException | ConfigurationException e) {
        debug.error("Could not create site", e);
        return new InternalServerErrorException("Could not create site").asPromise();
    } catch (NotFoundException e) {
        return new InternalServerErrorException("Could not read site just created").asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ConflictException(org.forgerock.json.resource.ConflictException) 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)

Example 14 with InternalServerErrorException

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

the class SitesResourceProvider method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (!"true".equals(request.getQueryFilter().toString())) {
        return new BadRequestException("Query only supports 'true' filter").asPromise();
    }
    try {
        SSOToken token = getSsoToken(context);
        Set<String> siteNames = SiteConfiguration.getSites(token);
        for (String siteName : siteNames) {
            handler.handleResource(getSite(token, siteName));
        }
        return newResultPromise(newQueryResponse());
    } catch (SSOException | SMSException | ConfigurationException e) {
        debug.error("Could not read sites", e);
        return new InternalServerErrorException("Could not read sites").asPromise();
    } catch (NotFoundException e) {
        debug.error("Could not read site", e);
        return new InternalServerErrorException("Could not read site we've just got name for").asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException)

Example 15 with InternalServerErrorException

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

the class SmsCollectionProvider method updateInstance.

/**
     * Updates a child instance of config. The parent config referenced by the request path is found, and
     * the config is updated using the resourceId.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, UpdateRequest request) {
    JsonValue content = request.getContent();
    String realm = realmFor(context);
    try {
        Map<String, Set<String>> attrs = converter.fromJson(realm, content);
        ServiceConfigManager scm = getServiceConfigManager(context);
        ServiceConfig config = parentSubConfigFor(context, scm);
        ServiceConfig node = checkedInstanceSubConfig(context, resourceId, config);
        node.setAttributes(attrs);
        JsonValue result = getJsonValue(realm, node);
        return newResultPromise(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
    } catch (ServiceNotFoundException e) {
        debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on update", e);
        return new NotFoundException("Unable to update SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on update", e);
        return new InternalServerErrorException("Unable to update SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on update", e);
        return new InternalServerErrorException("Unable to update SMS config: " + e.getMessage()).asPromise();
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) JsonValue(org.forgerock.json.JsonValue) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException) ResourceException(org.forgerock.json.resource.ResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

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