Search in sources :

Example 1 with IdRepoListener

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

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

Example 3 with IdRepoListener

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

the class IdRemoteEventListener method sendIdRepoNotification.

/**
     * Sends notifications to listeners added via <code>addListener</code>.
     * The parameter <code>nItem</code> is an XML document having a single
     * notification event, using the following DTD.
     * <p>
     * 
     * <pre>
     *       &lt;!-- EventNotification element specifes the change notification
     *       which contains AttributeValuePairs. The attributes defined
     *       are &quot;method&quot;, &quot;entityName&quot;, &quot;
     *       eventType&quot; and &quot;attrNames&quot;. --&gt;
     *       &lt;!ELEMENT EventNotification ( AttributeValuePairs )* &gt;
     *  
     *       &lt;!-- AttributeValuePair element contains attribute name and 
     *       values --&gt;
     *       &lt;!ELEMENT AttributeValuPair ( Attribute, Value*) &gt;
     *  
     *       &lt;!-- Attribute contains the attribute names, and the allowed 
     *       names are &quot;method&quot;, &quot;entityName&quot;, 
     *       &quot;eventType&quot; and &quot;attrNames&quot; --&gt;
     *       &lt;!ELEMENT Attribute EMPTY&gt;
     *       &lt;!ATTRLIST Attribute
     *       name ( method | entityName | eventType | attrNames ) 
     *       &quot;method&quot;
     *       &gt;
     *  
     *       &lt;!-- Value element specifies the values for the attributes 
     *       --&gt; &lt;!ELEMENT Value (#PCDATA) &gt;
     * </pre>
     * 
     * @param nItem
     *            notification event as a xml document
     * 
     */
static void sendIdRepoNotification(String nItem) {
    if (DEBUG.messageEnabled()) {
        DEBUG.message("IdRemoteEventListener::sendIdRepoNotification: " + "Received notification.");
    }
    // Construct the XML document
    StringBuilder sb = new StringBuilder(nItem.length() + 50);
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(nItem);
    try {
        // The second argument is set to false so that the xml escaped 
        // chars done by server code/IdRepoJAXRPCObjectImpl will not be 
        // unescaped.
        Map attrs = CreateServiceConfig.getAttributeValuePairs(SMSSchema.getXMLDocument(sb.toString(), false).getDocumentElement(), false);
        if (attrs == null || attrs.isEmpty()) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdRemoteEventListener::sendIdRepoNotification: " + "Invalid event: " + attrs);
            }
            return;
        } else if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteEventListener::sendIdRepoNotification " + "Decoded Event: " + attrs);
        }
        // Parse to get the entity name and the method
        String entityName = getAttributeValue(attrs, ENTITY_NAME);
        String method = getAttributeValue(attrs, METHOD);
        if (entityName == null || entityName.length() == 0 || method == null || method.length() == 0) {
            if (DEBUG.warningEnabled()) {
                DEBUG.warning("IdRemoteEventListener::sendIdRepoNotification: " + "Invalid universalID or method: " + entityName + " method");
            }
            return;
        }
        // Construct IdRepoListener and set the realm
        IdRepoListener repoListener = new IdRepoListener();
        String realm = null;
        if (entityName.toLowerCase().indexOf(",amsdkdn=") != -1) {
            AMIdentity id = new AMIdentity(null, entityName);
            realm = id.getRealm();
        } else {
            DN entityDN = DN.valueOf(entityName);
            realm = entityDN.parent().parent().toString();
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message("IdRemoteEventListener::sendIdRepoNotification: " + "modified UUID: " + entityName + " realm: " + realm);
        }
        Map configMap = new HashMap();
        configMap.put("realm", realm);
        repoListener.setConfigMap(configMap);
        // Send the notification change
        if (method.equalsIgnoreCase(OBJECT_CHANGED)) {
            int eventType = getEventType((Set) attrs.get(EVENT_TYPE));
            repoListener.objectChanged(entityName, null, eventType, null);
        } else if (method.equalsIgnoreCase(ALL_OBJECTS_CHANGED)) {
            repoListener.allObjectsChanged();
        } else {
            // Invalid method name
            handleError("invalid method name: " + method);
        }
    } catch (Exception e) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdRemoteEventListener::sendIdRepoNotification: " + "Unable to send notification: " + nItem, e);
        }
    }
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) HashMap(java.util.HashMap) AMIdentity(com.sun.identity.idm.AMIdentity) DN(org.forgerock.opendj.ldap.DN) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with IdRepoListener

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

the class IdRepoTestBase method setUpSuite.

@BeforeClass
public void setUpSuite() throws Exception {
    InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() {

        @Override
        public Set<Class<? extends Module>> getGuiceModules(Class<? extends Annotation> aClass) {
            return Collections.<Class<? extends Module>>singleton(TestGuiceModule.class);
        }
    });
    PowerMockito.mockStatic(WebtopNaming.class);
    idRepoListener = PowerMockito.mock(IdRepoListener.class);
    when(WebtopNaming.getAMServerID()).thenReturn("01");
    when(WebtopNaming.getSiteID(eq("01"))).thenReturn("02");
    memoryBackend = decorateBackend(new MemoryBackend(new LDIFEntryReader(getClass().getResourceAsStream(getLDIFPath()))));
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) Set(java.util.Set) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) GuiceModuleLoader(org.forgerock.guice.core.GuiceModuleLoader) MemoryBackend(org.forgerock.opendj.ldap.MemoryBackend) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with IdRepoListener

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

the class AMSDKRepo method notifyObjectChangedEvent.

public static void notifyObjectChangedEvent(String normalizedDN, int eventType) {
    if (debug.messageEnabled()) {
        debug.message("AMSDKRepo.notifyObjectChangedEvent - Sending " + "event to listeners.");
    }
    if (adminToken == null) {
        adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        try {
            sc = new AMStoreConnection(adminToken);
        } catch (SSOException ssoe) {
            // do nothing ... but log the error
            debug.error("AMSDKRepo:notifyObjectChangedEvent. Failed " + "to initialize AMStoreConnection...", ssoe);
        }
    }
    int type = 0;
    try {
        // If entry has been deleted, its type cannot be obtained
        if (eventType != AMObjectListener.DELETE) {
            type = sc.getAMObjectType(normalizedDN);
        }
    } catch (AMException amse) {
        debug.error("AMSDKRepo:notifyObjectChangedEvent Unable " + "to convert name to getAMObjectType.");
    } catch (SSOException amsso) {
        debug.error("AMSDKRepo:notifyObjectChangedEvent Unable " + "to detemine permission.");
    }
    IdType idType = null;
    switch(type) {
        case AMObject.GROUP:
        case AMObject.STATIC_GROUP:
        case AMObject.ASSIGNABLE_DYNAMIC_GROUP:
        case AMObject.DYNAMIC_GROUP:
            idType = IdType.GROUP;
            break;
        case AMObject.USER:
            idType = IdType.USER;
            break;
        case AMObject.ORGANIZATION:
        case AMObject.ORGANIZATIONAL_UNIT:
            idType = IdType.REALM;
            break;
        case AMObject.ROLE:
        case AMObject.MANAGED_ROLE:
            idType = IdType.ROLE;
            break;
        case AMObject.FILTERED_ROLE:
            idType = IdType.FILTEREDROLE;
            break;
        default:
            if (debug.messageEnabled()) {
                debug.message("AMSDKRepo:notifyObjectChangedEvent. " + "unknown matching type: type=" + type + " Entity: " + normalizedDN + " Eventtype: " + eventType);
            }
            break;
    }
    synchronized (listeners) {
        Iterator it = listeners.iterator();
        while (it.hasNext()) {
            IdRepoListener l = (IdRepoListener) it.next();
            Map configMap = l.getConfigMap();
            if (idType != null) {
                l.objectChanged(normalizedDN, idType, eventType, configMap);
                if (idType == IdType.USER) {
                    // agents were treated as users so we have to
                    // send agent change as well.
                    l.objectChanged(normalizedDN, IdType.AGENT, eventType, configMap);
                }
            } else {
                // Unknow idType, send notifications for all types
                l.objectChanged(normalizedDN, eventType, configMap);
            }
        }
    }
}
Also used : IdRepoListener(com.sun.identity.idm.IdRepoListener) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) IdType(com.sun.identity.idm.IdType)

Aggregations

IdRepoListener (com.sun.identity.idm.IdRepoListener)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 SSOException (com.iplanet.sso.SSOException)4 IdRepo (com.sun.identity.idm.IdRepo)4 IdRepoException (com.sun.identity.idm.IdRepoException)4 LinkedHashMap (java.util.LinkedHashMap)4 SMSException (com.sun.identity.sm.SMSException)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)2 Iterator (java.util.Iterator)2 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 IdType (com.sun.identity.idm.IdType)1 GuiceModuleLoader (org.forgerock.guice.core.GuiceModuleLoader)1 DN (org.forgerock.opendj.ldap.DN)1 MemoryBackend (org.forgerock.opendj.ldap.MemoryBackend)1 LDIFEntryReader (org.forgerock.opendj.ldif.LDIFEntryReader)1 BeforeClass (org.testng.annotations.BeforeClass)1