1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.security.jaas;
16  
17  import java.io.Serializable;
18  
19  import java.security.Principal;
20  import java.security.acl.Group;
21  
22  import java.util.Collections;
23  import java.util.Enumeration;
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.Map;
27  
28  /**
29   * <a href="PortalGroup.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class PortalGroup
34      extends PortalPrincipal implements Group, Serializable {
35  
36      public PortalGroup(String groupName) {
37          super(groupName);
38      }
39  
40      public boolean addMember(Principal user) {
41          if (!_members.containsKey(user)) {
42              _members.put(user, user);
43  
44              return true;
45          }
46          else {
47              return false;
48          }
49      }
50  
51      public boolean isMember(Principal member) {
52          boolean isMember = _members.containsKey(member);
53  
54          if (!isMember) {
55              Iterator<Principal> itr = _members.values().iterator();
56  
57              while (!isMember && itr.hasNext()) {
58                  Principal principal = itr.next();
59  
60                  if (principal instanceof Group) {
61                      Group group = (Group)principal;
62  
63                      isMember = group.isMember(member);
64                  }
65              }
66          }
67  
68          return isMember;
69      }
70  
71      public Enumeration<Principal> members() {
72          return Collections.enumeration(_members.values());
73      }
74  
75      public boolean removeMember(Principal user) {
76          Principal principal = _members.remove(user);
77  
78          if (principal != null) {
79              return true;
80          }
81          else {
82              return false;
83          }
84      }
85  
86      private Map<Principal, Principal> _members =
87          new HashMap<Principal, Principal>();
88  
89  }