1 package org.apache.fulcrum.security.model.basic;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 import org.apache.fulcrum.security.entity.Group;
22 import org.apache.fulcrum.security.util.GroupSet;
23
24 /**
25 * This is a control class that makes it easy to find out if a particular User
26 * has a given Permission. It also determines if a User has a a particular Role.
27 *
28 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
29 * @version $Id: BasicAccessControlListImpl.java 535465 2007-05-05 06:58:06Z tv
30 */
31 public class BasicAccessControlListImpl implements BasicAccessControlList
32 {
33 // TODO Need to rethink the two maps.. Why not just a single list of groups?
34 // That would then cascade down to all the other roles and so on..
35
36 /**
37 * Serial number
38 */
39 private static final long serialVersionUID = 2911747448261740381L;
40
41 /** The distinct list of groups that this user is part of */
42 private GroupSety/util/GroupSet.html#GroupSet">GroupSet groupSet = new GroupSet();
43
44 /**
45 * Constructs a new AccessControlList.
46 *
47 * This class follows 'immutable' pattern - it's objects can't be modified
48 * once they are created. This means that the permissions the users have are
49 * in effect form the moment they log in to the moment they log out, and
50 * changes made to the security settings in that time are not reflected in
51 * the state of this object. If you need to reset an user's permissions you
52 * need to invalidate his session. <br>
53 * The objects that constructs an AccessControlList must supply hashtables
54 * of role/permission sets keyed with group objects. <br>
55 *
56 * @param groupSet
57 * a hashtable containing GroupSet objects
58 */
59 public BasicAccessControlListImpl(GroupSet groupSet)
60 {
61 this.groupSet = groupSet;
62 }
63
64 /**
65 * Retrieves a set of Groups an user is assigned
66 *
67 * @return the set of Groups
68 */
69 public GroupSet getGroups()
70 {
71 return groupSet;
72 }
73
74 /**
75 * Checks if the user is assigned a specific Group
76 *
77 * @param group
78 * the Group
79 * @return <code>true</code> if the user is assigned the Group
80 */
81 public boolean hasGroup(Group group)
82 {
83 return groupSet.contains(group);
84 }
85
86 /**
87 * Checks if the user is assigned a specific Group
88 *
89 * @param group
90 * the Group name
91 * @return <code>true</code> if the user is assigned the Group
92 */
93 public boolean hasGroup(String group)
94 {
95 try
96 {
97 return groupSet.containsName(group);
98 }
99 catch (Exception e)
100 {
101 return false;
102 }
103 }
104 }