Search in sources :

Example 66 with ServiceConfig

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

the class IdRepoUtils method loadIdRepoSchema.

/**
     * Loads schema to specified IdRepo.
     * 
     * @param ssoToken single sign on token of authenticated user identity
     * @param idRepoName IdRepo name
     * @param realm the realm
     * @param servletCtx the servlet context
     *
     * @throws IdRepoException If schema can't be loaded or there are
     *     repository related error conditions.
     */
public static void loadIdRepoSchema(SSOToken ssoToken, String idRepoName, String realm, ServletContext servletCtx) throws IdRepoException {
    if (servletCtx == null) {
        return;
    }
    try {
        ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, ssoToken);
        ServiceConfig cfg = svcCfgMgr.getOrganizationConfig(realm, null);
        ServiceConfig ss = cfg.getSubConfig(idRepoName);
        if (ss == null) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdRepoUtils.loadIdRepoSchema: data store " + idRepoName + " for realm " + realm + " doesn't exist.");
            }
            Object[] args = { idRepoName, realm };
            throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_DOESNT_EXIST_FOR_REALM, args);
        }
        String idRepoType = ss.getSchemaID();
        Map attrValues = ss.getAttributes();
        String schemaFiles = getSchemaFiles(idRepoType);
        if ((schemaFiles == null) || (schemaFiles.trim().length() == 0)) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("IdRepoUtils.loadIdRepoSchema: data store " + idRepoName + " for realm " + realm + " doesn't have " + "schema files.");
            }
            return;
        }
        StringTokenizer st = new StringTokenizer(schemaFiles);
        while (st.hasMoreTokens()) {
            String schemaFile = st.nextToken();
            tagSwapAndImportSchema(schemaFile, attrValues, servletCtx, idRepoType);
        }
    } catch (SMSException smsex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", smsex);
        }
        Object[] args = { idRepoName, realm };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_READ_PLUGIN_FOR_REALM, args);
    } catch (SSOException ssoex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", ssoex);
        }
        Object[] args = { idRepoName, realm };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_READ_PLUGING_FOR_REALM_SSOTOKEN_NOT_VALID, args);
    } catch (Exception ex) {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRepoUtils.loadIdRepoSchema:", ex);
        }
        Object[] args = { idRepoName, realm, ex.getMessage() };
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_LOAD_SCHEMA_FOR_PLUGIN_FOR_REALM, args);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 67 with ServiceConfig

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

the class IdRepoPluginsCache method getIdRepoPlugins.

protected Set getIdRepoPlugins(String orgName) throws IdRepoException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("IdRepoPluginsCache.getIdRepoPlugins orgName: " + orgName);
    }
    // Check the cache
    Map orgRepos = null;
    orgName = DNUtils.normalizeDN(orgName);
    Set readOrgRepos = (Set) readonlyPlugins.get(orgName);
    if ((readOrgRepos != null) && !readOrgRepos.isEmpty()) {
        return (readOrgRepos);
    }
    synchronized (idrepoPlugins) {
        orgRepos = (Map) idrepoPlugins.get(orgName);
        if (orgRepos == null) {
            try {
                if (debug.messageEnabled()) {
                    debug.message("IdRepoPluginsCache.getIdRepoPlugins " + "Not in cache for: " + orgName);
                }
                // Initialize the plugins
                orgRepos = new LinkedHashMap();
                ServiceConfig sc = idRepoServiceConfigManager.getOrganizationConfig(orgName, null);
                if (sc == null) {
                    // Organization does not exist. Error condition
                    debug.error("IdRepoPluginsCache.getIdRepoPlugins " + "Org does not exisit: " + orgName);
                    Object[] args = { orgName };
                    throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.REALM_DOESNT_EXIST, args);
                }
                Set subConfigNames = sc.getSubConfigNames();
                if (debug.messageEnabled()) {
                    debug.message("IdRepoPluginsCache.getIdRepoPlugins " + "Loading plugins: " + subConfigNames);
                }
                if (subConfigNames != null && !subConfigNames.isEmpty()) {
                    for (Iterator items = subConfigNames.iterator(); items.hasNext(); ) {
                        String idRepoName = (String) items.next();
                        ServiceConfig reposc = sc.getSubConfig(idRepoName);
                        if (reposc == null) {
                            debug.error("IdRepoPluginsCache." + "getIdRepoPlugins SubConfig is null for" + " orgName: " + orgName + " subConfig Name: " + idRepoName);
                        }
                        IdRepo repo = constructIdRepoPlugin(orgName, reposc.getAttributesForRead(), idRepoName);
                        // Add to cache
                        orgRepos.put(idRepoName, repo);
                    }
                }
                // Add internal repos
                addInternalRepo(orgRepos, orgName);
                idrepoPlugins.put(orgName, orgRepos);
            } catch (SMSException ex) {
                debug.error("IdRepoPluginsCache.getIdRepoPlugins " + "SMS Exception for orgName: " + orgName, ex);
            }
        }
        // Cache a readonly copy
        if (orgRepos != null) {
            readOrgRepos = new OrderedSet();
            readOrgRepos.addAll(orgRepos.values());
            readonlyPlugins.put(orgName, readOrgRepos);
        }
    }
    if (debug.messageEnabled() && (readOrgRepos != null)) {
        Set ps = new HashSet();
        for (Iterator items = readOrgRepos.iterator(); items.hasNext(); ) {
            ps.add(items.next().getClass().getName());
        }
        debug.message("IdRepoPluginsCache.getIdRepoPlugins retuned for" + " OrgName: " + orgName + " Plugins: " + ps);
    }
    return (readOrgRepos);
}
Also used : OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) HashSet(java.util.HashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) LinkedHashMap(java.util.LinkedHashMap) IdRepo(com.sun.identity.idm.IdRepo) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 68 with ServiceConfig

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

the class AgentIdentityImpl method getAgentServiceConfig.

private ServiceConfig getAgentServiceConfig(SSOToken token) {
    AMIdentity identity;
    try {
        identity = IdUtils.getIdentity(token);
    } catch (IdRepoException | SSOException e) {
        debug.error("Exception while obtaining identity corresponding to SSOToken: {}", e, e);
        return null;
    }
    // before instantiating a ServiceConfigManager.
    if (!IdType.AGENT.equals(identity.getType())) {
        debug.message("Not an agent");
        return null;
    }
    ServiceConfig agentService;
    try {
        agentService = new ServiceConfigManager(AGENT_SERVICE_NAME, getAdminToken()).getOrganizationConfig(identity.getRealm(), null);
    } catch (Exception e) {
        debug.error("Exception while obtaining base AgentService ServiceConfig instance: {}", e, e);
        return null;
    }
    try {
        return agentService.getSubConfig(identity.getName());
    } catch (SSOException | SMSException e) {
        // Should only enter this block if the return from getAdminToken is an invalid token
        // or if an error occurs accessing LDAP.
        debug.error("Exception while obtaining AgentService SubConfig {}: {}", identity.getName(), e, e);
        return null;
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException)

Example 69 with ServiceConfig

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

the class UpgradeUtils method createOrgAuthConfig.

/**
     * Creates auth configurations for auth modules configuration in
     * core auth service.
     */
private static void createOrgAuthConfig(String realmName) throws Exception {
    String classMethod = "UpgradeUtils:createOrgAuthConfig: ";
    OrganizationConfigManager org = new OrganizationConfigManager(ssoToken, realmName);
    ServiceConfig orgConfig = org.getServiceConfig(AUTH_SERVICE_NAME);
    if (orgConfig != null) {
        Map aa = orgConfig.getAttributes();
        if (debug.messageEnabled()) {
            debug.message(classMethod + "Org is :" + realmName);
            debug.message(classMethod + "Attribute Map is :" + aa);
        }
        String orgName = realmName;
        if (LDAPUtils.isDN(realmName)) {
            orgName = LDAPUtils.rdnValueFromDn(realmName);
        }
        String authConfigName = orgName + "-authconfig";
        String adminAuthConfigName = orgName + "-admin-authconfig";
        Set authConfigAttrValue = (Set) aa.get(ATTR_ORG_AUTH_MODULE);
        if (debug.messageEnabled()) {
            debug.message(classMethod + "authConfigAttrValue : " + authConfigAttrValue);
        }
        Set newVal = new HashSet();
        if (authConfigAttrValue.size() != 1 && !authConfigAttrValue.contains(authConfigName)) {
            newVal.add(authConfigName);
            orgConfig.replaceAttributeValues(ATTR_ORG_AUTH_MODULE, authConfigAttrValue, newVal);
        }
        Set adminConfigAttrValue = (Set) aa.get(ATTR_ADMIN_AUTH_MODULE);
        if (debug.messageEnabled()) {
            debug.message("adminauthConfigAttrValue : " + adminConfigAttrValue);
        }
        if (adminConfigAttrValue.size() != 1 && !adminConfigAttrValue.contains(adminAuthConfigName)) {
            newVal.clear();
            newVal.add(adminAuthConfigName);
            orgConfig.replaceAttributeValues(ATTR_ADMIN_AUTH_MODULE, adminConfigAttrValue, newVal);
        }
        aa = orgConfig.getAttributes();
        ServiceConfig s = org.getServiceConfig(AUTH_CONFIG_SERVICE);
        ServiceConfig authConfig = s.getSubConfig(NAMED_CONFIG);
        if (authConfig == null) {
            s.addSubConfig(NAMED_CONFIG, null, 0, null);
            authConfig = s.getSubConfig(NAMED_CONFIG);
        }
        Map aMap = new HashMap();
        aMap.put(ATTR_AUTH_CONFIG, authConfigAttrValue);
        authConfig.addSubConfig(authConfigName, SUB_NAMED_CONFIG, 0, aMap);
        aMap.clear();
        aMap.put(ATTR_AUTH_CONFIG, adminConfigAttrValue);
        authConfig.addSubConfig(adminAuthConfigName, SUB_NAMED_CONFIG, 0, aMap);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 70 with ServiceConfig

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

the class UpgradeUtils method addSubConfig.

/**
     * Adds SubConfiguration to an existing subconfiguration in a service.
     *
     * @param serviceName the service name
     * @param parentConfigName the name of parent sub configuration.
     * @param subConfigName the subconfig name
     * @param subConfigID the subconfig id
     * @param attrValues a map of attribute value pairs to be added to the
     *        subconfig.
     * @param priority the priority value
     * @throws UpgradeException if there is an error.
     */
public static void addSubConfig(String serviceName, String parentConfigName, String subConfigName, String subConfigID, Map attrValues, int priority) throws UpgradeException {
    String classMethod = "UpgradeUtils:addSubConfig";
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, ssoToken);
        ServiceConfig sc = scm.getGlobalConfig(null);
        ServiceConfig sc1 = sc.getSubConfig(parentConfigName);
        if (sc != null) {
            sc1.addSubConfig(subConfigName, subConfigID, priority, attrValues);
        } else {
            debug.error(classMethod + "Error adding sub cofiguration" + subConfigName);
            throw new UpgradeException("Error adding subconfig");
        }
    } catch (SSOException ssoe) {
        throw new UpgradeException(classMethod + "invalid sso token");
    } catch (SMSException sm) {
        debug.error(classMethod + "Error loading subconfig", sm);
        throw new UpgradeException(classMethod + "error adding subconfig");
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

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