Search in sources :

Example 21 with ResourceException

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

the class IdentityResourceV1 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 if the create was successful
     */
private Promise<ActionResponse, ResourceException> createInstance(SSOToken admin, final 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) IdentityRestUtils.identityDetailsToJsonValue(org.forgerock.openam.core.rest.IdentityRestUtils.identityDetailsToJsonValue) JsonValue(org.forgerock.json.JsonValue) IdentityRestUtils.jsonValueToIdentityDetails(org.forgerock.openam.core.rest.IdentityRestUtils.jsonValueToIdentityDetails) 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)

Example 22 with ResourceException

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

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

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

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

ResourceException (org.forgerock.json.resource.ResourceException)323 Test (org.testng.annotations.Test)233 ResourceResponse (org.forgerock.json.resource.ResourceResponse)179 JsonValue (org.forgerock.json.JsonValue)145 Context (org.forgerock.services.context.Context)145 RealmContext (org.forgerock.openam.rest.RealmContext)110 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)71 Subject (javax.security.auth.Subject)58 ClientContext (org.forgerock.services.context.ClientContext)56 NotFoundException (org.forgerock.json.resource.NotFoundException)47 BadRequestException (org.forgerock.json.resource.BadRequestException)44 QueryResponse (org.forgerock.json.resource.QueryResponse)43 HashSet (java.util.HashSet)42 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)42 CreateRequest (org.forgerock.json.resource.CreateRequest)40 SSOException (com.iplanet.sso.SSOException)38 ActionResponse (org.forgerock.json.resource.ActionResponse)37 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)37 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)35