Search in sources :

Example 31 with IdRepo

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

the class IdServicesImpl method isActive.

public boolean isActive(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN) throws SSOException, IdRepoException {
    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);
    // First get the list of plugins that support the create 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);
    }
    // To avoid loading other plugins
    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)) {
                    return (idRepo.isActive(token, type, name));
                }
            }
        } catch (Exception idm) {
        // Ignore exception
        }
    }
    // Iterator through the plugins
    Iterator it = configuredPluginClasses.iterator();
    int noOfSuccess = configuredPluginClasses.size();
    boolean active = false;
    while (it.hasNext()) {
        IdRepo idRepo = (IdRepo) it.next();
        try {
            if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && (amsdkDN != null)) {
                active = idRepo.isActive(token, type, amsdkDN);
            } else if (idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
                // Already checked above
                noOfSuccess--;
                continue;
            } else {
                active = idRepo.isActive(token, type, name);
            }
            if (active) {
                break;
            }
        } catch (IdRepoFatalException idf) {
            // fatal ..throw it all the way up
            DEBUG.error("IdServicesImpl.isActive: Fatal Exception ", idf);
            throw idf;
        } catch (IdRepoException ide) {
            if (idRepo != null && DEBUG.warningEnabled()) {
                DEBUG.warning("IdServicesImpl.isActive: " + "Unable to check isActive 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.isActive: " + "Unable to check if identity is active " + type.getName() + "::" + name + " in any configured data store", origEx);
        }
        if (origEx != null) {
            throw origEx;
        } else {
            Object[] args = { "isActive", IdOperation.READ.getName() };
            throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
        }
    }
    return active;
}
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) 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)

Example 32 with IdRepo

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

the class IdRepoPluginsCache method removeIdRepo.

/**
     * Delete an IdRepo plugin
     */
private void removeIdRepo(String orgName, String name, boolean reinitialize) throws IdRepoException, SSOException {
    orgName = DNUtils.normalizeDN(orgName);
    synchronized (idrepoPlugins) {
        // Clear IdRepo plugins first since other threads should
        // not access it during shutdown
        clearReadOnlyPlugins(orgName);
        Map idrepos = (Map) idrepoPlugins.get(orgName);
        if (idrepos != null && !idrepos.isEmpty()) {
            // Iterate through the plugins
            for (Iterator items = idrepos.keySet().iterator(); items.hasNext(); ) {
                String iname = items.next().toString();
                if (iname.equalsIgnoreCase(name)) {
                    IdRepo repo = (IdRepo) idrepos.get(iname);
                    // Shutting down idrepo
                    if (debug.messageEnabled()) {
                        debug.message("IdRepoPluginsCache.removeIdRepo" + " for OrgName: " + orgName + " Repo Name: " + name);
                    }
                    // Remove from cache first
                    idrepos.remove(iname);
                    ShutdownIdRepoPlugin shutdownrepo = new ShutdownIdRepoPlugin(repo);
                    // Provide a delay of 500ms for existing operations
                    // to complete. the delay is in the forked thread.
                    SMSThreadPool.scheduleTask(shutdownrepo);
                    break;
                }
            }
            if (reinitialize) {
                // Adding plugin back provides the atomic operation
                // for the caller. Else, client will get No-plugins
                // configured exception.
                // Add the plugin back to the cache
                addIdRepo(orgName, name);
            }
        }
    }
}
Also used : IdRepo(com.sun.identity.idm.IdRepo) Iterator(java.util.Iterator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 33 with IdRepo

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

the class IdRepoPluginsCache method getAMRepoPlugin.

protected IdRepo getAMRepoPlugin(String orgName) throws SSOException, IdRepoException {
    IdRepo pluginClass = null;
    try {
        if (debug.messageEnabled()) {
            debug.message("AMSDK repo being initialized");
        }
        Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.AMSDK_PLUGIN);
        pluginClass = (IdRepo) thisClass.newInstance();
        Map amsdkConfig = new HashMap();
        Set vals = new HashSet();
        vals.add(DNMapper.realmNameToAMSDKName(orgName));
        amsdkConfig.put("amSDKOrgName", vals);
        pluginClass.initialize(amsdkConfig);
    } catch (Exception e) {
        debug.error("IdRepoPluginsCache.getAMRepoPlugin: " + "Unable to instantiate plugin for Org: " + orgName, e);
    }
    if (pluginClass != null) {
        // Add listener to this plugin class
        Map listenerConfig = new HashMap();
        listenerConfig.put("realm", orgName);
        listenerConfig.put("amsdk", "true");
        IdRepoListener lter = new IdRepoListener();
        lter.setConfigMap(listenerConfig);
        pluginClass.addListener(getAdminToken(), lter);
    }
    return pluginClass;
}
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) 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 34 with IdRepo

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

the class IdRepoPluginsCache method getSpecialRepoPlugin.

// Internal repos
private IdRepo getSpecialRepoPlugin() throws SSOException, IdRepoException {
    // Valid only for root realm
    IdRepo pluginClass = null;
    try {
        if (debug.messageEnabled()) {
            debug.message("Special repo being initialized");
        }
        Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.SPECIAL_PLUGIN);
        pluginClass = (IdRepo) thisClass.newInstance();
        HashMap config = new HashMap(2);
        config.put("realm", ServiceManager.getBaseDN());
        pluginClass.initialize(config);
        IdRepoListener lter = new IdRepoListener();
        lter.setConfigMap(config);
        pluginClass.addListener(getAdminToken(), lter);
    } catch (Exception e) {
        debug.error("IdRepoPluginsCache.getSpecialRepoPlugin: " + "Unable to init plugin: " + IdConstants.SPECIAL_PLUGIN, e);
    }
    return pluginClass;
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) IdRepo(com.sun.identity.idm.IdRepo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

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