use of com.sun.identity.policy.remote.PolicyListenerRequest in project OpenAM by OpenRock.
the class ResourceResultCache method addRemotePolicyListener.
/**
* Registers a listener with policy service to recieve
* notifications on policy changes
* @param appToken session token identifying the client
* @param serviceName service name
* @param notificationURL end point on the client that listens for
* notifications
*
* @param reRegister flag indicating whether to register listener
* even if it was already registered. <code>true</code> indicates
* to register listener again even if it was previously registered
*/
boolean addRemotePolicyListener(SSOToken appToken, String serviceName, String notificationURL, boolean reRegister) {
boolean status = false;
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL);
}
if (remotePolicyListeners.contains(serviceName) && !reRegister) {
if (debug.messageEnabled()) {
debug.message("ResourceResultCache.addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL + ":is already registered");
}
return status;
}
//else do the following
URL policyServiceURL = null;
if (appToken != null) {
try {
policyServiceURL = getPolicyServiceURL(appToken);
} catch (PolicyException pe) {
debug.error("ResourceResultCache.addRemotePolicyListener():" + "Can not add policy listner", pe);
}
}
if ((appToken != null) && (policyServiceURL != null)) {
PolicyListenerRequest listenerReq = new PolicyListenerRequest();
listenerReq.setServiceName(serviceName);
listenerReq.setNotificationURL(notificationURL);
PolicyRequest policyReq = new PolicyRequest();
policyReq.setAppSSOToken(appToken.getTokenID().toString());
policyReq.setMethodID(PolicyRequest.POLICY_REQUEST_ADD_POLICY_LISTENER);
policyReq.setPolicyListenerRequest(listenerReq);
try {
PolicyService ps = sendPLLRequest(policyServiceURL, policyReq);
if (ps != null) {
if (debug.messageEnabled()) {
debug.message("ResourceResultCache." + "addRemotePolicyListener():" + "result=" + ps.toXMLString());
}
PolicyResponse psres = ps.getPolicyResponse();
if (psres.getMethodID() == PolicyResponse.POLICY_ADD_LISTENER_RESPONSE) {
status = true;
remotePolicyListeners.add(serviceName);
if (debug.messageEnabled()) {
debug.message("ResourceResultCache." + "addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL + ":policyServiceURL=" + policyServiceURL + ":add succeeded");
}
}
} else {
debug.error("ResourceResultCache.addRemotePolicyListener():" + " no result");
}
} catch (Exception e) {
debug.error("ResourceResultCache.addRemotePolicyListener():", e);
}
}
return status;
}
Aggregations