KickJava   Java API By Example, From Geeks To Geeks.

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


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 EJB <i><code>isCallerInRole (String reference)</code></i>
32  * permissions. An EJBRoleRefPermission is a named permission and has actions.
33  * <P>
34  * The name of an EJBRoleRefPermission contains the value of the
35  * ejb-name element in the application's deployment descriptor
36  * that identifies the EJB in whose context the permission is
37  * being evalutated.
38  * <P>
39  * the actions of an EJBRoleRefPermission identifies the role reference to
40  * which the permission applies. An EJBRoleRefPermission 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
53 public final class EJBRoleRefPermission extends Permission
54 implements java.io.Serializable JavaDoc
55 {
56
57      private final String JavaDoc actions;
58
59      private transient int hashCodeValue = 0;
60
61      private static final long serialVersionUID = 1L;
62
63    /**
64     * The serialized fields of this permission are defined below. Whether
65     * or not the serialized fields correspond to actual (private) fields
66     * is an implementation decision.
67     * @serialField actions String
68     * the canonicalized actions string (as returned by getActions).
69     */

70     private static final ObjectStreamField JavaDoc[] serialPersistentFields = {
71         new ObjectStreamField JavaDoc("actions", java.lang.String JavaDoc.class)
72     };
73
74     /**
75      * Creates a new EJBRoleRefPermission with the specified name and actions.
76      * @param name the ejb-name that identifies the EJB
77      * 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 EJB 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 EJBRoleRefPermission(String JavaDoc name, String JavaDoc actions)
87      {
88     super(name);
89         this.actions = actions;
90      }
91
92     /**
93      * Checks two EJBRoleRefPermission objects for equality.
94      * EJBRoleRefPermission 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      * @param o the EJBRoleRefPermission object being tested for equality
101      * with this EJBRoleRefPermission.
102      * <P>
103      * @return true if the argument EJBRoleRefPermission object is equivalent
104      * to this EJBRoleRefPermission.
105      */

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

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

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

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

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

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

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