KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.turbine.om.security.Group;
23 import org.apache.turbine.om.security.User;
24 import org.apache.turbine.test.BaseTurbineHsqlTest;
25 import org.apache.turbine.util.security.AccessControlList;
26
27 public class TestSecurityACL
28         extends BaseTurbineHsqlTest
29 {
30     public TestSecurityACL(String JavaDoc name)
31             throws Exception JavaDoc
32     {
33         super(name, "conf/test/TurbineResources.properties");
34     }
35
36     public static Test suite()
37     {
38         return new TestSuite(TestSecurityACL.class);
39     }
40
41     public void testInit()
42     {
43         SecurityService ss = TurbineSecurity.getService();
44         assertTrue("Service failed to initialize", ss.getInit());
45     }
46
47     public void testAcl1()
48         throws Exception JavaDoc
49     {
50         SecurityService ss = TurbineSecurity.getService();
51
52         User admin = ss.getUser("admin");
53         assertNotNull(admin);
54
55         AccessControlList acl = ss.getACL(admin);
56         assertNotNull(acl);
57
58         assertFalse(acl.hasRole("Admin", "global"));
59         assertTrue(acl.hasRole("Admin", "Turbine"));
60         assertFalse(acl.hasRole("User", "global"));
61         assertFalse(acl.hasRole("User", "Turbine"));
62
63         assertFalse(acl.hasPermission("Admin", "global"));
64         assertTrue(acl.hasPermission("Admin", "Turbine"));
65         assertFalse(acl.hasPermission("Login", "global"));
66         assertFalse(acl.hasPermission("Login", "Turbine"));
67         assertFalse(acl.hasPermission("Application", "global"));
68         assertFalse(acl.hasPermission("Application", "Turbine"));
69     }
70
71     public void testAcl2()
72         throws Exception JavaDoc
73     {
74         SecurityService ss = TurbineSecurity.getService();
75
76         User admin = ss.getUser("user");
77         assertNotNull(admin);
78
79         AccessControlList acl = ss.getACL(admin);
80         assertNotNull(acl);
81
82         assertFalse(acl.hasRole("Admin", "global"));
83         assertFalse(acl.hasRole("Admin", "Turbine"));
84         assertFalse(acl.hasRole("User", "global"));
85         assertTrue(acl.hasRole("User", "Turbine"));
86
87         assertFalse(acl.hasPermission("Admin", "global"));
88         assertFalse(acl.hasPermission("Admin", "Turbine"));
89         assertFalse(acl.hasPermission("Login", "global"));
90         assertTrue(acl.hasPermission("Login", "Turbine"));
91         assertFalse(acl.hasPermission("Application", "global"));
92         assertTrue(acl.hasPermission("Application", "Turbine"));
93     }
94
95     public void testAcl3()
96         throws Exception JavaDoc
97     {
98         SecurityService ss = TurbineSecurity.getService();
99
100         User user = ss.getUser("user");
101         assertNotNull(user);
102
103         AccessControlList acl = ss.getACL(user);
104         assertNotNull(acl);
105
106         Group turbine = ss.getGroupByName("Turbine");
107         assertNotNull(turbine);
108
109         assertEquals(0, acl.getRoles().size());
110         assertEquals(1, acl.getRoles(turbine).size());
111         assertEquals(0, acl.getPermissions().size());
112         assertEquals(2, acl.getPermissions(turbine).size());
113     }
114
115 }
116
117
Popular Tags