Search in sources :

Example 11 with IdRepo

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

the class IdServicesImpl method getMembers.

/*
    * (non-Javadoc)
    */
public Set getMembers(SSOToken token, IdType type, String name, String amOrgName, IdType membersType, String amsdkDN) 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, null, 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);
    }
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    Set membersSet = new HashSet();
    Set amsdkMembers = new HashSet();
    boolean amsdkIncluded = false;
    while (it.hasNext()) {
        IdRepo idRepo = (IdRepo) it.next();
        if (!idRepo.getSupportedTypes().contains(membersType) || idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
            // IdRepo plugin does not support the idType for
            // memberships
            noOfSuccess--;
            continue;
        }
        try {
            boolean isAMSDK = idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN);
            Set members = (isAMSDK && (amsdkDN != null)) ? idRepo.getMembers(token, type, amsdkDN, membersType) : idRepo.getMembers(token, type, name, membersType);
            if (isAMSDK) {
                amsdkMembers.addAll(members);
                amsdkIncluded = true;
            } else {
                membersSet.add(members);
            }
        } catch (IdRepoUnsupportedOpException ide) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to read identity members 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("IdServicesImpl.getMembers: " + "Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to read identity members in the following" + " repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
            }
            noOfSuccess--;
            origEx = (origEx == null) ? ide : origEx;
        }
    }
    if (noOfSuccess == 0) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to get members for identity " + type.getName() + "::" + name + " in any configured data store", origEx);
        }
        if (origEx != null) {
            throw origEx;
        } else {
            return (Collections.EMPTY_SET);
        }
    } else {
        Set results = combineMembers(token, membersSet, membersType, amOrgName, amsdkIncluded, amsdkMembers);
        return results;
    }
}
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) IdRepoFatalException(com.sun.identity.idm.IdRepoFatalException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 12 with IdRepo

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

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

the class IdRepoPluginsCache method getIdRepoPlugins.

protected Set getIdRepoPlugins(String orgName, IdOperation op, IdType type) throws IdRepoException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("IdRepoPluginsCache.getIdRepoPlugins for " + "OrgName: " + orgName + " Op: " + op + " Type: " + type);
    }
    String cacheName = DNUtils.normalizeDN(orgName) + op.toString() + type.toString();
    Set answer = (Set) readonlyPlugins.get(cacheName);
    if ((answer != null) && !answer.isEmpty()) {
        return (answer);
    }
    answer = new OrderedSet();
    Set plugins = getIdRepoPlugins(orgName);
    if ((plugins != null) && !plugins.isEmpty()) {
        for (Iterator items = plugins.iterator(); items.hasNext(); ) {
            IdRepo repo = (IdRepo) items.next();
            if (repo.getSupportedTypes().contains(type)) {
                Set ops = repo.getSupportedOperations(type);
                if (ops.contains(op)) {
                    answer.add(repo);
                }
            }
        }
    }
    if (debug.messageEnabled()) {
        Set ps = new HashSet();
        for (Iterator items = answer.iterator(); items.hasNext(); ) {
            IdRepo repo = (IdRepo) items.next();
            ps.add(repo.getClass().getName());
        }
        debug.message("IdRepoPluginsCache.getIdRepoPlugins retuned for" + " OrgName: " + orgName + " Op: " + op + " Type: " + type + " Plugins: " + ps);
    }
    synchronized (idrepoPlugins) {
        if (answer != null) {
            readonlyPlugins.put(cacheName, answer);
        }
    }
    return (answer);
}
Also used : OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) HashSet(java.util.HashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) IdRepo(com.sun.identity.idm.IdRepo) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 14 with IdRepo

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

use of com.sun.identity.idm.IdRepo 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)

Aggregations

IdRepo (com.sun.identity.idm.IdRepo)34 HashSet (java.util.HashSet)30 IdRepoException (com.sun.identity.idm.IdRepoException)29 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)28 Iterator (java.util.Iterator)28 Set (java.util.Set)28 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)25 IdRepoFatalException (com.sun.identity.idm.IdRepoFatalException)19 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 AMHashMap (com.iplanet.am.sdk.AMHashMap)11 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)11 SMSException (com.sun.identity.sm.SMSException)11 SSOException (com.iplanet.sso.SSOException)10 LinkedHashMap (java.util.LinkedHashMap)8 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)7 DelegationException (com.sun.identity.delegation.DelegationException)6 IdRepoListener (com.sun.identity.idm.IdRepoListener)4 RepoSearchResults (com.sun.identity.idm.RepoSearchResults)3