KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > security > AccessControlListTest


1 package org.apache.turbine.services.security;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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