Search in sources :

Example 16 with NotFoundException

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

the class IdentityResourceV2 method createInstance.

/**
     * Creates an a resource using a privileged token
     * @param admin Token that has administrative privileges
     * @param details resource details that needs to be created
     * @return A successful promise containing the identity details if the create was successful
     */
private Promise<ActionResponse, ResourceException> createInstance(SSOToken admin, JsonValue details, final String realm) {
    JsonValue jVal = details;
    IdentityDetails identity = jsonValueToIdentityDetails(objectType, jVal, realm);
    final String resourceId = identity.getName();
    return attemptResourceCreation(realm, admin, identity, resourceId).thenAsync(new AsyncFunction<IdentityDetails, ActionResponse, ResourceException>() {

        @Override
        public Promise<ActionResponse, ResourceException> apply(IdentityDetails dtls) {
            if (dtls != null) {
                debug.message("IdentityResource.createInstance :: Anonymous CREATE in realm={} " + "for resourceId={}", realm, resourceId);
                return newResultPromise(newActionResponse(identityDetailsToJsonValue(dtls)));
            } else {
                return new NotFoundException(resourceId + " not found").asPromise();
            }
        }
    });
}
Also used : Promises.newResultPromise(org.forgerock.util.promise.Promises.newResultPromise) Promise(org.forgerock.util.promise.Promise) JsonValue(org.forgerock.json.JsonValue) IdentityDetails(com.sun.identity.idsvcs.IdentityDetails) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Responses.newActionResponse(org.forgerock.json.resource.Responses.newActionResponse)

Example 17 with NotFoundException

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

the class ServerInfoResource method getAllServerInfo.

/**
     * Retrieves all server info set on the server.
     *
     * @param context
     *         Current Server Context.
     * @param realm
     *         realm in whose security context we use.
     */
private Promise<ResourceResponse, ResourceException> getAllServerInfo(Context context, String realm) {
    JsonValue result = new JsonValue(new LinkedHashMap<String, Object>(1));
    Set<String> cookieDomains;
    ResourceResponse resource;
    //added for the XUI to be able to understand its locale to request the appropriate translations to cache
    ISLocaleContext localeContext = new ISLocaleContext();
    HttpContext httpContext = context.asContext(HttpContext.class);
    //we have nothing else to go on at this point other than their request
    localeContext.setLocale(httpContext);
    SelfServiceInfo selfServiceInfo = configHandler.getConfig(realm, SelfServiceInfoBuilder.class);
    RestSecurity restSecurity = restSecurityProvider.get(realm);
    Set<String> protectedUserAttributes = new HashSet<>();
    protectedUserAttributes.addAll(selfServiceInfo.getProtectedUserAttributes());
    protectedUserAttributes.addAll(restSecurity.getProtectedUserAttributes());
    try {
        cookieDomains = AuthClientUtils.getCookieDomains();
        result.put("domains", cookieDomains);
        result.put("protectedUserAttributes", protectedUserAttributes);
        result.put("cookieName", SystemProperties.get(Constants.AM_COOKIE_NAME, "iPlanetDirectoryPro"));
        result.put("secureCookie", CookieUtils.isCookieSecure());
        result.put("forgotPassword", String.valueOf(selfServiceInfo.isForgottenPasswordEnabled()));
        result.put("forgotUsername", String.valueOf(selfServiceInfo.isForgottenUsernameEnabled()));
        result.put("kbaEnabled", String.valueOf(selfServiceInfo.isKbaEnabled()));
        result.put("selfRegistration", String.valueOf(selfServiceInfo.isUserRegistrationEnabled()));
        result.put("lang", getJsLocale(localeContext.getLocale()));
        result.put("successfulUserRegistrationDestination", "default");
        result.put("socialImplementations", getSocialAuthnImplementations(realm));
        result.put("referralsEnabled", Boolean.FALSE.toString());
        result.put("zeroPageLogin", AuthUtils.getZeroPageLoginConfig(realm));
        result.put("realm", realm);
        result.put("xuiUserSessionValidationEnabled", SystemProperties.getAsBoolean(Constants.XUI_USER_SESSION_VALIDATION_ENABLED, true));
        if (debug.messageEnabled()) {
            debug.message("ServerInfoResource.getAllServerInfo ::" + " Added resource to response: " + ALL_SERVER_INFO);
        }
        resource = newResourceResponse(ALL_SERVER_INFO, Integer.toString(result.asMap().hashCode()), result);
        return newResultPromise(resource);
    } catch (Exception e) {
        debug.error("ServerInfoResource.getAllServerInfo : Cannot retrieve all server info domains.", e);
        return new NotFoundException(e.getMessage()).asPromise();
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) HttpContext(org.forgerock.json.resource.http.HttpContext) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) NotFoundException(org.forgerock.json.resource.NotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) SMSException(com.sun.identity.sm.SMSException) ResourceException(org.forgerock.json.resource.ResourceException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) RestSecurity(org.forgerock.openam.services.RestSecurity) ISLocaleContext(com.sun.identity.common.ISLocaleContext) HashSet(java.util.HashSet)

Example 18 with NotFoundException

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

the class ServerInfoResource method getCookieDomains.

/**
     * Retrieves the cookie domains set on the server.
     */
private Promise<ResourceResponse, ResourceException> getCookieDomains() {
    JsonValue result = new JsonValue(new LinkedHashMap<String, Object>(1));
    Set<String> cookieDomains;
    ResourceResponse resource;
    int rev;
    try {
        cookieDomains = AuthClientUtils.getCookieDomains();
        rev = cookieDomains.hashCode();
        result.put("domains", cookieDomains);
        resource = newResourceResponse(COOKIE_DOMAINS, Integer.toString(rev), result);
        if (debug.messageEnabled()) {
            debug.message("ServerInfoResource.getCookieDomains ::" + " Added resource to response: " + COOKIE_DOMAINS);
        }
        return newResultPromise(resource);
    } catch (Exception e) {
        debug.error("ServerInfoResource.getCookieDomains : Cannot retrieve cookie domains.", e);
        return new NotFoundException(e.getMessage()).asPromise();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) NotFoundException(org.forgerock.json.resource.NotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) SMSException(com.sun.identity.sm.SMSException) ResourceException(org.forgerock.json.resource.ResourceException)

Example 19 with NotFoundException

use of org.forgerock.json.resource.NotFoundException 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 20 with NotFoundException

use of org.forgerock.json.resource.NotFoundException 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)

Aggregations

NotFoundException (org.forgerock.json.resource.NotFoundException)69 ResourceException (org.forgerock.json.resource.ResourceException)43 SSOException (com.iplanet.sso.SSOException)42 JsonValue (org.forgerock.json.JsonValue)39 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)39 BadRequestException (org.forgerock.json.resource.BadRequestException)38 SMSException (com.sun.identity.sm.SMSException)34 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 ForbiddenException (org.forgerock.json.resource.ForbiddenException)26 IdRepoException (com.sun.identity.idm.IdRepoException)24 PermanentException (org.forgerock.json.resource.PermanentException)24 ConflictException (org.forgerock.json.resource.ConflictException)22 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)21 NotSupportedException (org.forgerock.json.resource.NotSupportedException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)17 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)16 RealmContext (org.forgerock.openam.rest.RealmContext)16 SSOToken (com.iplanet.sso.SSOToken)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 MessagingException (javax.mail.MessagingException)14