001: package org.apache.turbine.services.security;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.turbine.om.security.Group;
026: import org.apache.turbine.om.security.User;
027: import org.apache.turbine.test.BaseTurbineHsqlTest;
028: import org.apache.turbine.util.security.AccessControlList;
029:
030: public class TestSecurityACL extends BaseTurbineHsqlTest {
031: public TestSecurityACL(String name) throws Exception {
032: super (name, "conf/test/TurbineResources.properties");
033: }
034:
035: public static Test suite() {
036: return new TestSuite(TestSecurityACL.class);
037: }
038:
039: public void testInit() {
040: SecurityService ss = TurbineSecurity.getService();
041: assertTrue("Service failed to initialize", ss.getInit());
042: }
043:
044: public void testAcl1() throws Exception {
045: SecurityService ss = TurbineSecurity.getService();
046:
047: User admin = ss.getUser("admin");
048: assertNotNull(admin);
049:
050: AccessControlList acl = ss.getACL(admin);
051: assertNotNull(acl);
052:
053: assertFalse(acl.hasRole("Admin", "global"));
054: assertTrue(acl.hasRole("Admin", "Turbine"));
055: assertFalse(acl.hasRole("User", "global"));
056: assertFalse(acl.hasRole("User", "Turbine"));
057:
058: assertFalse(acl.hasPermission("Admin", "global"));
059: assertTrue(acl.hasPermission("Admin", "Turbine"));
060: assertFalse(acl.hasPermission("Login", "global"));
061: assertFalse(acl.hasPermission("Login", "Turbine"));
062: assertFalse(acl.hasPermission("Application", "global"));
063: assertFalse(acl.hasPermission("Application", "Turbine"));
064: }
065:
066: public void testAcl2() throws Exception {
067: SecurityService ss = TurbineSecurity.getService();
068:
069: User admin = ss.getUser("user");
070: assertNotNull(admin);
071:
072: AccessControlList acl = ss.getACL(admin);
073: assertNotNull(acl);
074:
075: assertFalse(acl.hasRole("Admin", "global"));
076: assertFalse(acl.hasRole("Admin", "Turbine"));
077: assertFalse(acl.hasRole("User", "global"));
078: assertTrue(acl.hasRole("User", "Turbine"));
079:
080: assertFalse(acl.hasPermission("Admin", "global"));
081: assertFalse(acl.hasPermission("Admin", "Turbine"));
082: assertFalse(acl.hasPermission("Login", "global"));
083: assertTrue(acl.hasPermission("Login", "Turbine"));
084: assertFalse(acl.hasPermission("Application", "global"));
085: assertTrue(acl.hasPermission("Application", "Turbine"));
086: }
087:
088: public void testAcl3() throws Exception {
089: SecurityService ss = TurbineSecurity.getService();
090:
091: User user = ss.getUser("user");
092: assertNotNull(user);
093:
094: AccessControlList acl = ss.getACL(user);
095: assertNotNull(acl);
096:
097: Group turbine = ss.getGroupByName("Turbine");
098: assertNotNull(turbine);
099:
100: assertEquals(0, acl.getRoles().size());
101: assertEquals(1, acl.getRoles(turbine).size());
102: assertEquals(0, acl.getPermissions().size());
103: assertEquals(2, acl.getPermissions(turbine).size());
104: }
105:
106: }
|