IdRemoteEventListener.java revision 7eec4dacb6610121d1e70afd31e53034525e2ae6
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: IdRemoteEventListener.java,v 1.7 2009/01/28 05:35:00 ww203982 Exp $
*
* Portions Copyrighted 2011-2016 ForgeRock AS.
*/
/**
* The <code>IdRemoteEventListener</code> handles the events generated from the
* server. If notification URL is provided, the class registers the URL with the
* Server and waits for notifications. Else it polls the server at configurable
* time periods to get updates from the server.
*/
public class IdRemoteEventListener {
private static SOAPClient client;
private static IdRemoteEventListener instance;
private static final String NOTIFICATION_PROPERTY =
"com.sun.identity.idm.remote.notification.enabled";
private static final String CACHE_POLLING_TIME_PROPERTY =
"com.iplanet.am.sdk.remote.pollingTime";
private static final int DEFAULT_CACHE_POLLING_TIME = 1;
public synchronized static IdRemoteEventListener getInstance() {
instance = new IdRemoteEventListener();
}
return instance;
}
/**
* Constructor for <class>EventListener</class>. Should be instantiated
* once by <code>RemoteServicesImpl</code>
*
*/
private IdRemoteEventListener() {
// Construct the SOAP Client
}
// Check if notification is enabled
// Default the notification enabled to true if the property
// is not found for backward compatibility.
NOTIFICATION_PROPERTY, "true");
// Run in notifications mode
// Check if notification URL is provided
try {
// Throws exception if NotificationURL is null
// Register for IdRepo Service
}
if (DEBUG.messageEnabled()) {
}
} else {
if (DEBUG.messageEnabled()) {
}
}
public void shutdown() {
try {
if (DEBUG.messageEnabled()) {
+ remoteId);
}
} else {
if (DEBUG.messageEnabled()) {
"deRegisterNotificationURL_idrepo due to null ID");
}
}
} catch (Exception e) {
"deRegisterNotificationURL_idrepo with ID " + remoteId, e);
}
}
});
// Register with PLLClient for notification
new IdRepoEventNotificationHandler());
if (DEBUG.messageEnabled()) {
+ "mechanism for cache updates: "
}
} catch (Exception e) {
// Use polling mechanism to update caches
if (DEBUG.warningEnabled()) {
+ "notification via URL failed for " + url
+ " Exception: " + e.getMessage()
+ "\nUsing polling mechanism for updates");
}
// Start Polling thread only if enabled.
}
} else {
// Start Polling thread only if enabled.
}
}
private int getCachePollingInterval() {
// If the property is not configured, default it to 1 minute.
if (cachePollingTimeStr != null) {
try {
} catch (NumberFormatException nfe) {
+ "Invalid Polling Time: " + cachePollingTimeStr +
" Defaulting to " + DEFAULT_CACHE_POLLING_TIME +
" minute");
}
}
return cachePollingInterval;
}
private static void startPollingThreadIfEnabled(int cachePollingInterval) {
if (cachePollingInterval > 0) {
if (DEBUG.messageEnabled()) {
"Starting the polling thread..");
}
// Run in polling mode
} else {
if (DEBUG.warningEnabled()) {
CACHE_POLLING_TIME_PROPERTY + "=" +
}
}
}
/**
* 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
*
*/
if (DEBUG.messageEnabled()) {
+ "Received notification.");
}
// Construct the XML document
try {
// The second argument is set to false so that the xml escaped
// chars done by server code/IdRepoJAXRPCObjectImpl will not be
// unescaped.
false);
if (DEBUG.warningEnabled()) {
+ "Invalid event: " + attrs);
}
return;
} else if (DEBUG.messageEnabled()) {
+ "Decoded Event: " + attrs);
}
// Parse to get the entity name and the method
if (DEBUG.warningEnabled()) {
+ "Invalid universalID or method: " + entityName
+ " method");
}
return;
}
// Construct IdRepoListener and set the realm
} else {
}
if (DEBUG.messageEnabled()) {
}
// Send the notification change
} else {
// Invalid method name
}
} catch (Exception e) {
if (DEBUG.warningEnabled()) {
+ "Unable to send notification: " + nItem, e);
}
}
}
// Debug the message and throw an exception
}
}
return (answer);
}
// throw an exception
throw (new Exception("IdRemoteEventListener::sendNotification: "
+ "invalid event type: " + eventSet));
}
}
static class NotificationRunnable extends GeneralTaskRunnable {
private int pollingTime;
private long runPeriod;
NotificationRunnable(int interval) {
}
return false;
}
return false;
}
public boolean isEmpty() {
return true;
}
public long getRunPeriod() {
return runPeriod;
}
public void run() {
return;
}
try {
if (DEBUG.messageEnabled()) {
+ "retrieved idrepo changes: " + mods);
}
}
if (DEBUG.warningEnabled()) {
"NotificationRunnable:run Exception", ex);
}
}
}
}
static class IdRepoEventNotificationHandler implements NotificationHandler {
// Empty constructor
}
if (DEBUG.messageEnabled()) {
+ "IdRepoEventNotificationHandler: "
+ " received notification: " + content);
}
// Send notification
}
}
}
// Static varaibles
}