1 17 18 19 20 package org.apache.lenya.ac.impl; 21 22 import java.io.File ; 23 24 import org.apache.avalon.framework.component.ComponentSelector; 25 import org.apache.lenya.ac.AccessControlException; 26 import org.apache.lenya.ac.AccessControllerResolver; 27 import org.apache.lenya.ac.AccreditableManager; 28 import org.apache.lenya.ac.Identity; 29 import org.apache.lenya.ac.User; 30 import org.apache.lenya.ac.file.FileAccreditableManager; 31 import org.apache.lenya.ac.file.FilePolicyManager; 32 import org.apache.lenya.cms.ExcaliburTest; 33 import org.apache.lenya.cms.PublicationHelper; 34 import org.apache.lenya.cms.ac.PublicationAccessControllerResolver; 35 36 40 public class AccessControlTest extends ExcaliburTest { 41 42 private ComponentSelector accessControllerResolverSelector; 43 private AccessControllerResolver accessControllerResolver; 44 private DefaultAccessController accessController; 45 46 private File accreditablesDirectory; 47 48 51 public AccessControlTest(String test) { 52 super(test); 53 } 54 55 59 public DefaultAccessController getAccessController() { 60 return accessController; 61 } 62 63 protected static final String URL = "/test/authoring/index.html"; 64 65 66 protected void setUp() throws Exception { 67 68 if (PublicationHelper.getPublication() == null) { 69 String [] args = { "D:\\Development\\build\\tomcat-4.1.24\\webapps\\lenya", "test" }; 70 PublicationHelper.extractPublicationArguments(args); 71 } 72 73 super.setUp(); 74 75 accessControllerResolverSelector = 76 (ComponentSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector"); 77 assertNotNull(accessControllerResolverSelector); 78 79 accessControllerResolver = 80 (AccessControllerResolver) accessControllerResolverSelector.select( 81 AccessControllerResolver.DEFAULT_RESOLVER); 82 83 assertNotNull(accessControllerResolver); 84 getLogger().info( 85 "Using access controller resolver: [" + accessControllerResolver.getClass() + "]"); 86 87 accessController = 88 (DefaultAccessController) 89 ( 90 ( 91 PublicationAccessControllerResolver) accessControllerResolver) 92 .resolveAccessController( 93 URL); 94 95 assertNotNull(accessController); 96 getLogger().info("Resolved access controller: [" + accessController.getClass() + "]"); 97 98 File servletContext = PublicationHelper.getPublication().getServletContext(); 99 ((FilePolicyManager) accessController.getPolicyManager()).setPoliciesDirectory( 100 servletContext); 101 102 accreditablesDirectory = 103 new File ( 104 PublicationHelper.getPublication().getDirectory(), 105 "config/ac/passwd".replace('/', File.separatorChar)); 106 ( 107 (FileAccreditableManager) accessController 108 .getAccreditableManager()) 109 .setConfigurationDirectory( 110 accreditablesDirectory); 111 112 } 113 114 120 public void tearDown() throws Exception { 121 super.tearDown(); 122 123 if (accessControllerResolverSelector != null) { 124 if (accessControllerResolver != null) { 125 if (accessController != null) { 126 accessControllerResolver.release(accessController); 127 } 128 accessControllerResolverSelector.release(accessControllerResolver); 129 } 130 manager.release(accessControllerResolver); 131 } 132 } 133 134 protected static final String USERNAME = "lenya"; 135 136 141 protected Identity getIdentity() throws AccessControlException { 142 DefaultAccessController controller = getAccessController(); 143 User user = controller.getAccreditableManager().getUserManager().getUser(USERNAME); 144 assertNotNull(user); 145 146 Identity identity = new Identity(); 147 identity.addIdentifiable(user); 148 149 return identity; 150 } 151 152 156 protected FilePolicyManager getPolicyManager() { 157 return (FilePolicyManager) getAccessController().getPolicyManager(); 158 } 159 160 164 protected AccreditableManager getAccreditableManager() { 165 return getAccessController().getAccreditableManager(); 166 } 167 168 172 protected File getAccreditablesDirectory() { 173 return accreditablesDirectory; 174 } 175 176 } 177 | Popular Tags |