1 11 12 13 package com.sun.jmx.snmp.IPAcl; 14 15 16 17 import java.security.Principal ; 18 import java.security.acl.Acl ; 19 import java.security.acl.AclEntry ; 20 import java.security.acl.NotOwnerException ; 21 22 import java.io.Serializable ; 23 import java.util.Vector ; 24 import java.util.Enumeration ; 25 26 27 41 42 class AclImpl extends OwnerImpl implements Acl , Serializable { 43 private Vector entryList = null; 44 private String aclName = null; 45 46 52 public AclImpl (PrincipalImpl owner, String name) { 53 super(owner); 54 entryList = new Vector (); 55 aclName = name; 56 } 57 58 69 public void setName(Principal caller, String name) 70 throws NotOwnerException { 71 if (!isOwner(caller)) 72 throw new NotOwnerException (); 73 aclName = name; 74 } 75 76 81 public String getName(){ 82 return aclName; 83 } 84 85 101 public boolean addEntry(Principal caller, AclEntry entry) 102 throws NotOwnerException { 103 if (!isOwner(caller)) 104 throw new NotOwnerException (); 105 106 if (entryList.contains(entry)) 107 return false; 108 115 116 entryList.addElement(entry); 117 return true; 118 } 119 120 132 public boolean removeEntry(Principal caller, AclEntry entry) 133 throws NotOwnerException { 134 if (!isOwner(caller)) 135 throw new NotOwnerException (); 136 137 return (entryList.removeElement(entry)); 138 } 139 140 149 public void removeAll(Principal caller) 150 throws NotOwnerException { 151 if (!isOwner(caller)) 152 throw new NotOwnerException (); 153 entryList.removeAllElements(); 154 } 155 156 173 public Enumeration getPermissions(Principal user){ 174 Vector empty = new Vector (); 175 for (Enumeration e = entryList.elements();e.hasMoreElements();){ 176 AclEntry ent = (AclEntry ) e.nextElement(); 177 if (ent.getPrincipal().equals(user)) 178 return ent.permissions(); 179 } 180 return empty.elements(); 181 } 182 183 189 public Enumeration entries(){ 190 return entryList.elements(); 191 } 192 193 209 public boolean checkPermission(Principal user, 210 java.security.acl.Permission perm) { 211 for (Enumeration e = entryList.elements();e.hasMoreElements();){ 212 AclEntry ent = (AclEntry ) e.nextElement(); 213 if (ent.getPrincipal().equals(user)) 214 if (ent.checkPermission(perm)) return true; 215 } 216 return false; 217 } 218 219 236 public boolean checkPermission(Principal user, String community, 237 java.security.acl.Permission perm) { 238 for (Enumeration e = entryList.elements();e.hasMoreElements();){ 239 AclEntryImpl ent = (AclEntryImpl) e.nextElement(); 240 if (ent.getPrincipal().equals(user)) 241 if (ent.checkPermission(perm) && ent.checkCommunity(community)) return true; 242 } 243 return false; 244 } 245 246 256 public boolean checkCommunity(String community) { 257 for (Enumeration e = entryList.elements();e.hasMoreElements();){ 258 AclEntryImpl ent = (AclEntryImpl) e.nextElement(); 259 if (ent.checkCommunity(community)) return true; 260 } 261 return false; 262 } 263 264 269 public String toString(){ 270 return ("AclImpl: "+ getName()); 271 } 272 } 273 274 275 276 277 278 279 | Popular Tags |