1 17 18 19 20 package org.apache.lenya.cms.cocoon.acting; 21 22 import java.util.Collections ; 23 import java.util.Map ; 24 25 import org.apache.avalon.framework.parameters.Parameters; 26 import org.apache.avalon.framework.service.ServiceSelector; 27 import org.apache.cocoon.acting.ConfigurableServiceableAction; 28 import org.apache.cocoon.environment.ObjectModelHelper; 29 import org.apache.cocoon.environment.Redirector; 30 import org.apache.cocoon.environment.Request; 31 import org.apache.cocoon.environment.SourceResolver; 32 import org.apache.lenya.ac.AccessController; 33 import org.apache.lenya.ac.AccessControllerResolver; 34 import org.apache.lenya.util.ServletHelper; 35 36 public abstract class AccessControlAction extends ConfigurableServiceableAction { 37 38 private AccessController accessController; 39 40 50 public Map act( 51 Redirector redirector, 52 SourceResolver sourceResolver, 53 Map objectModel, 54 String source, 55 Parameters parameters) 56 throws Exception { 57 58 ServiceSelector selector = null; 59 AccessControllerResolver resolver = null; 60 accessController = null; 61 62 Request request = ObjectModelHelper.getRequest(objectModel); 63 64 Map result = null; 65 66 try { 67 selector = 68 (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector"); 69 70 getLogger().debug("Resolving AC resolver for type [" + AccessControllerResolver.DEFAULT_RESOLVER + "]"); 71 resolver = 72 (AccessControllerResolver) selector.select( 73 AccessControllerResolver.DEFAULT_RESOLVER); 74 getLogger().debug("Resolved AC resolver [" + resolver + "]"); 75 76 String webappUrl = ServletHelper.getWebappURI(request); 77 accessController = resolver.resolveAccessController(webappUrl); 78 79 if (accessController == null) { 80 result = Collections.EMPTY_MAP; 81 } else { 82 accessController.setupIdentity(request); 83 result = doAct(redirector, sourceResolver, objectModel, source, parameters); 84 } 85 86 } finally { 87 if (selector != null) { 88 if (resolver != null) { 89 selector.release(resolver); 90 } 91 manager.release(selector); 92 } 93 } 94 return result; 95 } 96 97 116 protected abstract Map doAct( 117 Redirector redirector, 118 SourceResolver resolver, 119 Map objectModel, 120 String source, 121 Parameters parameters) 122 throws Exception ; 123 124 128 public AccessController getAccessController() { 129 return accessController; 130 } 131 132 } 133 | Popular Tags |