Search in sources :

Example 61 with EntitlementException

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

the class EntitlementService method storeApplicationType.

/**
     * Stores the application type to data store.
     *
     * @param applicationType Application type  object.
     * @throws EntitlementException if application type cannot be stored.
     */
public void storeApplicationType(ApplicationType applicationType) throws EntitlementException {
    try {
        SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
        if (token == null) {
            Object[] arg = { applicationType.getName() };
            throw new EntitlementException(246, arg);
        }
        ServiceConfig conf = getApplicationTypeCollectionConfig(token);
        if (conf != null) {
            ServiceConfig sc = conf.getSubConfig(applicationType.getName());
            if (sc == null) {
                conf.addSubConfig(applicationType.getName(), EntitlementUtils.APPLICATION_TYPE, 0, getApplicationTypeData(applicationType));
            } else {
                sc.setAttributes(getApplicationTypeData(applicationType));
            }
        }
    } catch (SMSException ex) {
        Object[] arg = { applicationType.getName() };
        throw new EntitlementException(241, arg, ex);
    } catch (SSOException ex) {
        Object[] arg = { applicationType.getName() };
        throw new EntitlementException(241, arg, ex);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 62 with EntitlementException

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

the class EntitlementService method addSubjectAttributeNames.

/**
     * Returns subject attribute names.
     *
     * @param applicationName  Application name.
     * @param names subject attribute names.
     * @throws EntitlementException if subject attribute names cannot be
     * returned.
     */
public void addSubjectAttributeNames(String applicationName, Set<String> names) throws EntitlementException {
    if ((names == null) || names.isEmpty()) {
        return;
    }
    try {
        SSOToken token = getSSOToken();
        if (token == null) {
            throw new EntitlementException(225);
        }
        Application appl = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realm, applicationName);
        if (appl != null) {
            appl.addAttributeNames(names);
        }
        ServiceConfig applConf = getApplicationSubConfig(token, realm, applicationName);
        String parentRealm = realm;
        while (applConf == null) {
            parentRealm = getParentRealm(parentRealm);
            if (parentRealm == null) {
                break;
            }
            applConf = getApplicationSubConfig(token, parentRealm, applicationName);
        }
        if (applConf != null) {
            Set<String> orig = (Set<String>) applConf.getAttributes().get(ATTR_NAME_SUBJECT_ATTR_NAMES);
            if ((orig == null) || orig.isEmpty()) {
                orig = new HashSet<String>();
            }
            orig.addAll(names);
            Map<String, Set<String>> map = new HashMap<String, Set<String>>();
            map.put(ATTR_NAME_SUBJECT_ATTR_NAMES, orig);
            applConf.setAttributes(map);
        }
    } catch (SMSException ex) {
        throw new EntitlementException(220, ex);
    } catch (SSOException ex) {
        throw new EntitlementException(220, 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) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) Application(com.sun.identity.entitlement.Application)

Example 63 with EntitlementException

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

the class EntitlementService method getApplications.

/**
     * Returns a set of registered applications.
     *
     * @return a set of registered applications.
     */
public Set<Application> getApplications() {
    final Set<Application> results = new HashSet<Application>();
    try {
        SSOToken token = getSSOToken();
        final ServiceConfig appConfig = getApplicationConfiguration(token, realm);
        if (appConfig != null) {
            final Set<String> names = appConfig.getSubConfigNames();
            for (String name : names) {
                results.add(createApplication(appConfig, name));
            }
        }
    } catch (EntitlementException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    } catch (ClassCastException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    } catch (InstantiationException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    } catch (IllegalAccessException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getRawApplications", ex);
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) EntitlementException(com.sun.identity.entitlement.EntitlementException) ServiceConfig(com.sun.identity.sm.ServiceConfig) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet)

Example 64 with EntitlementException

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

the class EntitlementService method searchApplicationNames.

/**
     * Returns a set of application names for a given search criteria.
     *
     * @param adminSubject Admin Subject
     * @param filters Set of search filter.
     * @return a set of application names for a given search criteria.
     * @throws EntitlementException if search failed.
     */
public Set<String> searchApplicationNames(Subject adminSubject, Set<SearchFilter> filters) throws EntitlementException {
    SSOToken token = getSSOToken(adminSubject);
    if (token == null) {
        throw new EntitlementException(451);
    }
    String baseDN = getApplicationSearchBaseDN(realm);
    if (!SMSEntry.checkIfEntryExists(baseDN, token)) {
        return Collections.EMPTY_SET;
    }
    try {
        Set<String> dns = SMSEntry.search(token, baseDN, getApplicationSearchFilter(filters), 0, 0, false, false);
        Set<String> results = new HashSet<String>();
        for (String dn : dns) {
            if (!LDAPUtils.dnEquals(baseDN, dn)) {
                results.add(LDAPUtils.rdnValueFromDn(dn));
            }
        }
        return results;
    } catch (SMSException e) {
        throw new EntitlementException(450, e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) HashSet(java.util.HashSet)

Example 65 with EntitlementException

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

the class EntitlementService method getApplication.

/**
     * {@inheritDoc}
     */
public Application getApplication(String name) {
    try {
        final ServiceConfig appConfig = getApplicationConfiguration(getSSOToken(), realm);
        final Set<String> names = appConfig.getSubConfigNames();
        if (appConfig != null && names.contains(name)) {
            return createApplication(appConfig, name);
        }
    } catch (EntitlementException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    } catch (ClassCastException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    } catch (InstantiationException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    } catch (IllegalAccessException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    } catch (SMSException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    } catch (SSOException ex) {
        PolicyConstants.DEBUG.error("EntitlementService.getApplication", ex);
    }
    return null;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

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