Search in sources :

Example 91 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class IdRepoPluginsCache method getAgentRepoPlugin.

protected IdRepo getAgentRepoPlugin(String orgName) throws SSOException, IdRepoException {
    IdRepo pluginClass = null;
    try {
        if (debug.messageEnabled()) {
            debug.message("Agents repo being initialized");
        }
        Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.AGENTREPO_PLUGIN);
        pluginClass = (IdRepo) thisClass.newInstance();
        HashMap config = new HashMap(2);
        HashSet realmName = new HashSet();
        realmName.add(orgName);
        config.put("agentsRepoRealmName", realmName);
        pluginClass.initialize(config);
    } catch (Exception e) {
        debug.error("IdRepoPluginsCache.getAgentRepoPlugin: " + "Unable to init plugin: " + IdConstants.AGENTREPO_PLUGIN, e);
    }
    // Add listener
    if (pluginClass != null) {
        Map listenerConfig = new HashMap();
        listenerConfig.put("realm", orgName);
        IdRepoListener lter = new IdRepoListener();
        lter.setConfigMap(listenerConfig);
        pluginClass.addListener(getAdminToken(), lter);
    }
    // Retuns the plugin class
    return pluginClass;
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) IdRepo(com.sun.identity.idm.IdRepo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Example 92 with IdRepoException

use of com.sun.identity.idm.IdRepoException 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 93 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class IdServicesImpl method getAttributes.

/*
    * (non-Javadoc)
    */
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isString) throws IdRepoException, SSOException {
    IdRepoException origEx = null;
    // Check permission first. If allowed then proceed, else the
    // checkPermission method throws an "402" exception.
    checkPermission(token, amOrgName, name, attrNames, IdOperation.READ, type);
    // Get the list of plugins that support the read operation
    Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.READ, type);
    if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
    }
    // Verify if it is an internal/special identity
    // to avoid calling other plugins for special users
    Set attrMapsSet = new HashSet();
    if (isSpecialIdentity(token, name, type, amOrgName)) {
        try {
            for (Iterator items = configuredPluginClasses.iterator(); items.hasNext(); ) {
                IdRepo idRepo = (IdRepo) items.next();
                if (idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
                    attrMapsSet.add(idRepo.getAttributes(token, type, name, attrNames));
                    return (combineAttrMaps(attrMapsSet, true));
                }
            }
        } catch (Exception e) {
        // Ignore and continue
        }
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    IdRepo idRepo;
    while (it.hasNext()) {
        idRepo = (IdRepo) it.next();
        try {
            Map cMap = idRepo.getConfiguration();
            // do stuff to map attr names.
            Set mappedAttributeNames = mapAttributeNames(attrNames, cMap);
            Map aMap = null;
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
                if (isString) {
                    aMap = idRepo.getAttributes(token, type, amsdkDN, mappedAttributeNames);
                } else {
                    aMap = idRepo.getBinaryAttributes(token, type, amsdkDN, mappedAttributeNames);
                }
            } else {
                if (isString) {
                    aMap = idRepo.getAttributes(token, type, name, mappedAttributeNames);
                } else {
                    aMap = idRepo.getBinaryAttributes(token, type, name, mappedAttributeNames);
                }
            }
            aMap = reverseMapAttributeNames(aMap, cMap);
            attrMapsSet.add(aMap);
        } catch (IdRepoUnsupportedOpException ide) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.getAttributes: " + "Unable to read identity in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("GetAttributes: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.getAttributes: " + "Unable to read identity in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        }
    }
    if (noOfSuccess == 0) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("idServicesImpl.getAttributes: " + "Unable to get attributes for identity " + type.getName() + ", " + name + " in any configured data store", origEx);
        }
        throw origEx;
    }
    return combineAttrMaps(attrMapsSet, isString);
}
Also used : IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) IdRepo(com.sun.identity.idm.IdRepo) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) DelegationException(com.sun.identity.delegation.DelegationException) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 94 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class IdServicesImpl method createRealmIdentity.

private AMIdentity createRealmIdentity(SSOToken token, IdType type, String name, Map attrMap, String orgName) throws IdRepoException, SSOException {
    try {
        OrganizationConfigManager orgMgr = new OrganizationConfigManager(token, orgName);
        Map<String, Set<String>> newAttrMap = new HashMap<>(attrMap);
        if (!newAttrMap.containsKey(IdConstants.ORGANIZATION_STATUS_ATTR)) {
            newAttrMap.put(IdConstants.ORGANIZATION_STATUS_ATTR, CollectionUtils.asSet("Active"));
        }
        Map serviceAttrsMap = new HashMap();
        serviceAttrsMap.put(IdConstants.REPO_SERVICE, newAttrMap);
        orgMgr.createSubOrganization(name, serviceAttrsMap);
        return getSubRealmIdentity(token, name, orgName);
    } catch (SMSException sme) {
        DEBUG.error("AMIdentityRepository.createIdentity() - " + "Error occurred while creating " + type.getName() + ":" + name, sme);
        throw new IdRepoException(sme.getMessage());
    }
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 95 with IdRepoException

use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.

the class IdRepoPluginsCache method constructIdRepoPlugin.

/**
     * Constructs IdRepo plugin object and returns.
     */
private IdRepo constructIdRepoPlugin(String orgName, Map configMap, String name) throws IdRepoException, SSOException {
    IdRepo answer = null;
    if (debug.messageEnabled()) {
        debug.message("IdRepoPluginsCache.constructIdRepoPlugin: config=" + configMap.get("sunIdRepoClass"));
    }
    if (configMap == null || configMap.isEmpty()) {
        if (debug.warningEnabled()) {
            debug.warning("IdRepoPluginsCache.constructIdRepoPlugin: " + "Cannot construct with empty config data");
        }
        return (null);
    }
    Set vals = (Set) configMap.get(IdConstants.ID_REPO);
    if ((vals != null) && !vals.isEmpty()) {
        String className = (String) vals.iterator().next();
        Class thisClass;
        try {
            thisClass = Thread.currentThread().getContextClassLoader().loadClass(className);
            answer = (IdRepo) thisClass.newInstance();
        } catch (Throwable ex) {
            debug.error("IdRepoPluginsCached.constructIdRepoPlugin " + " OrgName: " + orgName + " ConfigMap: " + configMap, ex);
            throw (new IdRepoException(ex.getMessage()));
        }
        answer.initialize(configMap);
        // Add listener to this plugin class!
        Map listenerConfig = new HashMap();
        listenerConfig.put("realm", orgName);
        listenerConfig.put("plugin-name", name);
        if (className.equals(IdConstants.AMSDK_PLUGIN)) {
            listenerConfig.put("amsdk", "true");
        }
        IdRepoListener listener = new IdRepoListener();
        listener.setConfigMap(listenerConfig);
        answer.addListener(getAdminToken(), listener);
    }
    return (answer);
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) HashSet(java.util.HashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) IdRepo(com.sun.identity.idm.IdRepo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdRepoException(com.sun.identity.idm.IdRepoException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

IdRepoException (com.sun.identity.idm.IdRepoException)403 SSOException (com.iplanet.sso.SSOException)275 Set (java.util.Set)224 AMIdentity (com.sun.identity.idm.AMIdentity)221 HashSet (java.util.HashSet)183 Map (java.util.Map)121 Iterator (java.util.Iterator)118 SSOToken (com.iplanet.sso.SSOToken)112 HashMap (java.util.HashMap)110 SMSException (com.sun.identity.sm.SMSException)103 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)96 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)67 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)58 IdType (com.sun.identity.idm.IdType)57 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)51 CLIException (com.sun.identity.cli.CLIException)48 IOutput (com.sun.identity.cli.IOutput)45 IdSearchResults (com.sun.identity.idm.IdSearchResults)44 IdSearchControl (com.sun.identity.idm.IdSearchControl)39 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)35