Search in sources :

Example 6 with ServiceNotFoundException

use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.

the class AMOrgTemplateImpl method store.

/**
     * Stores the change to directory server.
     * 
     * @throws AMException
     *             if there is an internal problem with AM Store.
     * @throws SSOException
     *             if the sign-on is no longer valid.
     */
public void store() throws AMException, SSOException {
    Map attributes = modAttributes;
    modAttributes = new HashMap();
    try {
        serviceConfig.setAttributes(attributes);
    } catch (ServiceNotFoundException ex) {
        Object[] args = { serviceName };
        throw new AMException(AMSDKBundle.getString("481", args), "481", args);
    } catch (InvalidAttributeValueException ex) {
        Object[] args = ex.getMessageArgs();
        debug.error("Store exception from SMS: " + ex, ex);
        throw new AMException(AMSDKBundle.getString("975", args), "975", args);
    } catch (SMSException ex) {
        Object[] args = { serviceName };
        debug.error("Store exception from SMS: " + ex, ex);
        throw new AMException(AMSDKBundle.getString("486", args), "486", args);
    }
}
Also used : HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) InvalidAttributeValueException(com.sun.identity.sm.InvalidAttributeValueException)

Example 7 with ServiceNotFoundException

use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.

the class AMServiceUtils method getOrgConfig.

/**
     * Get organization config for the service
     * 
     * @param token
     *            SSOToken
     * @param orgDN
     *            DN of the org or org unit
     * @param serviceName
     *            Service Name
     * @return ServiceConfig of the organization for the service
     */
public static ServiceConfig getOrgConfig(SSOToken token, String orgDN, String serviceName) throws SSOException, AMException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, token);
        ServiceConfig sc = scm.getOrganizationConfig(orgDN, null);
        DN theOrgDN = DN.valueOf(orgDN);
        if (theOrgDN.equals(DN.valueOf(SMSEntry.getAMSdkBaseDN())) && sc != null) {
            Map avPair = sc.getAttributes();
            Set subConfigs = sc.getSubConfigNames();
            if (avPair.isEmpty() && (subConfigs == null || subConfigs.isEmpty())) {
                return null;
            }
        }
        return sc;
    } catch (ServiceNotFoundException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("481", args, locale), "481", args);
    } catch (ServiceAlreadyExistsException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("479", args, locale), "479", args);
    } catch (SMSException ex) {
        Object[] args = { serviceName };
        String locale = AMCommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("482", args, locale), "482", args);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) DN(org.forgerock.opendj.ldap.DN) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

Example 8 with ServiceNotFoundException

use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.

the class SmsCollectionProvider method deleteInstance.

/**
     * Deletes a child instance of config. The parent config referenced by the request path is found, and
     * the config is deleted using the resourceId.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, final String resourceId, DeleteRequest request) {
    try {
        ServiceConfigManager scm = getServiceConfigManager(context);
        ServiceConfig config = parentSubConfigFor(context, scm);
        checkedInstanceSubConfig(context, resourceId, config);
        if (isDefaultCreatedAuthModule(context, resourceId)) {
            scm.removeOrganizationConfiguration(realmFor(context), null);
        } else {
            config.removeSubConfig(resourceId);
        }
        return awaitDeletion(context, resourceId).then(new Function<Void, ResourceResponse, ResourceException>() {

            @Override
            public ResourceResponse apply(Void aVoid) {
                return newResourceResponse(resourceId, "0", json(object(field("success", true))));
            }
        });
    } catch (ServiceNotFoundException e) {
        debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on delete", e);
        return new NotFoundException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on delete", e);
        return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on delete", e);
        return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 9 with ServiceNotFoundException

use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.

the class IdentityResourceV2 method anonymousCreate.

private Promise<ActionResponse, ResourceException> anonymousCreate(final Context context, final ActionRequest request, final String realm, RestSecurity restSecurity) {
    final JsonValue jVal = request.getContent();
    String tokenID = null;
    String confirmationId;
    String email;
    try {
        if (!restSecurity.isSelfRegistration()) {
            throw new BadRequestException("Self-registration disabled");
        }
        tokenID = jVal.get(TOKEN_ID).asString();
        jVal.remove(TOKEN_ID);
        confirmationId = jVal.get(CONFIRMATION_ID).asString();
        jVal.remove(CONFIRMATION_ID);
        email = jVal.get(EMAIL).asString();
        if (email == null || email.isEmpty()) {
            throw new BadRequestException("Email not provided");
        }
        // Convert to IDRepo Attribute schema
        jVal.put("mail", email);
        if (confirmationId == null || confirmationId.isEmpty()) {
            throw new BadRequestException("confirmationId not provided");
        }
        if (tokenID == null || tokenID.isEmpty()) {
            throw new BadRequestException("tokenId not provided");
        }
        validateToken(tokenID, realm, email, confirmationId);
        // create an Identity
        SSOToken admin = RestUtils.getToken();
        final String finalTokenID = tokenID;
        return createInstance(admin, jVal, realm).thenAsync(new AsyncFunction<ActionResponse, ActionResponse, ResourceException>() {

            @Override
            public Promise<ActionResponse, ResourceException> apply(ActionResponse response) {
                // Only remove the token if the create was successful, errors will be set in the handler.
                try {
                    // Even though the generated token will eventually timeout, delete it after a successful read
                    // so that the completed registration request cannot be made again using the same token.
                    CTSHolder.getCTS().deleteAsync(finalTokenID);
                } catch (DeleteFailedException e) {
                    // reading and deleting, the token has expired.
                    if (debug.messageEnabled()) {
                        debug.message("IdentityResource.anonymousCreate: Deleting token " + finalTokenID + " after a successful read failed due to " + e.getMessage(), e);
                    }
                } catch (CoreTokenException cte) {
                    // For any unexpected CTS error
                    debug.error("IdentityResource.anonymousCreate(): CTS Error : " + cte.getMessage());
                    return new InternalServerErrorException(cte.getMessage(), cte).asPromise();
                }
                return newResultPromise(response);
            }
        });
    } catch (BadRequestException bre) {
        debug.warning("IdentityResource.anonymousCreate() :: Invalid Parameter", bre);
        return bre.asPromise();
    } catch (ResourceException re) {
        debug.warning("IdentityResource.anonymousCreate() :: Resource error", re);
        return re.asPromise();
    } catch (CoreTokenException cte) {
        // For any unexpected CTS error
        debug.error("IdentityResource.anonymousCreate() :: CTS error", cte);
        return new InternalServerErrorException(cte).asPromise();
    } catch (ServiceNotFoundException snfe) {
        // Failure from RestSecurity
        debug.error("IdentityResource.anonymousCreate() :: Internal error", snfe);
        return new InternalServerErrorException(snfe).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) ActionResponse(org.forgerock.json.resource.ActionResponse) Responses.newActionResponse(org.forgerock.json.resource.Responses.newActionResponse) Promises.newResultPromise(org.forgerock.util.promise.Promises.newResultPromise) Promise(org.forgerock.util.promise.Promise) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException)

Example 10 with ServiceNotFoundException

use of com.sun.identity.sm.ServiceNotFoundException in project OpenAM by OpenRock.

the class IdentityResourceV1 method anonymousCreate.

private Promise<ActionResponse, ResourceException> anonymousCreate(final Context context, final ActionRequest request, final String realm, RestSecurity restSecurity) {
    final JsonValue jVal = request.getContent();
    String confirmationId;
    String email;
    try {
        if (!restSecurity.isSelfRegistration()) {
            throw new BadRequestException("Self-registration disabled");
        }
        final String tokenID = jVal.get(TOKEN_ID).asString();
        jVal.remove(TOKEN_ID);
        confirmationId = jVal.get(CONFIRMATION_ID).asString();
        jVal.remove(CONFIRMATION_ID);
        email = jVal.get(EMAIL).asString();
        if (email == null || email.isEmpty()) {
            throw new BadRequestException("Email not provided");
        }
        // Convert to IDRepo Attribute schema
        jVal.put("mail", email);
        if (confirmationId == null || confirmationId.isEmpty()) {
            throw new BadRequestException("confirmationId not provided");
        }
        if (tokenID == null || tokenID.isEmpty()) {
            throw new BadRequestException("tokenId not provided");
        }
        validateToken(tokenID, realm, email, confirmationId);
        // create an Identity
        SSOToken admin = RestUtils.getToken();
        return createInstance(admin, jVal, realm).thenAsync(new AsyncFunction<ActionResponse, ActionResponse, ResourceException>() {

            @Override
            public Promise<ActionResponse, ResourceException> apply(ActionResponse response) {
                // Only remove the token if the create was successful, errors will be set in the handler.
                try {
                    // Even though the generated token will eventually timeout, delete it after a successful read
                    // so that the completed registration request cannot be made again using the same token.
                    CTSHolder.getCTS().deleteAsync(tokenID);
                } catch (DeleteFailedException e) {
                    // reading and deleting, the token has expired.
                    if (debug.messageEnabled()) {
                        debug.message("IdentityResource.anonymousCreate: Deleting token {} after a" + " successful read failed.", tokenID, e);
                    }
                } catch (CoreTokenException cte) {
                    // For any unexpected CTS error
                    debug.error("IdentityResource.anonymousCreate(): CTS Error", cte);
                    return new InternalServerErrorException(cte.getMessage(), cte).asPromise();
                }
                return newResultPromise(response);
            }
        });
    } catch (BadRequestException bre) {
        debug.warning("IdentityResource.anonymousCreate() :: Invalid Parameter", bre);
        return bre.asPromise();
    } catch (ResourceException re) {
        debug.warning("IdentityResource.anonymousCreate() :: Resource error", re);
        return re.asPromise();
    } catch (CoreTokenException cte) {
        // For any unexpected CTS error
        debug.error("IdentityResource.anonymousCreate() :: CTS error", cte);
        return new InternalServerErrorException(cte).asPromise();
    } catch (ServiceNotFoundException snfe) {
        // Failure from RestSecurity
        debug.error("IdentityResource.anonymousCreate() :: Internal error", snfe);
        return new InternalServerErrorException(snfe).asPromise();
    }
}
Also used : IdentityRestUtils.getSSOToken(org.forgerock.openam.core.rest.IdentityRestUtils.getSSOToken) SSOToken(com.iplanet.sso.SSOToken) IdentityRestUtils.identityDetailsToJsonValue(org.forgerock.openam.core.rest.IdentityRestUtils.identityDetailsToJsonValue) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) ActionResponse(org.forgerock.json.resource.ActionResponse) Promises.newResultPromise(org.forgerock.util.promise.Promises.newResultPromise) Promise(org.forgerock.util.promise.Promise) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException)

Aggregations

ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)24 Set (java.util.Set)10 SMSException (com.sun.identity.sm.SMSException)8 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)8 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)6 ServiceConfig (com.sun.identity.sm.ServiceConfig)6 HashSet (java.util.HashSet)6 CaseInsensitiveTreeSet (com.sun.identity.common.CaseInsensitiveTreeSet)5 File (java.io.File)5 Properties (java.util.Properties)5 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)4 ResourceException (org.forgerock.json.resource.ResourceException)4 SSOException (com.iplanet.sso.SSOException)3 SSOToken (com.iplanet.sso.SSOToken)3 CaseInsensitiveProperties (com.sun.identity.common.CaseInsensitiveProperties)3 JsonValue (org.forgerock.json.JsonValue)3 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)3