01: package org.apache.turbine.services.security;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 extends BaseTestCase {
38: private static final String PREFIX = "services."
39: + SecurityService.SERVICE_NAME + '.';
40:
41: public AccessControlListTest(String name) throws Exception {
42: super (name);
43: }
44:
45: public void testSelection() {
46: try {
47: doit();
48: } catch (Exception e) {
49: fail(e.getMessage());
50: }
51: }
52:
53: public void doit() throws Exception {
54: ServiceManager serviceManager = TurbineServices.getInstance();
55: serviceManager.setApplicationRoot(".");
56:
57: Configuration cfg = new BaseConfiguration();
58:
59: cfg.setProperty(PREFIX + "classname", DBSecurityService.class
60: .getName());
61:
62: cfg.setProperty(PREFIX + "acl.class",
63: TurbineAccessControlList.class.getName());
64:
65: // We must run init!
66: cfg.setProperty(PREFIX + "earlyInit", "true");
67:
68: /* Ugh */
69:
70: cfg.setProperty("services." + FactoryService.SERVICE_NAME
71: + ".classname", TurbineFactoryService.class.getName());
72:
73: serviceManager.setConfiguration(cfg);
74:
75: serviceManager.init();
76:
77: Class aclClass = TurbineSecurity.getService().getAclClass();
78:
79: if (!aclClass.getName().equals(
80: TurbineAccessControlList.class.getName())) {
81: fail("ACL Class is " + aclClass.getName()
82: + ", expected was "
83: + TurbineAccessControlList.class.getName());
84: }
85:
86: Map roles = new HashMap();
87: Map permissions = new HashMap();
88:
89: AccessControlList aclTest = TurbineSecurity.getService()
90: .getAclInstance(roles, permissions);
91:
92: if (aclTest == null) {
93: fail("Security Service failed to deliver a "
94: + aclClass.getName() + " Object");
95: }
96: }
97: }
|