You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2007/01/13 15:51:36 UTC
svn commit: r495903 - in
/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main:
java/org/apache/cocoon/auth/ java/org/apache/cocoon/auth/acting/
java/org/apache/cocoon/auth/impl/ resources/META-INF/
resources/META-INF/cocoon/ resources/META-INF/co...
Author: cziegeler
Date: Sat Jan 13 06:51:35 2007
New Revision: 495903
URL: http://svn.apache.org/viewvc?view=rev&rev=495903
Log:
Start conversion of auth block to spring
Added:
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-auth-sitemap-xconf
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml (with props)
Removed:
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/org/
Modified:
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/AbstractSecurityHandler.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/ApplicationManager.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/StandardApplication.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LoginAction.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LogoutAction.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/PipelineSecurityHandler.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/ServletSecurityHandler.java
cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/StandardApplicationManager.java
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/AbstractSecurityHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/AbstractSecurityHandler.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/AbstractSecurityHandler.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/AbstractSecurityHandler.java Sat Jan 13 06:51:35 2007
@@ -18,29 +18,17 @@
*/
package org.apache.cocoon.auth;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.BeanNameAware;
/**
- * This is a base class that can be used for own {@link SecurityHandler}s. It
- * provides a save implementation for the {@link #getId()} method. The only
- * drawback is that a subclass has to use {@link Configurable} and can't
- * use {@link org.apache.avalon.framework.parameters.Parameterizable}.
+ * This is a base class that can be used for own {@link SecurityHandler}s.
*
* @version $Id$
-*/
+ */
public abstract class AbstractSecurityHandler
- extends AbstractLogEnabled
- implements SecurityHandler, Configurable, Contextualizable, ThreadSafe {
-
- /** The unique identifier. */
- protected String id;
+ implements SecurityHandler, BeanNameAware {
/** Support for anonymous user? */
protected boolean supportAnonUser = false;
@@ -51,35 +39,37 @@
/** Password of the anonymous user. */
protected String anonPass = "anonymous";
- /** Component Context. */
- protected Context context;
+ /** The id for the security handler. */
+ protected String id = String.valueOf(this.hashCode());
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
- public void contextualize(final Context aContext) throws ContextException {
- this.context = aContext;
- String sitemapPrefix = null;
- try {
- // this is available starting with Cocoon 2.2
- sitemapPrefix = (String)this.context.get("env-prefix");
- } catch (ContextException ce) {
- // no prefix available, so we are running pre 2.2 which means
- // we only have one cocoon.xconf anyway
- sitemapPrefix = "cocoon-2.1.x";
- }
- this.id = sitemapPrefix + '/';
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ public void setLogger(Log l) {
+ this.logger = l;
+ }
+
+ public void setAnonymousName(String anonName) {
+ this.anonName = anonName;
+ }
+
+ public void setAnonymousPassword(String anonPass) {
+ this.anonPass = anonPass;
+ }
+
+ public void setSupportAnonymousUser(boolean supportAnonUser) {
+ this.supportAnonUser = supportAnonUser;
}
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
- public void configure(final Configuration conf) throws ConfigurationException {
- this.id = this.id + '/' + this.getClass().getName() + '/'
- + conf.getAttribute( "role", this.getClass().getName());
- this.supportAnonUser = conf.getChild("supportAnonymous").getValueAsBoolean(this.supportAnonUser);
- this.anonName = conf.getChild("anonymousName").getValue(this.anonName);
- this.anonPass = conf.getChild("anonymousPassword").getValue(this.anonPass);
+ public void setBeanName(String name) {
+ this.id = name;
}
/**
@@ -88,4 +78,5 @@
public String getId() {
return this.id;
}
+
}
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/ApplicationManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/ApplicationManager.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/ApplicationManager.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/ApplicationManager.java Sat Jan 13 06:51:35 2007
@@ -39,11 +39,11 @@
/** The string used to store the application data in the object model .*/
String APPLICATION_DATA = "cauth-application-data";
- /** The key for parameters in the login context. */
- String LOGIN_CONTEXT_PARAMETERS_KEY = "parameters";
+ /** The key for properties in the login context. */
+ String LOGIN_CONTEXT_PROPERTIES_KEY = "properties";
- /** The key for parameters in the logout context. */
- String LOGOUT_CONTEXT_PARAMETERS_KEY = "parameters";
+ /** The key for properties in the logout context. */
+ String LOGOUT_CONTEXT_PROPERTIES_KEY = "properties";
/** The key for the logout method in the logout context. */
String LOGOUT_CONTEXT_MODE_KEY = "mode";
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/StandardApplication.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/StandardApplication.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/StandardApplication.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/StandardApplication.java Sat Jan 13 06:51:35 2007
@@ -21,16 +21,9 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.auth.impl.AnonymousSecurityHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* This is the default implementation for an {@link Application}.
@@ -38,8 +31,7 @@
* @version $Id$
*/
public class StandardApplication
- extends AbstractLogEnabled
- implements Application, Configurable, Serviceable, Disposable, ThreadSafe {
+ implements Application {
/** This prefix is used to lookup security handlers. */
protected static final String HANDLER_CONFIG_PREFIX =
@@ -48,86 +40,36 @@
protected static final String STORE_CONFIG_PREFIX =
ApplicationStore.class.getName() + '/';
- /** The service manager. */
- protected ServiceManager manager;
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ public void setLogger(Log l) {
+ this.logger = l;
+ }
/** The security handler. */
- protected SecurityHandler handler;
+ protected SecurityHandler handler = new AnonymousSecurityHandler();
/** Attributes. */
- protected final Map attributes = new HashMap();
+ protected Map attributes = new HashMap();
/** Application store. */
protected ApplicationStore store;
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(final ServiceManager aManager) throws ServiceException {
- this.manager = aManager;
- }
-
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(final Configuration conf)
- throws ConfigurationException {
- String handlerName = conf.getAttribute("security-handler", null);
- String storeName = conf.getAttribute("store", null);
- try {
- if ( handlerName == null ) {
- this.handler = new AnonymousSecurityHandler();
- } else {
- if ( !handlerName.startsWith(HANDLER_CONFIG_PREFIX) ) {
- handlerName = HANDLER_CONFIG_PREFIX + handlerName;
- }
- this.handler = (SecurityHandler)this.manager.lookup(handlerName);
- }
- if ( storeName != null ) {
- if ( !storeName.startsWith(STORE_CONFIG_PREFIX) ) {
- storeName = STORE_CONFIG_PREFIX + storeName;
- }
- this.store = (ApplicationStore)this.manager.lookup(storeName);
- }
- } catch (ServiceException se) {
- throw new ConfigurationException("Unable to look up component.", se);
- }
- this.configureAttributes(conf);
+ public void setSecurityHandler(SecurityHandler h) {
+ this.handler = h;
}
- /**
- * This method is invoked during configuration of the application. The
- * default behaviour is to add all children of the configuration object
- * as key value pairs. The name of the child is the key, and the value
- * of the tag is the value (as a string).
- * Subclasses can override this method, if a different/additional
- * behaviour is wanted.
- * @param conf The application configuration.
- */
- protected void configureAttributes(final Configuration conf) {
- Configuration[] children = conf.getChildren();
- for(int i=0; i<children.length; i++) {
- final String name = children[i].getName();
- final String value = children[i].getValue(null);
- if ( value != null && value.trim().length() > 0 ) {
- this.setAttribute(name, value.trim());
- }
- }
+ public void setApplicationStore(ApplicationStore s) {
+ this.store = s;
}
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if ( this.manager != null) {
- this.manager.release(this.store);
- if ( !(this.handler instanceof AnonymousSecurityHandler) ) {
- this.manager.release(this.handler);
- }
- this.store = null;
- this.handler = null;
- this.manager = null;
- }
+ public void setAttributes(Map map) {
+ this.attributes = map;
}
/**
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LoginAction.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LoginAction.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LoginAction.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LoginAction.java Sat Jan 13 06:51:35 2007
@@ -59,7 +59,7 @@
Map map = null;
final Map loginContext = new HashMap();
- loginContext.put(ApplicationManager.LOGIN_CONTEXT_PARAMETERS_KEY, par);
+ loginContext.put(ApplicationManager.LOGIN_CONTEXT_PROPERTIES_KEY, Parameters.toProperties(par));
final User user =
this.applicationManager.login( applicationName, loginContext );
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LogoutAction.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LogoutAction.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LogoutAction.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/acting/LogoutAction.java Sat Jan 13 06:51:35 2007
@@ -64,7 +64,7 @@
}
final Map logoutContext = new HashMap();
- logoutContext.put(ApplicationManager.LOGOUT_CONTEXT_PARAMETERS_KEY, par);
+ logoutContext.put(ApplicationManager.LOGOUT_CONTEXT_PROPERTIES_KEY, Parameters.toProperties(par));
logoutContext.put(ApplicationManager.LOGOUT_CONTEXT_MODE_KEY, mode);
this.applicationManager.logout(applicationName, logoutContext);
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/PipelineSecurityHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/PipelineSecurityHandler.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/PipelineSecurityHandler.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/PipelineSecurityHandler.java Sat Jan 13 06:51:35 2007
@@ -18,25 +18,19 @@
*/
package org.apache.cocoon.auth.impl;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.components.source.SourceUtil;
-import org.apache.cocoon.util.NetUtils;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceException;
-import org.apache.excalibur.source.SourceParameters;
-import org.apache.excalibur.source.SourceResolver;
import org.apache.cocoon.auth.AbstractSecurityHandler;
import org.apache.cocoon.auth.ApplicationManager;
import org.apache.cocoon.auth.StandardUser;
import org.apache.cocoon.auth.User;
+import org.apache.cocoon.components.source.util.SourceUtil;
+import org.apache.cocoon.util.NetUtils;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -48,25 +42,27 @@
* @version $Id$
*/
public class PipelineSecurityHandler
- extends AbstractSecurityHandler
- implements Serviceable,
- Disposable {
-
- /** The service manager. */
- protected ServiceManager manager;
+ extends AbstractSecurityHandler {
/** The source resolver. */
protected SourceResolver resolver;
- /** Configuration. */
- protected Configuration config;
+ /** The authentication resource. */
+ protected String authenticationResource;
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(final Configuration conf) throws ConfigurationException {
- super.configure(conf);
- this.config = conf;
+ /** The logout resource. */
+ protected String logoutResource;
+
+ public void setAuthenticationResource(String authenticationResource) {
+ this.authenticationResource = authenticationResource;
+ }
+
+ public void setLogoutResource(String logoutResource) {
+ this.logoutResource = logoutResource;
+ }
+
+ public void setResolver(SourceResolver resolver) {
+ this.resolver = resolver;
}
/**
@@ -86,22 +82,21 @@
// now authentication must have one child ID
if (child.hasChildNodes()) {
final NodeList children = child.getChildNodes();
- boolean found = false;
int i = 0;
Node current = null;
- while (!found && i < children.getLength()) {
- current = children.item(i);
- if (current.getNodeType() == Node.ELEMENT_NODE
- && current.getNodeName().equals("ID")) {
- found = true;
+ while (current == null && i < children.getLength()) {
+ final Node node = children.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && node.getNodeName().equals("ID")) {
+ current = node;
} else {
i++;
}
}
// now the last check: ID must have a TEXT child
- if (found) {
+ if ( current != null ) {
current.normalize(); // join text nodes
if (current.hasChildNodes() &&
current.getChildNodes().getLength() == 1 &&
@@ -123,19 +118,19 @@
* @see org.apache.cocoon.auth.SecurityHandler#login(java.util.Map)
*/
public User login(final Map loginContext) throws Exception {
- String authenticationResourceName =
- this.config.getChild("authentication-resource").getValue();
+ String authenticationResourceName = this.authenticationResource;
// append parameters
- Parameters p = (Parameters)
- loginContext.get(ApplicationManager.LOGIN_CONTEXT_PARAMETERS_KEY);
+ Properties p = (Properties)
+ loginContext.get(ApplicationManager.LOGIN_CONTEXT_PROPERTIES_KEY);
if ( p != null ) {
final StringBuffer b = new StringBuffer(authenticationResourceName);
boolean hasParams = (authenticationResourceName.indexOf('?') != -1);
- final String[] names = p.getNames();
- for(int i=0;i<names.length;i++) {
- final String key = names[i];
- final String value = p.getParameter(key);
+ final Iterator i = p.entrySet().iterator();
+ while ( i.hasNext() ) {
+ final Map.Entry current = (Map.Entry)i.next();
+ final String key = current.getKey().toString();
+ final String value = current.getValue().toString();
if ( hasParams ) {
b.append('&');
} else {
@@ -154,7 +149,7 @@
try {
source = SourceUtil.getSource(authenticationResourceName, null,
null, this.resolver);
- doc = SourceUtil.toDOM(source);
+ doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
} catch (SourceException se) {
throw SourceUtil.handle(se);
} finally {
@@ -176,29 +171,10 @@
}
/**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(final ServiceManager aManager) throws ServiceException {
- this.manager = aManager;
- this.resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if ( this.manager != null ){
- this.manager.release( this.resolver );
- this.manager = null;
- this.resolver = null;
- }
- }
-
- /**
* @see org.apache.cocoon.auth.SecurityHandler#logout(java.util.Map, org.apache.cocoon.auth.User)
*/
public void logout(final Map logoutContext, final User user) {
- final String logoutResourceName = this.config.getChild("logout-resource").getValue(null);
+ final String logoutResourceName = this.logoutResource;
if (logoutResourceName != null) {
// invoke the source
Source source = null;
@@ -206,7 +182,7 @@
// This allows arbitrary business logic to be called. Whatever is returned
// is ignored.
source = SourceUtil.getSource(logoutResourceName, null, null, this.resolver);
- SourceUtil.toDOM(source);
+ org.apache.cocoon.components.source.SourceUtil.toDOM(source);
} catch (Exception ignore) {
this.getLogger().warn("Exception during logout of user: " + user.getId(),
ignore);
@@ -249,7 +225,7 @@
* attributes to the user object.
*/
protected void calculateContextInfo() {
- SourceParameters parameters = new SourceParameters();
+ final Properties parameters = new Properties();
// add all elements from inside the handler data
this.addParametersFromAuthenticationXML("/data",
@@ -259,18 +235,12 @@
this.addParametersFromAuthenticationXML(null,
parameters);
- Parameters pars = parameters.getFirstParameters();
- String[] names = pars.getNames();
- if (names != null) {
- String key;
- String value;
- for(int i=0;i<names.length;i++) {
- key = names[i];
- value = pars.getParameter(key, null);
- if (value != null) {
- this.setAttribute(key, value);
- }
- }
+ final Iterator i = parameters.entrySet().iterator();
+ while ( i.hasNext() ) {
+ final Map.Entry current = (Map.Entry)i.next();
+ final String key = current.getKey().toString();
+ final String value = current.getValue().toString();
+ this.setAttribute(key, value);
}
}
@@ -283,8 +253,8 @@
* @param childElementName The name of the element to search in.
* @param parameters The found key-value pair is added to this parameters object.
*/
- private void addParametersFromAuthenticationXML(final String childElementName,
- final SourceParameters parameters) {
+ private void addParametersFromAuthenticationXML(final String childElementName,
+ final Properties parameters) {
Element root = this.userInfo.getDocumentElement();
if ( childElementName != null ) {
NodeList l = root.getElementsByTagName(childElementName);
@@ -322,7 +292,7 @@
}
value = valueBuffer.toString().trim();
if (key != null && value != null && value.length() > 0) {
- parameters.setParameter(key, value);
+ parameters.setProperty(key, value);
}
}
}
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/ServletSecurityHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/ServletSecurityHandler.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/ServletSecurityHandler.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/ServletSecurityHandler.java Sat Jan 13 06:51:35 2007
@@ -21,10 +21,9 @@
import java.security.Principal;
import java.util.Map;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.processing.ProcessInfoProvider;
import org.apache.cocoon.auth.AbstractSecurityHandler;
import org.apache.cocoon.auth.StandardUser;
import org.apache.cocoon.auth.User;
@@ -39,15 +38,11 @@
public class ServletSecurityHandler
extends AbstractSecurityHandler {
- /** The component context. */
- protected Context context;
+ /** The process info provider. */
+ protected ProcessInfoProvider processInfoProvider;
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
- public void contextualize(final Context aContext) throws ContextException {
- super.contextualize(aContext);
- this.context = aContext;
+ public void setProcessInfoProvider(ProcessInfoProvider p) {
+ this.processInfoProvider = p;
}
/**
@@ -64,7 +59,7 @@
* @see org.apache.cocoon.auth.SecurityHandler#login(java.util.Map)
*/
public User login(final Map loginContext) throws Exception {
- final Request req = ContextHelper.getRequest(this.context);
+ final Request req = ObjectModelHelper.getRequest(this.processInfoProvider.getObjectModel());
User user = null;
if ( req.getRemoteUser() != null ) {
user = this.createUser( req );
Modified: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/StandardApplicationManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/StandardApplicationManager.java?view=diff&rev=495903&r1=495902&r2=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/StandardApplicationManager.java (original)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/java/org/apache/cocoon/auth/impl/StandardApplicationManager.java Sat Jan 13 06:51:35 2007
@@ -18,6 +18,7 @@
*/
package org.apache.cocoon.auth.impl;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -25,42 +26,34 @@
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
-import org.apache.avalon.framework.CascadingRuntimeException;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.Constants;
-import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.Session;
-import org.apache.commons.lang.ObjectUtils;
import org.apache.cocoon.auth.Application;
import org.apache.cocoon.auth.ApplicationManager;
import org.apache.cocoon.auth.ApplicationUtil;
import org.apache.cocoon.auth.SecurityHandler;
import org.apache.cocoon.auth.User;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
/**
* This is the default implementation of the
* {@link org.apache.cocoon.auth.ApplicationManager}.
*
+ * This implementation is heavily tied to Spring. This has been done to make
+ * the configuration of the application manager easier.
+ *
* @version $Id$
-*/
+ */
public class StandardApplicationManager
- extends AbstractLogEnabled
- implements ApplicationManager,
- Contextualizable,
- Serviceable,
- ThreadSafe,
- Disposable {
+ implements ApplicationManager, BeanFactoryAware {
/** The key used to store the login information in the session. */
protected static final String LOGIN_INFO_KEY =
@@ -70,68 +63,60 @@
protected static final String APPLICATION_KEY_PREFIX =
StandardApplicationManager.class.getName() + "/app:";
- /** The component context. */
- protected Context context;
+ /** The prefix used to register applications. */
+ protected static final String APPLICATION_BEAN_NAME_PREFIX = Application.class.getName() + '/';
- /** The service manager. */
- protected ServiceManager manager;
+ /** The prefix used to register security handler. */
+ protected static final String SECURITYHANDLER_BEAN_NAME_PREFIX = SecurityHandler.class.getName() + '/';
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
- public void contextualize(final Context aContext) throws ContextException {
- this.context = aContext;
- try {
- final ServletContext servletContext = (ServletContext)aContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
- servletContext.setAttribute(StandardApplicationManager.class.getName(), this);
- } catch (ContextException ignore) {
- // we ignore this if we are not running inside a servlet environment
- }
+ /** By default we use the logger for this class. */
+ private Log logger = LogFactory.getLog(getClass());
+
+ /** The process info provider. */
+ protected ProcessInfoProvider processInfoProvider;
+
+ /** A map containing all applications. */
+ protected Map applications = Collections.synchronizedMap(new HashMap());
+
+ public Log getLogger() {
+ return this.logger;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(final ServiceManager aManager) throws ServiceException {
- this.manager = aManager;
+ public void setLogger(Log l) {
+ this.logger = l;
}
/**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
*/
- public void dispose() {
- this.manager = null;
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ this.processInfoProvider = (ProcessInfoProvider)factory.getBean(ProcessInfoProvider.ROLE);
+ // put map with applications into servlet context
+ final ServletContext servletContext = (ServletContext)factory.getBean(ServletContext.class.getName());
+ servletContext.setAttribute(StandardApplicationManager.class.getName(), this.applications);
}
/**
- * Get the application with the given name. This method tries to lookup the
- * applicating using the current sitemap service manager.
- * @param appName The name of the application.
- * @return The application object.
- * @throws Exception If the application can't be found.
+ * Return the application with the name.
*/
- protected Application getApplication(final String appName)
- throws Exception {
- final ServiceManager current = (ServiceManager)
- this.context.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
- Object o = current.lookup(Application.class.getName() + '/' + appName);
- if ( o == null ) {
- throw new ConfigurationException(
- "Application '" + appName + "' not found."
- );
+ protected Application getApplication(final String appName) {
+ final Application app = (Application) WebAppContextUtils.getCurrentWebApplicationContext().getBean(Application.class.getName() + '/' + appName);
+ if ( !this.applications.containsKey(appName) ) {
+ this.applications.put(appName, app);
}
- // to avoid messy release stuff later on, we just release the app now
- // as an application is thread safe this isn't really a problem
- current.release(o);
- return (Application)o;
+ return app;
+ }
+
+ protected String getKey(SecurityHandler handler) {
+ return handler.getId();
}
/**
- * @see org.apache.cocoon.auth.ApplicationManager#isLoggedIn(java.lang.String)
+ * @see org.apache.cocoon.auth.ApplicationManager#isLoggedIn(String)
*/
public boolean isLoggedIn(final String appName) {
Object appData = null;
- final Map objectModel = ContextHelper.getObjectModel( this.context );
+ final Map objectModel = this.processInfoProvider.getObjectModel();
final Request req = ObjectModelHelper.getRequest(objectModel);
final Session session = req.getSession(false);
if ( session != null ) {
@@ -152,8 +137,8 @@
application.userIsAccessing(user);
}
} catch (Exception ignore) {
- throw new CascadingRuntimeException("Unable to get application '"
- + appName + "'", ignore);
+ throw new RuntimeException("Unable to get application '"
+ + appName + "'", ignore);
}
}
}
@@ -162,12 +147,14 @@
}
/**
- * @see org.apache.cocoon.auth.ApplicationManager#login(java.lang.String, java.util.Map)
+ * @see org.apache.cocoon.auth.ApplicationManager#login(String, java.util.Map)
*/
public User login(final String appName, final Map loginContext) throws Exception {
- User user = null;
+ final Map objectModel = this.processInfoProvider.getObjectModel();
+ final Application application = this.getApplication(appName);
+ final String securityHandlerKey = this.getKey(application.getSecurityHandler());
- final Map objectModel = ContextHelper.getObjectModel( this.context );
+ User user = null;
// first check, if we are already logged in
if ( this.isLoggedIn(appName) ) {
@@ -176,21 +163,19 @@
final Request req = ObjectModelHelper.getRequest(objectModel);
Session session = req.getSession(false);
- final Application app = this.getApplication(appName);
LoginInfo info = null;
Map loginInfos = null;
if ( session != null ) {
// is the user already logged in on the security handler?
loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
- if ( loginInfos != null
- && loginInfos.containsKey(app.getSecurityHandler()) ) {
- info = (LoginInfo)loginInfos.get(app.getSecurityHandler());
+ if ( loginInfos != null && loginInfos.containsKey(securityHandlerKey)) {
+ info = (LoginInfo)loginInfos.get(securityHandlerKey);
user = info.user;
}
}
if ( user == null ) {
- user = app.getSecurityHandler().login(loginContext);
+ user = application.getSecurityHandler().login(loginContext);
if ( user != null ) {
// create new login info
session = req.getSession();
@@ -199,7 +184,7 @@
loginInfos = new HashMap();
}
info = new LoginInfo(user);
- loginInfos.put(app.getSecurityHandler().getId(), info);
+ loginInfos.put(securityHandlerKey, info);
}
}
@@ -213,21 +198,21 @@
objectModel.put(ApplicationManager.USER, user);
// set the application in the object model
- objectModel.put(ApplicationManager.APPLICATION, app);
+ objectModel.put(ApplicationManager.APPLICATION, application);
// set the application data in the session
Object data = ObjectUtils.NULL;
- if ( app.getApplicationStore() != null ) {
- data = app.getApplicationStore().loadApplicationData(user, app);
+ if ( application.getApplicationStore() != null ) {
+ data = application.getApplicationStore().loadApplicationData(user, application);
}
session.setAttribute(APPLICATION_KEY_PREFIX + appName, data);
objectModel.put(ApplicationManager.APPLICATION_DATA, data);
// notify the application about successful login
- app.userDidLogin(user, loginContext);
+ application.userDidLogin(user, loginContext);
// notify the application about accessing
- app.userIsAccessing(user);
+ application.userIsAccessing(user);
}
}
@@ -235,27 +220,21 @@
}
/**
- * @see org.apache.cocoon.auth.ApplicationManager#logout(java.lang.String, java.util.Map)
+ * @see org.apache.cocoon.auth.ApplicationManager#logout(String, java.util.Map)
*/
public void logout(final String appName, final Map logoutContext) {
- final Map objectModel = ContextHelper.getObjectModel( this.context );
+ final Map objectModel = this.processInfoProvider.getObjectModel();
final Request req = ObjectModelHelper.getRequest(objectModel);
final Session session = req.getSession(false);
if ( session != null ) {
- Application app;
-
- try {
- app = this.getApplication(appName);
- } catch (Exception ignore) {
- throw new CascadingRuntimeException("Unable to get application '"
- + appName + "'", ignore);
- }
-
// remove application data from session
session.removeAttribute(APPLICATION_KEY_PREFIX + appName);
+ final Application application = this.getApplication(appName);
+ final String securityHandlerKey = this.getKey(application.getSecurityHandler());
+
// remove application from object model
- if ( app.equals( ApplicationUtil.getApplication(objectModel) ) ) {
+ if ( application.equals( ApplicationUtil.getApplication(objectModel) ) ) {
objectModel.remove(ApplicationManager.APPLICATION);
objectModel.remove(ApplicationManager.APPLICATION_DATA);
objectModel.remove(ApplicationManager.USER);
@@ -267,19 +246,19 @@
// decrement logininfo counter
final Map loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
if ( loginInfos != null ) {
- final LoginInfo info = (LoginInfo)loginInfos.get(app.getSecurityHandler().getId());
+ final LoginInfo info = (LoginInfo)loginInfos.get(securityHandlerKey);
if ( info != null ) {
// notify the application
- app.userWillLogout(info.user, logoutContext);
+ application.userWillLogout(info.user, logoutContext);
info.decUsageCounter(appName);
if ( info.isUsed() ) {
session.setAttribute(LOGIN_INFO_KEY, loginInfos);
} else {
// logout from security handler
- app.getSecurityHandler().logout(logoutContext, info.user);
+ application.getSecurityHandler().logout(logoutContext, info.user);
// remove user info
- loginInfos.remove(app.getSecurityHandler().getId());
+ loginInfos.remove(securityHandlerKey);
if ( loginInfos.size() > 0 ) {
session.setAttribute(LOGIN_INFO_KEY, loginInfos);
} else {
@@ -308,9 +287,7 @@
public static void logoutFromAllApplications(final HttpSession session) {
final Map loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
if ( loginInfos != null ) {
- final StandardApplicationManager appManager =
- (StandardApplicationManager)session.getServletContext()
- .getAttribute(StandardApplicationManager.class.getName());
+ final Map applications = (Map)session.getServletContext().getAttribute(StandardApplicationManager.class.getName());
final Iterator i = loginInfos.values().iterator();
while ( i.hasNext() ) {
final LoginInfo info = (LoginInfo)i.next();
@@ -320,14 +297,16 @@
while ( appIter.hasNext() ) {
final String appName = (String)appIter.next();
try {
- final Application app = appManager.getApplication(appName);
- app.userWillLogout(info.getUser(), null);
+ final Application app = (Application)applications.get(appName);
+ app.userWillLogout(info.getUser(), Collections.EMPTY_MAP);
handler = app.getSecurityHandler();
} catch (Exception ignore) {
// we ignore this
}
}
- handler.logout(null, info.getUser());
+ if ( handler != null ) {
+ handler.logout(Collections.EMPTY_MAP, info.getUser());
+ }
}
}
}
Added: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-auth-sitemap-xconf
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-auth-sitemap-xconf?view=auto&rev=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-auth-sitemap-xconf (added)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/avalon/cocoon-auth-sitemap-xconf Sat Jan 13 06:51:35 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<map:components xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ <map:actions>
+ <map:action name="cauth-is-logged-in"
+ src="org.apache.cocoon.auth.acting.LoggedInAction"/>
+ <map:action name="cauth-login"
+ src="org.apache.cocoon.auth.acting.LoginAction"/>
+ <map:action name="cauth-logout"
+ src="org.apache.cocoon.auth.acting.LogoutAction"/>
+ </map:actions>
+</map:components>
Added: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml?view=auto&rev=495903
==============================================================================
--- cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml (added)
+++ cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml Sat Jan 13 06:51:35 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!--+
+ | This is the configuration for the standard application manager.
+ |
+ | @version $Id$
+ +-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
+
+ <!-- Define authentication manager -->
+ <bean name="org.apache.cocoon.auth.ApplicationManager"
+ class="org.apache.cocoon.auth.impl.StandardApplicationManager"
+ scope="singleton"/>
+
+</beans>
\ No newline at end of file
Propchange: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/blocks/cocoon-auth/cocoon-auth-impl/src/main/resources/META-INF/cocoon/spring/cocoon-auth.xml
------------------------------------------------------------------------------
svn:keywords = Id