1 19 20 package com.sslexplorer.policyframework; 21 22 import com.sslexplorer.boot.Util; 23 import com.sslexplorer.core.CoreAttributeConstants; 24 import com.sslexplorer.core.CoreEvent; 25 import com.sslexplorer.security.SessionInfo; 26 27 34 public class ResourceAccessEvent extends CoreEvent { 35 36 private Policy policy; 37 private Resource resource; 38 39 48 public ResourceAccessEvent(Object source, int id, SessionInfo session, Throwable exception) { 49 super(source, id, exception, session, STATE_UNSUCCESSFUL); 50 addAttribute(CoreAttributeConstants.EVENT_ATTR_EXCEPTION_MESSAGE, Util.getExceptionMessageChain(exception)); 51 } 52 53 64 public ResourceAccessEvent(Object source, int id, Resource resource, Policy policy, SessionInfo session, Throwable exception) { 65 this(source, id, resource, policy, session, STATE_UNSUCCESSFUL); 66 addAttribute(CoreAttributeConstants.EVENT_ATTR_EXCEPTION_MESSAGE, Util.getExceptionMessageChain(exception)); 67 } 68 69 79 public ResourceAccessEvent(Object source, int id, Resource resource, Policy policy, SessionInfo session, int state) { 80 super(source, id, resource, session, state); 81 this.resource = resource; 82 this.policy = policy; 83 if (state == CoreEvent.STATE_UNSUCCESSFUL || (state == CoreEvent.STATE_SUCCESSFUL && resource != null)) { 84 if (resource != null) { 85 addAttribute(CoreAttributeConstants.EVENT_ATTR_RESOURCE_NAME, resource.getResourceName()); 86 if (resource instanceof OwnedResource) { 87 OwnedResource or = (OwnedResource) resource; 88 if (or.getOwnerUsername() != null) { 89 addAttribute(CoreAttributeConstants.EVENT_ATTR_RESOURCE_OWNER, or.getOwnerUsername()); 90 } 91 92 } 93 } 94 } else { 95 throw new IllegalArgumentException ("Must provide a non-null resource if the event was successful."); 96 } 97 } 98 99 105 public Policy getPolicy() { 106 return policy; 107 } 108 109 114 public Resource getResource() { 115 return resource; 116 } 117 118 } 119 | Popular Tags |