* @see com.adito.policyframework.PolicyDatabase#attachResourceToPolicyList(com.adito.policyframework.Resource, com.adito.boot.PropertyList, com.adito.security.SessionInfo)
*/
public void attachResourceToPolicyList(Resource resource, PropertyList selectedPolicies, SessionInfo session) throws Exception {
List l = getPoliciesAttachedToResource(resource, session.getUser().getRealm());
for (Iterator i = l.iterator(); i.hasNext();) {
Policy p = (Policy) i.next();
if(!selectedPolicies.contains(String.valueOf(p.getResourceId()))) {
if (log.isDebugEnabled())
log.debug("Detaching policy " + p.getResourceName() + " (" + p.getResourceId() + ") to resource "
+ resource.getResourceName() + "(id=" + resource.getResourceId() + ", type="
+ resource.getResourceType() + ")");
try {
detachResourceFromPolicy(resource, p, session.getUser().getRealm());
CoreServlet.getServlet().fireCoreEvent(new ResourceDetachedFromPolicyEvent(this, resource, p, session, CoreEvent.STATE_SUCCESSFUL));
}
catch(Exception e) {
CoreServlet.getServlet().fireCoreEvent(new ResourceDetachedFromPolicyEvent(this, resource, p, session, CoreEvent.STATE_UNSUCCESSFUL));
throw e;
}
}
}
int idx = 0;
for (Iterator i = selectedPolicies.iterator(); i.hasNext(); ) {
String pn = (String)i.next();
Policy p = getPolicy(Integer.parseInt(pn));
if (!l.contains(p)) {
if (log.isDebugEnabled())
log.debug("Attaching policy " + p.getResourceName() + " (" + p.getResourceId() + ") to resource "
+ resource.getResourceName() + "(id=" + resource.getResourceId() + ", type="
+ resource.getResourceType() + ")");
try {
attachResourceToPolicy(resource, p, idx++, session.getUser().getRealm());
CoreServlet.getServlet().fireCoreEvent(new ResourceAttachedToPolicyEvent(this, resource, p, session, CoreEvent.STATE_SUCCESSFUL));