KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
23 import java.util.Calendar JavaDoc;
24
25 import com.sslexplorer.security.AuthenticationScheme;
26 import com.sslexplorer.security.Constants;
27 import com.sslexplorer.security.LogonControllerFactory;
28 import com.sslexplorer.security.SessionInfo;
29
30 /**
31  * Abstract implementation of a {@link Resource}. Provides setters and getters
32  * for attributes common to all resource types.
33  *
34  * @author Brett Smith <brett@3sp.com>
35  * @since 0.2.0
36  */

37
38 public abstract class AbstractResource implements Resource, Serializable JavaDoc {
39
40     // Protected instance variables
41
protected int resourceId;
42     protected String JavaDoc resourceName;
43     protected String JavaDoc resourceDescription;
44     protected Calendar JavaDoc dateCreated;
45     protected Calendar JavaDoc dateAmended;
46     protected ResourceType resourceType;
47     protected int realmID;
48     
49     /**
50      * Required for Serialization!
51      */

52     protected AbstractResource() {
53     }
54     
55     /**
56      * Constructor.
57      * @param realmID the id of the realm the resource is in.
58      * @param resourceType resource type.
59      * @param resourceId resource Id
60      * @param resourceName resource name
61      * @param resourceDescription resource description
62      * @param dateCreated date created
63      * @param dateAmended date amended
64      */

65     public AbstractResource(int realmID, ResourceType resourceType, int resourceId, String JavaDoc resourceName, String JavaDoc resourceDescription,
66                     Calendar JavaDoc dateCreated, Calendar JavaDoc dateAmended) {
67         this.resourceType = resourceType;
68         this.resourceId = resourceId;
69         this.resourceName = resourceName;
70         this.resourceDescription = resourceDescription;
71         this.dateCreated = dateCreated;
72         this.dateAmended = dateAmended;
73         this.realmID = realmID;
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see java.lang.Object#equals(java.lang.Object)
80      */

81     public boolean equals(Object JavaDoc o) {
82         return o instanceof Resource && ((Resource) o).getResourceType().equals(getResourceType())
83                         && ((Resource) o).getResourceId() == getResourceId() && ((Resource) o).getRealmID() == getRealmID();
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see com.sslexplorer.boot.policyframework.Resource#getResourceId()
90      */

91     public int getResourceId() {
92         return resourceId;
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see com.sslexplorer.boot.policyframework.Resource#getResourceType()
99      */

100     public ResourceType getResourceType() {
101         return resourceType;
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see com.sslexplorer.boot.policyframework.Resource#getResourceName()
108      */

109     public String JavaDoc getResourceName() {
110         return resourceName;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see com.sslexplorer.boot.policyframework.Resource#getResourceDisplayName()
117      */

118     public String JavaDoc getResourceDisplayName() {
119         return getResourceName();
120     }
121     
122     /*
123      * (non-Javadoc)
124      *
125      * @see com.sslexplorer.boot.policyframework.Resource#getResourceDescription()
126      */

127     public String JavaDoc getResourceDescription() {
128         return resourceDescription;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see com.sslexplorer.boot.policyframework.Resource#setResourceName(java.lang.String)
135      */

136     public void setResourceName(String JavaDoc resourceName) {
137         this.resourceName = resourceName;
138     }
139
140     /**
141      * Set this resources ID
142      *
143      * @param resourceId resource Id
144      */

145     public void setResourceId(int resourceId) {
146         this.resourceId = resourceId;
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see com.sslexplorer.boot.policyframework.Resource#setResourceDescription(java.lang.String)
153      */

154     public void setResourceDescription(String JavaDoc resourceDescription) {
155         this.resourceDescription = resourceDescription;
156     }
157
158     /**
159      * Compare this resource with another using the resource name for
160      * comparison.
161      *
162      * @param o resource to compare with
163      * @return comparison result
164      */

165     public int compareTo(Object JavaDoc o) {
166         return getResourceName().compareTo(((Resource) o).getResourceName());
167     }
168
169     /*
170      * (non-Javadoc)
171      *
172      * @see com.sslexplorer.boot.policyframework.Resource#getDateCreated()
173      */

174     public Calendar JavaDoc getDateCreated() {
175         return dateCreated;
176     }
177
178     /**
179      * Set the date this resource was created
180      *
181      * @param dateCreated date created
182      */

183     public void setDateCreated(Calendar JavaDoc dateCreated) {
184         this.dateCreated = dateCreated;
185     }
186
187     /*
188      * (non-Javadoc)
189      *
190      * @see com.sslexplorer.boot.policyframework.Resource#getDateAmended()
191      */

192     public Calendar JavaDoc getDateAmended() {
193         return dateAmended;
194     }
195
196     /*
197      * (non-Javadoc)
198      *
199      * @see com.sslexplorer.boot.policyframework.Resource#setDateAmended(java.util.Calendar)
200      */

201     public void setDateAmended(Calendar JavaDoc dateAmended) {
202         this.dateAmended = dateAmended;
203     }
204
205     /*
206      * (non-Javadoc)
207      *
208      * @see com.sslexplorer.policyframework.Resource#requiresPassword()
209      */

210     public boolean sessionPasswordRequired(SessionInfo sessionInfo) {
211         boolean hasSessionPassword = false;
212         AuthenticationScheme scheme = sessionInfo.getHttpSession() == null ? null : (AuthenticationScheme) sessionInfo.getHttpSession().getAttribute(Constants.AUTH_SESSION);
213         if (scheme != null) {
214             char[] pw = LogonControllerFactory.getInstance().getPasswordFromCredentials(scheme);
215             if (pw != null) {
216                 hasSessionPassword = true;
217             }
218         }
219
220         if (!hasSessionPassword & paramsRequirePassword())
221             return true;
222         else
223             return false;
224     }
225
226     /*
227      * (non-Javadoc)
228      *
229      * @see com.sslexplorer.policyframework.Resource#paramsRequirePassword()
230      */

231     public boolean paramsRequirePassword() {
232         return false;
233     }
234
235     /*
236      * (non-Javadoc)
237      *
238      * @see java.lang.Object#toString()
239      */

240     public String JavaDoc toString() {
241         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("Resource '");
242         buf.append(getResourceName());
243         buf.append("' [id=");
244         buf.append(getResourceId());
245         buf.append("]");
246         return buf.toString();
247     }
248     
249
250     /* (non-Javadoc)
251      * @see com.sslexplorer.policyframework.Resource#getRealmID()
252      */

253     public int getRealmID() {
254         return realmID;
255     }
256
257
258 }
259
Popular Tags