8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: IdRepoListener.java,v 1.16 2009/01/28 05:34:59 ww203982 Exp $
e6c3a72a023407f5d1fface64356e1cc81f1af31Phill Cunnington * Portions Copyrighted 2011-2016 ForgeRock AS.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.openam.ldap.PersistentSearchChangeType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.security.AdminTokenAction;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport com.sun.identity.shared.jaxrpc.SOAPClient;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfigManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Provides methods that can be called by IdRepo plugins to notify change
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * events. Used to update cache and also to send notifications to registered
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * listeners. Each IdRepo plugin will be given a unique instance of this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Additionally, this class maintains the configuration data for the IdRepo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * plugin and also to store the SMS Service attributes for the organization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.all.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Configuration data for the IdRepo plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Must have "realm" key to correctly send the notifications to clients
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Listener registed by JAXRPC Impl to send notifications
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static IdEventListener remoteListener = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("idrepoListener");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // To serialize and deserialize configMap
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Configured Identity Types
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Flags to check if caching is enabled and to clear them
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.am.sdk.AMObjectListener#allObjectsChanged()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("IdRepoListener: allObjectsChanged Called!");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if caching is enabled
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idServices = IdServicesFactory.getDataStoreServices();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If Caching was enabled - then clear the cache!!
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If Caching was enabled - then clear the cache!!
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the list of listeners setup with idRepo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ArrayList list = (ArrayList) AMIdentityRepository.listeners.get(org);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Update any listeners registered with IdRepo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster IdEventListener l = (IdEventListener) list.get(j);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method has been deprecated as of OpenSSO Enterprise 8.0.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name name of the identity that changed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param type change type i.e., add, delete, modify, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cMap configuration map that contains realm and plugin-name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @deprecated As of Sun Java System Access Manager 7.1.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void objectChanged(String name, int type, Map cMap) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Notification mechanism for IdRepo plugins to specify the identiy name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and identity type that has been changed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name name of the identity that changed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param idType IdType i.e., user, group, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param changeType change type i.e., add, delete, modify, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cMap configuration map that contains realm and plugin-name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void objectChanged(String name, IdType idType, int changeType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("objectChanged called with IdType= name: " + name +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " IdType: " + idType + " ChangeType: " + changeType +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the list of listeners setup with idRepo
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington List<IdEventListener> list = (List<IdEventListener>) AMIdentityRepository.listeners.get(org);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington list = list == null ? new ArrayList<IdEventListener>() : new ArrayList<>(list);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if caching is enabled
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idServices = IdServicesFactory.getDataStoreServices();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If Caching was enabled - then clear the cache!!
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] changed = getChangedIds(name, idType, cMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((IdCachedServices) idServices).dirtyCache(changed[i],
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster changeType, false, false, Collections.EMPTY_SET);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington // Update any listeners registered with IdRepo
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if(changeType == OBJECT_CHANGED || changeType == OBJECT_ADDED) {
c6f4e5c984e2f1a5a79e3253d8589591af50699aJon Thomas debug.warning("objectChanged called with an empty name");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void addRemoteListener(IdEventListener l) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the configurations for the IdRepo plugins
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Maintains the configurations for the IdRepo plugins
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Stores service's dynamic attributes within the IdRepo plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration. In the current implementation changes to dynamic
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attributes to LDAPv3Repo restart the plugin, since it triggers
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * a configuration change notification.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param sName service name for which attributes are being set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrs service synamic attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.idm.IdRepoException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setServiceAttributes(String sName, Map attrs)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String realm = (String) configMap.get("realm");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String pluginName = (String) configMap.get("plugin-name");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "IdRepoListener.setServiveAttribute: realm or plugin name"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + " is null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] args = { sName, IdType.ROLE.getName() };
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_ALREADY_ASSIGNED, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceConfigManager scm = new ServiceConfigManager(token,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceConfig sc = scm.getOrganizationConfig(realm, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceConfig subConfig = sc.getSubConfig(pluginName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = (Set) attributes.get(IdConstants.SERVICE_ATTRS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (vals == null || vals == Collections.EMPTY_SET) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String mapStr = sclient.encodeMap("result", attrs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attributes.put(IdConstants.SERVICE_ATTRS, vals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "IdRepoListener: Unable to set service attributes", smse);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] args = { sName, IdType.ROLE.getName() };
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_ALREADY_ASSIGNED, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "IdRepoListener: Unable to set service attributes", ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] args = { sName, IdType.ROLE.getName() };
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICE_ALREADY_ASSIGNED, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String[] getChangedIds(String name, IdType type, Map cMap) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If configMap is null, then this is a "remote" cache update
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Name should be the universal id
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Default to user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ct[0] = "id=" + name + ",ou=" + type.getName() + "," +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster defaultIdTypes = (IdType[]) idtypes.toArray(defaultIdTypes);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String n = LDAPUtils.isDN(name) ? LDAPUtils.rdnValueFromDn(name) : name;
ca104336443132651d076396c9cedeaec3ea8321sachiko String id = "id=" + LDAPUtils.escapeValue(n) + ",ou=" + itype.getName() + "," + realm;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Constants for change type recevied from the IdRepo plugins
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an object addition event type.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington public static final int OBJECT_ADDED = PersistentSearchChangeType.ADDED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an object change event type.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington public static final int OBJECT_CHANGED = PersistentSearchChangeType.MODIFIED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an object removal event type.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington public static final int OBJECT_REMOVED = PersistentSearchChangeType.REMOVED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an object renaming event type.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington public static final int OBJECT_RENAMED = PersistentSearchChangeType.RENAMED;