Search in sources :

Example 46 with EntitlementException

use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.

the class PolicyV1Filter method filterCreate.

/**
     * The policy json will not have any resource type defined. Create retrieves the policy's associated application
     * and uses the applications associated resource type for the policy.
     *
     * @param context
     *         the filter chain context
     * @param request
     *         the create request
     * @param next
     *         a request handler representing the remainder of the filter chain
     */
@Override
public Promise<ResourceResponse, ResourceException> filterCreate(Context context, CreateRequest request, RequestHandler next) {
    try {
        final JsonValue jsonValue = request.getContent();
        final Subject callingSubject = contextHelper.getSubject(context);
        final String realm = contextHelper.getRealm(context);
        retrieveResourceType(jsonValue, callingSubject, realm);
    } catch (EntitlementException eE) {
        debug.error("Error filtering policy create CREST request", eE);
        return resourceErrorHandler.handleError(context, request, eE).asPromise();
    } catch (ResourceException rE) {
        debug.error("Error filtering policy create CREST request", rE);
        return rE.asPromise();
    }
    return transform(next.handleCreate(context, request));
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject)

Example 47 with EntitlementException

use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStep method addMissingApplicationTypes.

/**
     * Add missing application types.
     *
     * @throws UpgradeException
     *         should the process of creating new application types fail
     */
private void addMissingApplicationTypes() throws UpgradeException {
    for (final Node typeNode : missingApplicationTypes) {
        final Map<String, Set<String>> keyValueMap = parseAttributeValuePairTags(typeNode);
        final String name = getNodeAttributeValue(typeNode, NAME);
        UpgradeProgress.reportStart(AUDIT_NEW_TYPE_START, name);
        keyValueMap.put(NAME, Collections.singleton(name));
        try {
            DEBUG.message("Saving new entitlement application type: " + name);
            entitlementService.storeApplicationType(createApplicationType(name, keyValueMap));
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        } catch (EntitlementException eE) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(eE);
        } catch (InstantiationException ie) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(ie);
        } catch (IllegalAccessException iae) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(iae);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.w3c.dom.Node)

Example 48 with EntitlementException

use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStep method addMissingActions.

/**
     * Adds the missing actions to their corresponding application type's.
     *
     * @throws UpgradeException If there was an error while updating the application type.
     */
private void addMissingActions() throws UpgradeException {
    for (final Map.Entry<String, Map<String, Boolean>> entry : missingActions.entrySet()) {
        final String name = entry.getKey();
        final Map<String, Boolean> actions = entry.getValue();
        try {
            UpgradeProgress.reportStart(AUDIT_MODIFIED_TYPE_START, name);
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Modifying application type " + name + " ; adding actions: " + actions);
            }
            final ApplicationType type = getType(name);
            type.getActions().putAll(actions);
            entitlementService.storeApplicationType(type);
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        } catch (EntitlementException ee) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(ee);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)

Example 49 with EntitlementException

use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStep method addChangedSubjects.

/**
     * Clears the subjects currently associated with an application, then replaces them with
     * the new set of conditions defined.
     *
     * @throws UpgradeException If there was an error while updating the application.
     */
private void addChangedSubjects() throws UpgradeException {
    for (final Map.Entry<String, Set<String>> entry : changedSubjects.entrySet()) {
        final String name = entry.getKey();
        final Set<String> subjects = entry.getValue();
        try {
            UpgradeProgress.reportStart(AUDIT_MODIFIED_SUB_START, name);
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Modifying application " + name + " ; adding subjects: " + subjects);
            }
            final Application application = getApplication(name);
            application.setSubjects(subjects);
            entitlementService.storeApplication(application);
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        } catch (EntitlementException ee) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(ee);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) Application(com.sun.identity.entitlement.Application)

Example 50 with EntitlementException

use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.

the class DataStore method searchPrivileges.

private Set<IPrivilege> searchPrivileges(String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, Set<String> subjectIndexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
    Set<IPrivilege> results = new HashSet<IPrivilege>();
    String filter = getFilter(indexes, subjectIndexes, bSubTree);
    String baseDN = getSearchBaseDN(realm, null);
    if (PolicyConstants.DEBUG.messageEnabled()) {
        PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchPrivileges");
        PolicyConstants.DEBUG.message("[PolicyEval] search filter: " + filter);
        PolicyConstants.DEBUG.message("[PolicyEval] search DN: " + baseDN);
    }
    if (filter != null) {
        SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        long start = DB_MONITOR_PRIVILEGE.start();
        if (SMSEntry.checkIfEntryExists(baseDN, token)) {
            try {
                Iterator i = SMSEntry.search(token, baseDN, filter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, excludeDNs);
                while (i.hasNext()) {
                    SMSDataEntry e = (SMSDataEntry) i.next();
                    Privilege privilege = Privilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
                    iterator.add(privilege);
                    results.add(privilege);
                }
            } catch (JSONException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            } catch (SMSException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            }
        }
        DB_MONITOR_PRIVILEGE.end(start);
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) JSONException(org.json.JSONException) EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONObject(org.json.JSONObject) IPrivilege(com.sun.identity.entitlement.IPrivilege) BufferedIterator(com.sun.identity.shared.BufferedIterator) Iterator(java.util.Iterator) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) HashSet(java.util.HashSet)

Aggregations

EntitlementException (com.sun.identity.entitlement.EntitlementException)221 Subject (javax.security.auth.Subject)68 HashSet (java.util.HashSet)58 SSOException (com.iplanet.sso.SSOException)51 Set (java.util.Set)50 SSOToken (com.iplanet.sso.SSOToken)47 SMSException (com.sun.identity.sm.SMSException)45 Application (com.sun.identity.entitlement.Application)37 Test (org.testng.annotations.Test)37 HashMap (java.util.HashMap)34 ResourceException (org.forgerock.json.resource.ResourceException)33 ResourceResponse (org.forgerock.json.resource.ResourceResponse)32 Privilege (com.sun.identity.entitlement.Privilege)22 JsonValue (org.forgerock.json.JsonValue)19 JSONException (org.json.JSONException)19 CLIException (com.sun.identity.cli.CLIException)18 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)17 ServiceConfig (com.sun.identity.sm.ServiceConfig)17 ResourceType (org.forgerock.openam.entitlement.ResourceType)17 PolicyException (com.sun.identity.policy.PolicyException)16