1 7 package org.jboss.security; 8 9 import java.security.Principal ; 10 import java.security.acl.Group ; 11 import java.util.Enumeration ; 12 import java.util.LinkedList ; 13 14 29 public class NestablePrincipal extends SimplePrincipal implements Group 30 { 31 34 private LinkedList principalStack; 35 36 38 public NestablePrincipal(String name) 39 { 40 super(name); 41 principalStack = new LinkedList (); 42 } 43 44 48 public Enumeration members() 49 { 50 return new IndexEnumeration(); 51 } 52 53 59 public boolean removeMember(Principal user) 60 { 61 return principalStack.remove(user); 62 } 63 64 68 public boolean addMember(Principal user) 69 { 70 principalStack.addFirst(user); 71 return true; 72 } 73 74 84 public boolean isMember(Principal member) 85 { 86 if( principalStack.size() == 0 ) 87 return false; 88 89 Object activePrincipal = principalStack.getFirst(); 90 return member.equals(activePrincipal); 91 } 92 94 private class IndexEnumeration implements Enumeration 95 { 96 private boolean hasMoreElements; 97 98 IndexEnumeration() 99 { 100 hasMoreElements = principalStack.size() > 0; 101 } 102 public boolean hasMoreElements() 103 { 104 return hasMoreElements; 105 } 106 public Object nextElement() 107 { 108 Object next = principalStack.getFirst(); 109 hasMoreElements = false; 110 return next; 111 } 112 } 113 } 114 | Popular Tags |