Search in sources :

Example 61 with SMSException

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

the class EntitlementService method getApplicationConfiguration.

/**
     * Get the service config for registered applications.
     * @param token The admin token for access to the Service Config.
     * @param realm The realm from which to retrieve the service config.
     * @return The application Service Config.
     */
private ServiceConfig getApplicationConfiguration(SSOToken token, String realm) {
    try {
        if (token != null) {
            if (realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX) || realm.startsWith(SMSEntry.SUN_INTERNAL_REALM_PREFIX2)) {
                realm = "/";
            }
            // TODO. Since applications for the hidden realms have to be
            // the same as root realm mainly for delegation without any
            // referrals, the hack is to use root realm for hidden realm.
            String hackRealm = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
            ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, token);
            ServiceConfig orgConfig = mgr.getOrganizationConfig(hackRealm, null);
            if (orgConfig != null) {
                return orgConfig.getSubConfig(EntitlementUtils.REGISTERED_APPLICATIONS);
            }
        } else {
            PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration, admin token is missing");
        }
    } catch (ClassCastException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplicationConfiguration", ex);
    }
    return null;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 62 with SMSException

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

the class EntitlementService method addApplicationAction.

/**
     * Adds a new action.
     *
     * @param appName application name.
     * @param name Action name.
     * @param defVal Default value.
     * @throws EntitlementException if action cannot be added.
     */
public void addApplicationAction(String appName, String name, Boolean defVal) throws EntitlementException {
    try {
        SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
        if (token == null) {
            throw new EntitlementException(226);
        }
        ServiceConfig applConf = getApplicationSubConfig(token, realm, appName);
        if (applConf != null) {
            Map<String, Set<String>> data = applConf.getAttributes();
            Map<String, Set<String>> result = addAction(data, name, defVal);
            if (result != null) {
                applConf.setAttributes(result);
            }
        }
    } catch (SMSException ex) {
        throw new EntitlementException(221, ex);
    } catch (SSOException ex) {
        throw new EntitlementException(221, ex);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 63 with SMSException

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

the class EntitlementService method setConfiguration.

private static void setConfiguration(SSOToken token, String attrName, Set<String> values) {
    try {
        if (token != null) {
            ServiceSchemaManager smgr = new ServiceSchemaManager(SERVICE_NAME, token);
            AttributeSchema as = smgr.getGlobalSchema().getAttributeSchema(attrName);
            if (as != null) {
                as.setDefaultValues(values);
            }
        } else {
            PolicyConstants.DEBUG.error("EntitlementService.getAttributeValues: " + "admin token is missing");
        }
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.setAttributeValues", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.setAttributeValues", ex);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) AttributeSchema(com.sun.identity.sm.AttributeSchema) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 64 with SMSException

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

the class DataStore method findPolicies.

private List<Privilege> findPolicies(String realm, String ldapFilter) throws EntitlementException {
    List<Privilege> results = new ArrayList<>();
    String baseDN = getSearchBaseDN(realm, null);
    SSOToken token = AccessController.doPrivileged(AdminTokenAction.getInstance());
    if (SMSEntry.checkIfEntryExists(baseDN, token)) {
        try {
            @SuppressWarnings("unchecked") Iterator<SMSDataEntry> iterator = SMSEntry.search(token, baseDN, ldapFilter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, emptySet());
            while (iterator.hasNext()) {
                SMSDataEntry entry = iterator.next();
                String policyJson = entry.getAttributeValue(SERIALIZABLE_INDEX_KEY);
                results.add(Privilege.getInstance(new JSONObject(policyJson)));
            }
        } catch (JSONException | SMSException e) {
            throw new EntitlementException(EntitlementException.UNABLE_SEARCH_PRIVILEGES, e);
        }
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONObject(org.json.JSONObject) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege)

Example 65 with SMSException

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

the class DataStore method searchReferral.

/**
     * Returns a set of referral privilege that satifies the resource and
     * subject indexes.
     *
     * @param adminToken Subject who has the rights to read datastore.
     * @param realm Realm name
     * @param iterator Buffered iterator to have the result fed to it.
     * @param indexes Resource search indexes.
     * @param bSubTree <code>true</code> to do sub tree search
     * @param excludeDNs Set of DN to be excluded from the search results.
     * @return a set of privilege that satifies the resource and subject
     * indexes.
     */
public Set<ReferralPrivilege> searchReferral(SSOToken adminToken, String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
    Set<ReferralPrivilege> results = new HashSet<ReferralPrivilege>();
    String filter = getFilter(indexes, null, bSubTree);
    String baseDN = getSearchBaseDN(realm, REFERRAL_STORE);
    if (PolicyConstants.DEBUG.messageEnabled()) {
        PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchReferral");
        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_REFERRAL.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();
                    ReferralPrivilege referral = ReferralPrivilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
                    iterator.add(referral);
                    results.add(referral);
                }
                iterator.isDone();
            } 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_REFERRAL.end(start);
    }
    return results;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) SSOToken(com.iplanet.sso.SSOToken) JSONObject(org.json.JSONObject) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) BufferedIterator(com.sun.identity.shared.BufferedIterator) Iterator(java.util.Iterator) JSONException(org.json.JSONException) HashSet(java.util.HashSet)

Aggregations

SMSException (com.sun.identity.sm.SMSException)704 SSOException (com.iplanet.sso.SSOException)525 Set (java.util.Set)272 HashSet (java.util.HashSet)200 SSOToken (com.iplanet.sso.SSOToken)185 Map (java.util.Map)166 ServiceConfig (com.sun.identity.sm.ServiceConfig)164 HashMap (java.util.HashMap)158 CLIException (com.sun.identity.cli.CLIException)149 ServiceSchema (com.sun.identity.sm.ServiceSchema)138 Iterator (java.util.Iterator)133 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)131 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)104 IOutput (com.sun.identity.cli.IOutput)96 IdRepoException (com.sun.identity.idm.IdRepoException)86 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)84 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)83 AttributeSchema (com.sun.identity.sm.AttributeSchema)66 IOException (java.io.IOException)55 List (java.util.List)51