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;
}
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);
}
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>
* <!-- EventNotification element specifes the change notification
* which contains AttributeValuePairs. The attributes defined
* are "method", "entityName", "
* eventType" and "attrNames". -->
* <!ELEMENT EventNotification ( AttributeValuePairs )* >
*
* <!-- AttributeValuePair element contains attribute name and
* values -->
* <!ELEMENT AttributeValuPair ( Attribute, Value*) >
*
* <!-- Attribute contains the attribute names, and the allowed
* names are "method", "entityName",
* "eventType" and "attrNames" -->
* <!ELEMENT Attribute EMPTY>
* <!ATTRLIST Attribute
* name ( method | entityName | eventType | attrNames )
* "method"
* >
*
* <!-- Value element specifies the values for the attributes
* --> <!ELEMENT Value (#PCDATA) >
* </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);
}
}
}
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()))));
}
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);
}
}
}
}
Aggregations