1 package org.apache.turbine.services.security; 2 3 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 name) 31 throws Exception 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 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 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 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 |