View Javadoc
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.acl.AccessControlList;
22  import org.apache.fulcrum.security.entity.User;
23  import org.apache.fulcrum.security.model.ACLFactory;
24  import org.apache.fulcrum.security.model.basic.entity.BasicUser;
25  import org.apache.fulcrum.security.spi.AbstractManager;
26  import org.apache.fulcrum.security.util.GroupSet;
27  import org.apache.fulcrum.security.util.UnknownEntityException;
28  
29  /**
30   *
31   * This factory creates instance of the DynamicAccessControlList
32   *
33   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
34   * @version $Id$
35   */
36  public class BasicACLFactory extends AbstractManager implements ACLFactory
37  {
38      /**
39       * Construct a new ACL object.
40       *
41       * This constructs a new ACL object from the configured class and
42       * initializes it with the supplied roles and permissions.
43       *
44       * @param groupSet
45       *            The GroupSet that this ACL should contain
46       *
47       * @return an object implementing ACL interface.
48       * @throws UnknownEntityException
49       *             if the object could not be instantiated.
50       */
51      private BasicAccessControlListImpl getAclInstance(GroupSet groupSet) throws UnknownEntityException
52      {
53      	BasicAccessControlListImpl accessControlList;
54  
55          try
56          {
57              accessControlList = new BasicAccessControlListImpl(groupSet);
58          }
59          catch (Exception e)
60          {
61              throw new UnknownEntityException("Failed to instantiate an ACL implementation object", e);
62          }
63  
64          return accessControlList;
65      }
66  
67      /* (non-Javadoc)
68       * @see org.apache.fulcrum.security.model.ACLFactory#getAccessControlList(org.apache.fulcrum.security.entity.User)
69       */
70      public <T extends AccessControlList> T getAccessControlList(User user)
71      {
72          GroupSet groupSet = ((BasicUser) user).getGroups();
73  
74          try
75          {
76              @SuppressWarnings("unchecked")
77  			T aclInstance = (T) getAclInstance(groupSet);
78  			return aclInstance;
79          }
80          catch (UnknownEntityException uue)
81          {
82              throw new RuntimeException(uue.getMessage(), uue);
83          }
84      }
85  }