1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.jaas;
20
21 import java.security.Principal;
22 import java.security.acl.Group;
23 import java.util.Enumeration;
24 import java.util.HashSet;
25 import java.util.Iterator;
26
27 public class JAASGroup implements Group
28 {
29 public static final String ROLES = "__roles__";
30
31 private String _name = null;
32 private HashSet<Principal> _members = null;
33
34 public JAASGroup(String n)
35 {
36 this._name = n;
37 this._members = new HashSet<Principal>();
38 }
39
40
41 public synchronized boolean addMember(Principal principal)
42 {
43 return _members.add(principal);
44 }
45
46 public synchronized boolean removeMember(Principal principal)
47 {
48 return _members.remove(principal);
49 }
50
51 public boolean isMember(Principal principal)
52 {
53 return _members.contains(principal);
54 }
55
56 public Enumeration<? extends Principal> members()
57 {
58
59 class MembersEnumeration implements Enumeration<Principal>
60 {
61 private Iterator<? extends Principal> itor;
62
63 public MembersEnumeration (Iterator<? extends Principal> itor)
64 {
65 this.itor = itor;
66 }
67
68 public boolean hasMoreElements ()
69 {
70 return this.itor.hasNext();
71 }
72
73
74 public Principal nextElement ()
75 {
76 return this.itor.next();
77 }
78
79 }
80
81 return new MembersEnumeration (_members.iterator());
82 }
83
84 public int hashCode()
85 {
86 return getName().hashCode();
87 }
88
89 public boolean equals(Object object)
90 {
91 if (! (object instanceof JAASGroup))
92 return false;
93
94 return ((JAASGroup)object).getName().equals(getName());
95 }
96
97 public String toString()
98 {
99 return getName();
100 }
101
102 public String getName()
103 {
104
105 return _name;
106 }
107 }