KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > ResourceAccessEvent


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

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 /**
28  * Extension of a {@link com.sslexplorer.core.CoreEvent} that should be used
29  * when a {@link Resource} is accessed in some way. For example, such an event
30  * should be fired when the user launches a <i>Web Forward</i>
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class ResourceAccessEvent extends CoreEvent {
35
36     private Policy policy;
37     private Resource resource;
38
39     /**
40      * Constructor for {@link CoreEvent#STATE_UNSUCCESSFUL} that also takes the
41      * message from an exception and adds it as an attribute
42      *
43      * @param source source of event
44      * @param id event ID
45      * @param session session that fired the event
46      * @param exception exception
47      */

48     public ResourceAccessEvent(Object JavaDoc source, int id, SessionInfo session, Throwable JavaDoc exception) {
49         super(source, id, exception, session, STATE_UNSUCCESSFUL);
50         addAttribute(CoreAttributeConstants.EVENT_ATTR_EXCEPTION_MESSAGE, Util.getExceptionMessageChain(exception));
51     }
52
53     /**
54      * Constructor for {@link CoreEvent#STATE_UNSUCCESSFUL} that also takes the
55      * message from an exception and adds it as an attribute
56      *
57      * @param source source of event
58      * @param id event ID
59      * @param resource resource accessed
60      * @param policy the policy resource access was attempted under
61      * @param session session that fired the event
62      * @param exception exception
63      */

64     public ResourceAccessEvent(Object JavaDoc source, int id, Resource resource, Policy policy, SessionInfo session, Throwable JavaDoc exception) {
65         this(source, id, resource, policy, session, STATE_UNSUCCESSFUL);
66         addAttribute(CoreAttributeConstants.EVENT_ATTR_EXCEPTION_MESSAGE, Util.getExceptionMessageChain(exception));
67     }
68
69     /**
70      * Constructor
71      *
72      * @param source source of event
73      * @param id event ID
74      * @param resource resource accessed
75      * @param policy the policy resource access was attempted under
76      * @param session session that fired the event
77      * @param state event state
78      */

79     public ResourceAccessEvent(Object JavaDoc 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 JavaDoc("Must provide a non-null resource if the event was successful.");
96         }
97     }
98
99     /**
100      * Get the policy resource access was attempted under. This will only be
101      * available on successful events
102      *
103      * @return policy
104      */

105     public Policy getPolicy() {
106         return policy;
107     }
108
109     /**
110      * Get the resource. This will only be available on successful events
111      *
112      * @return resource
113      */

114     public Resource getResource() {
115         return resource;
116     }
117
118 }
119
Popular Tags