KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)file OwnerImpl.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.9
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.io.Serializable JavaDoc;
19
20 import java.security.Principal JavaDoc;
21 import java.security.acl.Owner JavaDoc;
22 import java.security.acl.LastOwnerException JavaDoc;
23 import java.security.acl.NotOwnerException JavaDoc;
24
25
26 /**
27  * Owner of Access Control Lists (ACLs).
28  * The initial owner Principal should be specified as an
29  * argument to the constructor of the class AclImpl.
30  *
31  * @see java.security.acl.Owner
32  * @version 4.9 12/19/03
33  * @author Sun Microsystems, Inc
34  */

35
36 class OwnerImpl implements Owner JavaDoc, Serializable JavaDoc {
37   private Vector JavaDoc ownerList = null;
38   
39   /**
40    * Constructs an empty list of owner.
41    */

42   public OwnerImpl (){
43     ownerList = new Vector JavaDoc();
44   }
45   
46   /**
47    * Constructs a list of owner with the specified principal as first element.
48    *
49    * @param owner the principal added to the owner list.
50    */

51   public OwnerImpl (PrincipalImpl owner){
52     ownerList = new Vector JavaDoc();
53     ownerList.addElement(owner);
54   }
55   
56   /**
57    * Adds an owner. Only owners can modify ACL contents. The caller principal
58    * must be an owner of the ACL in order to invoke this method. That is, only
59    * an owner can add another owner. The initial owner is configured at
60    * ACL construction time.
61    *
62    * @param caller the principal invoking this method.
63    * It must be an owner of the ACL.
64    * @param owner the owner that should be added to the list of owners.
65    * @return true if successful, false if owner is already an owner.
66    * @exception NotOwnerException if the caller principal is not an owner
67    * of the ACL.
68    */

69   public boolean addOwner(Principal JavaDoc caller, Principal JavaDoc owner)
70     throws NotOwnerException JavaDoc {
71     if (!ownerList.contains(caller))
72       throw new NotOwnerException JavaDoc();
73
74     if (ownerList.contains(owner)) {
75       return false;
76     } else {
77       ownerList.addElement(owner);
78       return true;
79     }
80   }
81   
82   /**
83    * Deletes an owner. If this is the last owner in the ACL, an exception is raised.
84    *<P>
85    * The caller principal must be an owner of the ACL in order to invoke this method.
86    *
87    * @param caller the principal invoking this method. It must be an owner
88    * of the ACL.
89    * @param owner the owner to be removed from the list of owners.
90    * @return true if successful, false if owner is already an owner.
91    * @exception NotOwnerException if the caller principal is not an owner
92    * of the ACL.
93    * @exception LastOwnerException if there is only one owner left, so that
94    * deleteOwner would leave the ACL owner-less.
95    */

96   public boolean deleteOwner(Principal JavaDoc caller, Principal JavaDoc owner)
97         throws NotOwnerException JavaDoc,LastOwnerException JavaDoc {
98
99     if (!ownerList.contains(caller))
100       throw new NotOwnerException JavaDoc();
101     
102     if (!ownerList.contains(owner)){
103       return false;
104     } else {
105       if (ownerList.size() == 1)
106         throw new LastOwnerException JavaDoc();
107       
108       ownerList.removeElement(owner);
109       return true;
110     }
111   }
112   
113   /**
114    * Returns true if the given principal is an owner of the ACL.
115    *
116    * @param owner the principal to be checked to determine whether or
117    * not it is an owner.
118    * @return true if the given principal is an owner of the ACL.
119    */

120   public boolean isOwner(Principal JavaDoc owner){
121     return ownerList.contains(owner);
122   }
123 }
124
Popular Tags