1   package org.apache.turbine.services.security;
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  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.commons.configuration.BaseConfiguration;
26  import org.apache.commons.configuration.Configuration;
27  
28  import org.apache.turbine.services.ServiceManager;
29  import org.apache.turbine.services.TurbineServices;
30  import org.apache.turbine.services.factory.FactoryService;
31  import org.apache.turbine.services.factory.TurbineFactoryService;
32  import org.apache.turbine.services.security.db.DBSecurityService;
33  import org.apache.turbine.test.BaseTestCase;
34  import org.apache.turbine.util.security.AccessControlList;
35  import org.apache.turbine.util.security.TurbineAccessControlList;
36  
37  public class AccessControlListTest
38      extends BaseTestCase
39  {
40      private static final String PREFIX = "services." +
41          SecurityService.SERVICE_NAME + '.';
42  
43      public AccessControlListTest( String name )
44              throws Exception
45      {
46          super(name);
47      }
48  
49      public void testSelection()
50      {
51           try
52          {
53              doit();
54          }
55          catch( Exception e )
56          {
57              fail( e.getMessage() );
58          }
59     }
60  
61      public void doit()
62          throws Exception
63      {
64          ServiceManager serviceManager = TurbineServices.getInstance();
65          serviceManager.setApplicationRoot(".");
66  
67          Configuration cfg = new BaseConfiguration();
68  
69          cfg.setProperty(PREFIX + "classname",
70                          DBSecurityService.class.getName());
71  
72          cfg.setProperty(PREFIX + "acl.class",
73                          TurbineAccessControlList.class.getName());
74  
75          // We must run init!
76          cfg.setProperty(PREFIX+"earlyInit", "true");
77  
78          /* Ugh */
79  
80          cfg.setProperty("services." + FactoryService.SERVICE_NAME + ".classname",
81                          TurbineFactoryService.class.getName());
82  
83          serviceManager.setConfiguration(cfg);
84  
85          serviceManager.init();
86  
87          Class aclClass = TurbineSecurity.getService().getAclClass();
88  
89          if(!aclClass.getName().equals(TurbineAccessControlList.class.getName()))
90          {
91              fail("ACL Class is " + aclClass.getName()
92                   + ", expected was " + TurbineAccessControlList.class.getName());
93          }
94  
95          Map roles = new HashMap();
96          Map permissions = new HashMap();
97  
98          AccessControlList aclTest =
99            TurbineSecurity.getService().getAclInstance(roles, permissions);
100 
101         if(aclTest == null)
102         {
103           fail("Security Service failed to deliver a " + aclClass.getName()
104                + " Object");
105         }
106     }
107 }