Search in sources :

Example 41 with ServiceConfig

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

the class DataStore method getIndexCount.

private static int getIndexCount(String realm, boolean referral) {
    int count = 0;
    if (adminToken != null) {
        try {
            ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, adminToken);
            ServiceConfig orgConf = mgr.getOrganizationConfig(realm, null);
            if (orgConf != null) {
                Map<String, Set<String>> map = orgConf.getAttributes();
                Set<String> set = (referral) ? map.get(REFERRAL_INDEX_COUNT) : map.get(INDEX_COUNT);
                if ((set != null) && !set.isEmpty()) {
                    String strCount = (String) set.iterator().next();
                    count = Integer.parseInt(strCount);
                }
            }
        } catch (NumberFormatException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        } catch (SMSException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        } catch (SSOException ex) {
            PolicyConstants.DEBUG.error("DataStore.getIndexCount", ex);
        }
    }
    return count;
}
Also used : HashSet(java.util.HashSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 42 with ServiceConfig

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

the class DataStore method getOrgConfig.

private ServiceConfig getOrgConfig(SSOToken adminToken, String realm) throws SMSException, SSOException {
    ServiceConfigManager mgr = new ServiceConfigManager(SERVICE_NAME, adminToken);
    ServiceConfig orgConf = mgr.getOrganizationConfig(realm, null);
    if (orgConf == null) {
        mgr.createOrganizationConfig(realm, null);
    }
    return orgConf;
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 43 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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 44 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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 45 with ServiceConfig

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

the class UserIdRepo method getOrgConfig.

static ServiceConfig getOrgConfig(SSOToken adminToken) throws SMSException, SSOException {
    ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminToken);
    ServiceConfig cfg = svcCfgMgr.getOrganizationConfig("", null);
    Map values = new HashMap();
    if (cfg == null) {
        OrganizationConfigManager orgCfgMgr = new OrganizationConfigManager(adminToken, "/");
        ServiceSchemaManager schemaMgr = new ServiceSchemaManager(IdConstants.REPO_SERVICE, adminToken);
        ServiceSchema orgSchema = schemaMgr.getOrganizationSchema();
        Set attrs = orgSchema.getAttributeSchemas();
        for (Iterator iter = attrs.iterator(); iter.hasNext(); ) {
            AttributeSchema as = (AttributeSchema) iter.next();
            values.put(as.getName(), as.getDefaultValues());
        }
        cfg = orgCfgMgr.addServiceConfig(IdConstants.REPO_SERVICE, values);
    }
    return cfg;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) Iterator(java.util.Iterator) AttributeSchema(com.sun.identity.sm.AttributeSchema) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Aggregations

ServiceConfig (com.sun.identity.sm.ServiceConfig)285 SMSException (com.sun.identity.sm.SMSException)180 Set (java.util.Set)144 SSOException (com.iplanet.sso.SSOException)143 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)124 HashSet (java.util.HashSet)119 Map (java.util.Map)101 HashMap (java.util.HashMap)96 SSOToken (com.iplanet.sso.SSOToken)52 Iterator (java.util.Iterator)41 IdRepoException (com.sun.identity.idm.IdRepoException)27 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)22 EntitlementException (com.sun.identity.entitlement.EntitlementException)19 LinkedHashSet (java.util.LinkedHashSet)18 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)17 CLIException (com.sun.identity.cli.CLIException)16 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)16 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)13 ServiceSchema (com.sun.identity.sm.ServiceSchema)12