1 package org.apache.turbine.services.security; 2 3 18 19 import java.util.HashMap ; 20 import java.util.Map ; 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 PREFIX = "services." + 38 SecurityService.SERVICE_NAME + '.'; 39 40 public AccessControlListTest( String name ) 41 throws Exception 42 { 43 super(name); 44 } 45 46 public void testSelection() 47 { 48 try 49 { 50 doit(); 51 } 52 catch( Exception e ) 53 { 54 fail( e.getMessage() ); 55 } 56 } 57 58 public void doit() 59 throws Exception 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 cfg.setProperty(PREFIX+"earlyInit", "true"); 74 75 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 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 roles = new HashMap (); 93 Map permissions = new HashMap (); 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 |