001: // ========================================================================
002: // $Id: JAASGroup.java 305 2006-03-07 10:32:14Z janb $
003: // Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
004: // ------------------------------------------------------------------------
005: // Licensed under the Apache License, Version 2.0 (the "License");
006: // you may not use this file except in compliance with the License.
007: // You may obtain a copy of the License at
008: // http://www.apache.org/licenses/LICENSE-2.0
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014: // ========================================================================
015:
016: package org.mortbay.jetty.plus.jaas;
017:
018: import java.security.Principal;
019: import java.security.acl.Group;
020: import java.util.Enumeration;
021: import java.util.HashSet;
022: import java.util.Iterator;
023:
024: public class JAASGroup implements Group {
025: public static final String ROLES = "__roles__";
026:
027: private String name = null;
028: private HashSet members = null;
029:
030: public JAASGroup(String n) {
031: this .name = n;
032: this .members = new HashSet();
033: }
034:
035: /* ------------------------------------------------------------ */
036: /**
037: *
038: * @param principal <description>
039: * @return <description>
040: */
041: public synchronized boolean addMember(Principal principal) {
042: return members.add(principal);
043: }
044:
045: /**
046: *
047: * @param principal <description>
048: * @return <description>
049: */
050: public synchronized boolean removeMember(Principal principal) {
051: return members.remove(principal);
052: }
053:
054: /**
055: *
056: * @param principal <description>
057: * @return <description>
058: */
059: public boolean isMember(Principal principal) {
060: return members.contains(principal);
061: }
062:
063: /**
064: *
065: * @return <description>
066: */
067: public Enumeration members() {
068:
069: class MembersEnumeration implements Enumeration {
070: private Iterator itor;
071:
072: public MembersEnumeration(Iterator itor) {
073: this .itor = itor;
074: }
075:
076: public boolean hasMoreElements() {
077: return this .itor.hasNext();
078: }
079:
080: public Object nextElement() {
081: return this .itor.next();
082: }
083:
084: }
085:
086: return new MembersEnumeration(members.iterator());
087: }
088:
089: /**
090: *
091: * @return <description>
092: */
093: public int hashCode() {
094: return getName().hashCode();
095: }
096:
097: /**
098: *
099: * @param object <description>
100: * @return <description>
101: */
102: public boolean equals(Object object) {
103: if (!(object instanceof JAASGroup))
104: return false;
105:
106: return ((JAASGroup) object).getName().equals(getName());
107: }
108:
109: /**
110: *
111: * @return <description>
112: */
113: public String toString() {
114: return getName();
115: }
116:
117: /**
118: *
119: * @return <description>
120: */
121: public String getName() {
122:
123: return name;
124: }
125:
126: }
|