KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > IPAcl > AclEntryImpl


1 /*
2  * @(#)file AclEntryImpl.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.11
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11
12
13 package com.sun.jmx.snmp.IPAcl;
14
15
16
17 import java.util.Vector JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.io.Serializable JavaDoc;
20 import java.net.UnknownHostException JavaDoc;
21
22 import java.security.Principal JavaDoc;
23 import java.security.acl.AclEntry JavaDoc;
24
25
26 /**
27  * Represent one entry in the Access Control List (ACL).
28  * This ACL entry object contains a permission associated with a particular principal.
29  * (A principal represents an entity such as an individual machine or a group).
30  *
31  * @see java.security.acl.AclEntry
32  * @version 4.11 12/19/03
33  * @author Sun Microsystems, Inc
34  */

35
36 class AclEntryImpl implements AclEntry JavaDoc, Serializable JavaDoc {
37   
38   private AclEntryImpl (AclEntryImpl i) throws UnknownHostException JavaDoc {
39     setPrincipal(i.getPrincipal());
40     permList = new Vector JavaDoc();
41     commList = new Vector JavaDoc();
42     
43     for (Enumeration JavaDoc en = i.communities(); en.hasMoreElements();){
44       addCommunity((String JavaDoc)en.nextElement());
45     }
46     
47     for (Enumeration JavaDoc en = i.permissions(); en.hasMoreElements();){
48       addPermission((java.security.acl.Permission JavaDoc)en.nextElement());
49     }
50     if (i.isNegative()) setNegativePermissions();
51   }
52   
53   /**
54    * Contructs an empty ACL entry.
55    */

56   public AclEntryImpl (){
57     princ = null;
58     permList = new Vector JavaDoc();
59     commList = new Vector JavaDoc();
60   }
61   
62   /**
63    * Constructs an ACL entry with a specified principal.
64    *
65    * @param p the principal to be set for this entry.
66    */

67   public AclEntryImpl (Principal JavaDoc p) throws UnknownHostException JavaDoc {
68     princ = p;
69     permList = new Vector JavaDoc();
70     commList = new Vector JavaDoc();
71   }
72   
73   /**
74    * Clones this ACL entry.
75    *
76    * @return a clone of this ACL entry.
77    */

78   public Object JavaDoc clone() {
79     AclEntryImpl i;
80     try {
81       i = new AclEntryImpl(this);
82     }catch (UnknownHostException JavaDoc e) {
83       i = null;
84     }
85     return (Object JavaDoc) i;
86   }
87   
88   /**
89    * Returns true if this is a negative ACL entry (one denying the associated principal
90    * the set of permissions in the entry), false otherwise.
91    *
92    * @return true if this is a negative ACL entry, false if it's not.
93    */

94   public boolean isNegative(){
95     return neg;
96   }
97   
98   /**
99    * Adds the specified permission to this ACL entry. Note: An entry can
100    * have multiple permissions.
101    *
102    * @param perm the permission to be associated with the principal in this
103    * entry
104    * @return true if the permission is removed, false if the permission was
105    * not part of this entry's permission set.
106    *
107    */

108   public boolean addPermission(java.security.acl.Permission JavaDoc perm){
109     if (permList.contains(perm)) return false;
110     permList.addElement(perm);
111     return true;
112   }
113   
114   /**
115    * Removes the specified permission from this ACL entry.
116    *
117    * @param perm the permission to be removed from this entry.
118    * @return true if the permission is removed, false if the permission
119    * was not part of this entry's permission set.
120    */

121   public boolean removePermission(java.security.acl.Permission JavaDoc perm){
122     if (!permList.contains(perm)) return false;
123     permList.removeElement(perm);
124     return true;
125   }
126   
127   /**
128    * Checks if the specified permission is part of the permission set in
129    * this entry.
130    *
131    * @param perm the permission to be checked for.
132    * @return true if the permission is part of the permission set in this
133    * entry, false otherwise.
134    */

135   
136   public boolean checkPermission(java.security.acl.Permission JavaDoc perm){
137     return (permList.contains(perm));
138   }
139   
140   /**
141    * Returns an enumeration of the permissions in this ACL entry.
142    *
143    * @return an enumeration of the permissions in this ACL entry.
144    */

145   public Enumeration JavaDoc permissions(){
146     return permList.elements();
147   }
148   
149   /**
150    * Sets this ACL entry to be a negative one. That is, the associated principal
151    * (e.g., a user or a group) will be denied the permission set specified in the
152    * entry. Note: ACL entries are by default positive. An entry becomes a negative
153    * entry only if this setNegativePermissions method is called on it.
154    *
155    * Not Implemented.
156    */

157   public void setNegativePermissions(){
158     neg = true;
159   }
160   
161   /**
162    * Returns the principal for which permissions are granted or denied by this ACL
163    * entry. Returns null if there is no principal set for this entry yet.
164    *
165    * @return the principal associated with this entry.
166    */

167   public Principal JavaDoc getPrincipal(){
168     return princ;
169   }
170   
171   /**
172    * Specifies the principal for which permissions are granted or denied by
173    * this ACL entry. If a principal was already set for this ACL entry,
174    * false is returned, otherwise true is returned.
175    *
176    * @param p the principal to be set for this entry.
177    * @return true if the principal is set, false if there was already a
178    * principal set for this entry.
179    */

180   public boolean setPrincipal(Principal JavaDoc p) {
181     if (princ != null )
182       return false;
183     princ = p;
184     return true;
185   }
186   
187   /**
188    * Returns a string representation of the contents of this ACL entry.
189    *
190    * @return a string representation of the contents.
191    */

192   public String JavaDoc toString(){
193     return "AclEntry:"+princ.toString();
194   }
195   
196   /**
197    * Returns an enumeration of the communities in this ACL entry.
198    *
199    * @return an enumeration of the communities in this ACL entry.
200    */

201   public Enumeration JavaDoc communities(){
202     return commList.elements();
203   }
204   
205   /**
206    * Adds the specified community to this ACL entry. Note: An entry can
207    * have multiple communities.
208    *
209    * @param comm the community to be associated with the principal
210    * in this entry.
211    * @return true if the community was added, false if the community was
212    * already part of this entry's community set.
213    */

214   public boolean addCommunity(String JavaDoc comm){
215     if (commList.contains(comm)) return false;
216     commList.addElement(comm);
217     return true;
218   }
219   
220   /**
221    * Removes the specified community from this ACL entry.
222    *
223    * @param comm the community to be removed from this entry.
224    * @return true if the community is removed, false if the community was
225    * not part of this entry's community set.
226    */

227   public boolean removeCommunity(String JavaDoc comm){
228     if (!commList.contains(comm)) return false;
229     commList.removeElement(comm);
230     return true;
231   }
232   
233   /**
234    * Checks if the specified community is part of the community set in this
235    * entry.
236    *
237    * @param comm the community to be checked for.
238    * @return true if the community is part of the community set in this
239    * entry, false otherwise.
240    */

241   public boolean checkCommunity(String JavaDoc comm){
242     return (commList.contains(comm));
243   }
244
245   private Principal JavaDoc princ = null;
246   private boolean neg = false;
247   private Vector JavaDoc permList = null;
248   private Vector JavaDoc commList = null;
249 }
250
251
252
253
254
255
256
257
258
259
Popular Tags