KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > jacc > WebRoleRefPermission


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package javax.security.jacc;
25
26 import java.security.*;
27 import java.io.IOException JavaDoc;
28 import java.io.ObjectStreamField JavaDoc;
29
30 /**
31  * Class for Servlet <i><code>isUserInRole (String reference)</code></i>
32  * permissions. A WebRoleRefPermission is a named permission and has actions.
33  * <P>
34  * The name of an WebRoleRefPermission (also referred to as the target name)
35  * identifies a Web resource by the servlet name (in the deployment
36  * descriptor corresponding to the component from which the call to
37  * <i><code>isUserInRole (String reference)</code></i> is being made.
38  * <P>
39  * The actions of an WebRoleRefPermission identifies the role reference to
40  * which the permission applies. A WebRoleRefPermission is checked to
41  * determine if the subject is a member of the role identified by the
42  * reference.
43  * <P>
44  * Implementations of this class MAY implement newPermissionCollection or
45  * inherit its implementation from the super class.
46  *
47  * @see java.security.Permission
48  *
49  * @author Ron Monzillo
50  * @author Gary Ellison
51  */

52 public final class WebRoleRefPermission extends Permission
53 implements java.io.Serializable JavaDoc
54 {
55
56      private final String JavaDoc actions;
57
58      private transient int hashCodeValue = 0;
59
60      private static final long serialVersionUID = 1L;
61
62    /**
63     * The serialized fields of this permission are defined below. Whether
64     * or not the serialized fields correspond to actual (private) fields
65     * is an implementation decision.
66     * @serialField actions String
67     * the canonicalized actions string (as returned by getActions).
68     */

69     private static final ObjectStreamField JavaDoc[] serialPersistentFields = {
70         new ObjectStreamField JavaDoc("actions", java.lang.String JavaDoc.class)
71     };
72
73     /**
74      * Creates a new WebRoleRefPermission with the specified name and actions.
75      * <P>
76      * @param name the servlet-name that identifies the application
77      * specific web resource in whose context the role references are
78      * to be evaluated.
79      * <P>
80      * @param actions identifies the role reference to which the permission
81      * pertains. The role reference is scoped to the Web resource identified
82      * in the name parameter. The value of the role reference must not be
83      * <code>null</code> or the empty string.
84      */

85
86      public WebRoleRefPermission(String JavaDoc name, String JavaDoc actions)
87      {
88      super(name);
89      this.actions = actions;
90      }
91
92     /**
93      * Checks two WebRoleRefPermission objects for equality.
94      * WebRoleRefPermission objects are equivalent if they have case
95      * equivalent name and actions values.
96      * <P>
97      * Two Permission objects, P1 and P2, are equivalent if and only if
98      * P1.implies(P2) && P2.implies(P1).
99      * <P>
100      * The name and actions comparisons described above are case sensitive.
101      * <P>
102      * @param o the WebRoleRefPermission object being tested for equality
103      * with this WebRoleRefPermission.
104      * @return true if the argument WebRoleRefPermission object is equivalent
105      * to this WebRoleRefPermission.
106      */

107
108     public boolean equals(Object JavaDoc o)
109     {
110     if (o == null ||
111         ! (o instanceof WebRoleRefPermission JavaDoc)) return false;
112
113     WebRoleRefPermission JavaDoc that = (WebRoleRefPermission JavaDoc) o;
114
115     if (!this.getName().equals(that.getName())) return false;
116         
117     return this.actions.equals(that.actions);
118     }
119
120     /**
121      * Returns a canonical String representation of the actions of this
122      * WebRoleRefPermission.
123      * <P>
124      * @return a String containing the canonicalized actions of this
125      * WebRoleRefPermission.
126      */

127
128     public String JavaDoc getActions()
129     {
130     return this.actions;
131     }
132
133     /**
134      * Returns the hash code value for this WebRoleRefPermission. The
135      * properties of the returned hash code must be as follows: <p>
136      * <ul>
137      * <li> During the lifetime of a Java application, the hashCode method
138      * must return the same integer value, every time it is called on a
139      * WebRoleRefPermission object. The value returned by hashCode for a
140      * particular WebRoleRefPermission need not remain consistent from
141      * one execution of an application to another.
142      * <li> If two WebRoleRefPermission objects are equal according to the
143      * equals method, then calling the hashCode method on each of the two
144      * Permission objects must produce the same integer result (within an
145      * application).
146      * </ul>
147      * <P>
148      * @return the integer hash code value for this object.
149      */

150     public int hashCode()
151     {
152
153     if (this.hashCodeValue == 0) {
154         
155         String JavaDoc hashInput = new String JavaDoc(this.getName() + " " + this.actions);
156     
157         this.hashCodeValue = hashInput.hashCode();
158     }
159
160     return this.hashCodeValue;
161     }
162
163     /**
164      * Determines if the argument Permission is "implied by" this
165      * WebRoleRefPermission. For this to be the case, <p>
166      * <ul>
167      * <li> The argument must be an instanceof WebRoleRefPermission
168      * <li> with name equivalent to this WebRoleRefPermission, and
169      * <li> with role reference equivalent to this WebRoleRefPermission
170      * (as defined in their actions).
171      * </ul>
172      * <P>
173      * The comparisons described above are case sensitive.
174      * <P>
175      * @param permission "this" WebRoleRefPermission is checked to see if
176      * it implies the argument permission.
177      * <P>
178      * @return true if the specified permission is implied by this object,
179      * false if not.
180      */

181
182     public boolean implies(Permission permission)
183     {
184     return this.equals(permission);
185     }
186
187     // ----------------- Private Methods ---------------------
188

189    /**
190      * readObject reads the serialized fields from the
191      * input stream and uses them to restore the permission.
192      * This method need not be implemented if establishing the
193      * values of the serialized fields (as is done by defaultReadObject)
194      * is sufficient to initialize the permission.
195      */

196     private synchronized void readObject(java.io.ObjectInputStream JavaDoc s)
197          throws IOException JavaDoc,ClassNotFoundException JavaDoc
198     {
199     s.defaultReadObject();
200     }
201
202     /**
203      * writeObject is used to establish the values of the serialized fields
204      * before they are written to the output stream and need not be
205      * implemented if the values of the serialized fields are always
206      * available and up to date. The serialized fields are written to
207      * the output stream in the same form as they would be written
208      * by defaultWriteObject.
209      */

210     private synchronized void writeObject(java.io.ObjectOutputStream JavaDoc s)
211          throws IOException JavaDoc
212     {
213     s.defaultWriteObject();
214     }
215
216 }
217
218
219
220
221
222
223
Popular Tags