Search in sources :

Example 21 with ServiceNotFoundException

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

the class PolicyManager method removePolicy.

/**
     * Deletes a policy in the organization with the given name.
     *
     * @param policyName name of the policy to be deleted
     *
     * @throws SSOException invalid or expired single-sign-on token
     * @throws NoPermissionException user does not have sufficient
     * privileges to remove policies
     * @throws PolicyException for any other abnormal condition
     *
     * @supported.api
     */
public void removePolicy(String policyName) throws SSOException, NoPermissionException, PolicyException {
    // Check if name is valid
    if (policyName == null) {
        if (debug.warningEnabled()) {
            debug.warning("In PolicyManager::removePolicy(), name is null");
        }
        throw (new InvalidNameException(ResBundleUtils.rbName, "null_name", null, "null", PolicyException.POLICY));
    }
    try {
        // Get service config for named policy node
        ServiceConfig oConfig = scm.getOrganizationConfig(org, null);
        ServiceConfig namedPolicy = (oConfig == null) ? null : oConfig.getSubConfig(NAMED_POLICY);
        if (namedPolicy != null) {
            /* Remove the named policy
                 * before removing the named policy
                 * prepare for changes in resources tree
                 */
            Policy policy = getPolicy(policyName);
            // do the removal of policy 
            namedPolicy.removeSubConfig(policyName);
            if (policy != null) {
                if (isMigratedToEntitlementService()) {
                    // should use super admin token to remove the index store
                    // entry
                    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSuperAdminSubject(), getOrganizationDN());
                    if (policy.isReferralPolicy()) {
                        pis.deleteReferral((policyName));
                    } else {
                        pis.delete(PrivilegeUtils.policyToPrivileges(policy));
                    }
                    policyCache.sendPolicyChangeNotification(null, policy, ServiceListener.REMOVED);
                } else {
                    // do the removal in resources tree
                    rim.removePolicyFromResourceTree(svtm, token, policy);
                }
            }
        }
    } catch (EntitlementException e) {
        debug.error("Error while removing policy : " + e.getMessage());
    } catch (ServiceNotFoundException snfe) {
        debug.error("Error while removing policy : " + snfe.getMessage());
    } catch (SMSException smse) {
        String[] objs = { policyName, org };
        if (PolicyUtils.logStatus) {
            PolicyUtils.logErrorMessage("UNABLE_TO_REMOVE_POLICY", objs, token);
        }
        debug.error("SMS error in deleting policy: " + policyName + " for org: " + org, smse);
        // Check for permission exception
        if (smse.getExceptionCode() == SMSException.STATUS_NO_PERMISSION) {
            throw (new NoPermissionException(ResBundleUtils.rbName, "insufficient_access_rights", null));
        } else {
            // Throw generic policy exception
            throw (new PolicyException(ResBundleUtils.rbName, "unable_to_remove_policy", objs, smse));
        }
    }
    String[] objs = { policyName, org };
    if (PolicyUtils.logStatus) {
        PolicyUtils.logAccessMessage("POLICY_REMOVE_SUCCESS", objs, token);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

Example 22 with ServiceNotFoundException

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

the class AMServiceUtils method createOrgConfig.

/**
     * Create Service Template for a AMro profile, could be used to set policy
     * to a profile
     * 
     * @param token
     *            SSOToken
     * @param orgDN
     *            DN of the org or org unit
     * @param serviceName
     *            Service Name
     * @param avPair
     *            attributes to be set
     * @return String DN of the newly created template
     */
protected static ServiceConfig createOrgConfig(SSOToken token, String orgDN, String serviceName, Map avPair) throws SSOException, AMException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, token);
        ServiceConfig sc = scm.createOrganizationConfig(orgDN, avPair);
        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 : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

Example 23 with ServiceNotFoundException

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

the class AMServiceUtils method serviceHasSubSchema.

/**
     * Returns true if the service has the subSchema. False otherwise.
     * 
     * @param token
     *            SSOToken a valid SSOToken
     * @param serviceName
     *            the service name
     * @param schemaType
     *            service schema type (Dynamic, Policy etc)
     * @return true if the service has the subSchema.
     */
public static boolean serviceHasSubSchema(SSOToken token, String serviceName, SchemaType schemaType) throws SMSException, SSOException {
    boolean schemaTypeFlg = false;
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, token);
        Set types = ssm.getSchemaTypes();
        if (debug.messageEnabled()) {
            debug.message("AMServiceUtils.serviceHasSubSchema() " + "SchemaTypes types for " + serviceName + " are: " + types);
        }
        schemaTypeFlg = types.contains(schemaType);
    } catch (ServiceNotFoundException ex) {
        if (debug.warningEnabled()) {
            debug.warning("AMServiceUtils.serviceHasSubSchema() " + "Service does not exist : " + serviceName);
        }
    }
    return (schemaTypeFlg);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 24 with ServiceNotFoundException

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

the class AMAuthLevelManager method addServiceListener.

private ListenerMapEntry addServiceListener(String service) throws SMSException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("addServiceListener for " + service);
    }
    // add Service Schema Listener 
    ServiceSchemaManager ssm = null;
    try {
        ssm = new ServiceSchemaManager(service, AuthD.getAuth().getSSOAuthSession());
    } catch (ServiceNotFoundException e) {
        // module does not define any xml file
        return null;
    }
    String schemaListenerId = ssm.addListener(this);
    // add Service Config Manager
    ServiceConfigManager scm = null;
    try {
        scm = new ServiceConfigManager(service, AuthD.getAuth().getSSOAuthSession());
    } catch (ServiceNotFoundException e) {
        // module does not define any xml file
        return null;
    }
    String configListenerId = scm.addListener(this);
    return new ListenerMapEntry(ssm, schemaListenerId, scm, configListenerId);
}
Also used : ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

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