use of com.sun.identity.policy.interfaces.PolicyListener in project OpenAM by OpenRock.
the class PolicyCache method firePolicyChanged.
/**
* Creates a policyEvent with the changed resource names
* and then invokes all the registered PolicyListeners
* to notify about the event.
*/
private void firePolicyChanged(String serviceName, Set affectedResourceNames, int changeType) {
if (DEBUG.messageEnabled()) {
StringBuilder sb = new StringBuilder(255);
sb.append("at firePolicyChanged(serrviceName,affectedResourceNames):");
sb.append(serviceName).append(":");
sb.append(affectedResourceNames.toString());
DEBUG.message(sb.toString());
}
PolicyEvent policyEvent = new PolicyEvent();
policyEvent.setResourceNames(affectedResourceNames);
policyEvent.setChangeType(changeType);
Set pListeners = (Set) policyListenersMap.get(serviceName);
if (pListeners != null) {
Iterator listeners = pListeners.iterator();
while (listeners.hasNext()) {
PolicyListener policyListener = (PolicyListener) listeners.next();
try {
policyListener.policyChanged(policyEvent);
} catch (Exception e) {
DEBUG.error("policy change not handled properly", e);
}
}
}
//notify policy evaluator so it can clean up cached resource names
PolicyEvaluator.policyChanged(serviceName, policyEvent);
}
use of com.sun.identity.policy.interfaces.PolicyListener in project OpenAM by OpenRock.
the class PolicyCache method firePrivilegeChanged.
/**
* Creates a policyEvent with the changed resource names
* and then invokes all the registered PolicyListeners
* to notify about the event. This is triggered when
* entitlement privilege is added, removed or modified.
*/
public void firePrivilegeChanged(String serviceName, Set affectedResourceNames, int changeType) {
if (DEBUG.messageEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("at firePrivilegeChanged(serrviceName,affectedResourceNames):");
sb.append(serviceName).append(":");
sb.append(affectedResourceNames.toString());
DEBUG.message(sb.toString());
}
PolicyEvent policyEvent = new PolicyEvent();
policyEvent.setResourceNames(affectedResourceNames);
policyEvent.setChangeType(changeType);
Set pListeners = (Set) policyListenersMap.get(serviceName);
if (pListeners != null) {
Iterator listeners = pListeners.iterator();
while (listeners.hasNext()) {
PolicyListener policyListener = (PolicyListener) listeners.next();
try {
policyListener.policyChanged(policyEvent);
} catch (Exception e) {
DEBUG.error("policy change not handled properly", e);
}
}
}
//notify policy evaluator so it can clean up cached resource names
PolicyEvaluator.policyChanged(serviceName, policyEvent);
}
use of com.sun.identity.policy.interfaces.PolicyListener in project OpenAM by OpenRock.
the class PolicyRequestHandler method removePolicyListener.
/*
* Remove a policy change listener from the policy framework.
*/
private boolean removePolicyListener(SSOToken appToken, RemoveListenerRequest removeListenerReq, Map<String, Set<String>> appAttributes) {
if (removeListenerReq == null) {
debug.error("PolicyRequestHandler.removePolicyListener: " + "invalid remove policy listener request received");
return false;
}
String serviceTypeName = removeListenerReq.getServiceName();
String notiURL = removeListenerReq.getNotificationURL();
if (!listenerRegistry.containsKey(notiURL)) {
if (debug.messageEnabled()) {
debug.message("PolicyRequestHandler.removePolicyListener: " + "policy listener to be removed for service " + serviceTypeName + " has not been registered yet; the notification URL is " + notiURL);
}
return true;
}
PolicyListener policyListener = (PolicyListener) listenerRegistry.get(notiURL);
if (policyListener == null) {
listenerRegistry.remove(notiURL);
return true;
}
PolicyEvaluator policyEvaluator = null;
try {
// Get an instance of the policy evaluator
policyEvaluator = getPolicyEvaluator(appToken, serviceTypeName, appAttributes);
if (policyEvaluator != null) {
// remove the policy listener from the policy framework
policyEvaluator.removePolicyListener(policyListener);
listenerRegistry.remove(notiURL);
if (debug.messageEnabled()) {
debug.message("PolicyRequestHandler.removePolicyListener: " + "policy listener for service " + serviceTypeName + " removed");
}
}
} catch (PolicyException e) {
debug.error("PolicyRequestHandler.removePolicyListener: " + "failed to remove policy change listener", e);
return false;
}
return true;
}
Aggregations