1 5 6 package org.exoplatform.services.security.jaas; 7 8 import java.security.acl.Group ; 9 import java.security.Principal ; 10 import java.util.Enumeration ; 11 import java.util.Iterator ; 12 import java.util.HashSet ; 13 14 19 public class JAASGroup implements Group { 20 public static final String ROLES = "Roles"; 21 22 private String name = null; 23 private HashSet members = null; 24 25 26 public JAASGroup(String n) { 27 this.name = n; 28 this.members = new HashSet (); 29 } 30 31 public synchronized boolean addMember(Principal principal) { 32 return members.add(principal); 33 } 34 35 public synchronized boolean removeMember(Principal principal) { 36 return members.remove(principal); 37 } 38 39 public boolean isMember(Principal principal) { 40 Enumeration en = members(); 41 while (en.hasMoreElements()) { 42 Principal principal1 = (Principal ) en.nextElement(); 43 if(principal1.getName().equals(principal.getName())) 44 return true; 45 } 46 return false; 47 } 48 49 public Enumeration members() { 50 class MembersEnumeration implements Enumeration { 51 private Iterator itor; 52 public MembersEnumeration(Iterator itor) { 53 this.itor = itor; 54 } 55 public boolean hasMoreElements() { 56 return this.itor.hasNext(); 57 } 58 public Object nextElement() { 59 return this.itor.next(); 60 } 61 } 62 return new MembersEnumeration(members.iterator()); 63 } 64 65 public int hashCode() { 66 return getName().hashCode(); 67 } 68 69 public boolean equals(Object object) { 70 if (!(object instanceof Group )) 71 return false; 72 return ((Group ) object).getName().equals(getName()); 73 } 74 75 public String toString() { 76 return getName(); 77 } 78 79 public String getName() { 80 return name; 81 } 82 83 } 84 | Popular Tags |