cziegeler 2003/04/27 07:45:04
Modified:
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user
UserHandler.java RequestState.java
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context
AuthenticationContext.java
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication
AuthenticationConstants.java
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
DefaultAuthenticationManager.java
Authenticator.java
Added:
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting
NewLogoutAction.java NewLoggedInAction.java
NewAuthAction.java NewLoginAction.java
Log:
Refactoring of authentication framework - continued
Revision Changes Path
1.2 +28 -10
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java
Index: UserHandler.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserHandler.java 27 Apr 2003 12:52:53 -0000 1.1
+++ UserHandler.java 27 Apr 2003 14:45:03 -0000 1.2
@@ -50,9 +50,13 @@
*/
package org.apache.cocoon.webapps.authentication.user;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.cocoon.ProcessingException;
+import
org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
import
org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
-import org.apache.cocoon.webapps.session.context.SessionContext;
+import
org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
/**
* The authentication Handler.
@@ -69,6 +73,12 @@
/** Are all apps loaded? */
private boolean appsLoaded = false;
+ /** The context */
+ private AuthenticationContext context;
+
+ /** Loaded List */
+ private List loadedApps = new ArrayList(3);
+
/**
* Create a new handler object.
*/
@@ -76,11 +86,6 @@
this.handler = handler;
}
- public void setApplicationsLoaded(boolean value)
- throws ProcessingException {
- this.appsLoaded = value;
- }
-
public boolean getApplicationsLoaded()
throws ProcessingException {
if ( this.handler.getApplications().isEmpty() ) {
@@ -93,11 +98,15 @@
/**
* Add a handler context
*/
- public SessionContext getContext() {
- // TODO
- return null;
+ public AuthenticationContext getContext() {
+ return this.context;
}
+ public AuthenticationContext createContext() {
+ this.context = new AuthenticationContext();
+ return this.context;
+ }
+
/**
* Get the handler name
*/
@@ -110,5 +119,14 @@
*/
public HandlerConfiguration getHandlerConfiguration() {
return this.handler;
+ }
+
+ public boolean isApplicationLoaded(ApplicationConfiguration appConf) {
+ return this.loadedApps.contains( appConf );
+ }
+
+ public void setApplicationIsLoaded(ApplicationConfiguration appConf) {
+ this.loadedApps.add( appConf );
+ this.appsLoaded = (this.loadedApps.size() ==
this.handler.getApplications().size());
}
}
1.2 +11 -2
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/RequestState.java
Index: RequestState.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/RequestState.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestState.java 27 Apr 2003 12:52:53 -0000 1.1
+++ RequestState.java 27 Apr 2003 14:45:03 -0000 1.2
@@ -52,8 +52,10 @@
import java.util.Map;
+import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.CocoonComponentManager;
import
org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
+import org.apache.excalibur.source.SourceResolver;
/**
@@ -92,9 +94,16 @@
/**
* Create a new handler object.
*/
- public RequestState(UserHandler handler, String app) {
+ public RequestState(UserHandler handler, String app, SourceResolver
resolver)
+ throws ProcessingException {
this.handler = handler;
this.application = app;
+ if ( this.application != null &&
!this.handler.getApplicationsLoaded()) {
+ ApplicationConfiguration conf = (ApplicationConfiguration)
this.handler.getHandlerConfiguration().getApplications().get(this.application);
+ if ( !this.handler.isApplicationLoaded( conf ) ) {
+ this.handler.createContext().loadApplicationXML( conf,
resolver );
+ }
+ }
}
public String getApplicationName() {
1.2 +218 -201
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java
Index: AuthenticationContext.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AuthenticationContext.java 27 Apr 2003 12:52:53 -0000 1.1
+++ AuthenticationContext.java 27 Apr 2003 14:45:03 -0000 1.2
@@ -50,14 +50,21 @@
*/
package org.apache.cocoon.webapps.authentication.context;
-import org.apache.avalon.framework.component.ComponentException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.SourceUtil;
-import
org.apache.cocoon.webapps.authentication.components.ApplicationHandler;
-import
org.apache.cocoon.webapps.authentication.components.AuthenticationManager;
-import org.apache.cocoon.webapps.authentication.components.Handler;
+import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
+import
org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
+import org.apache.cocoon.webapps.authentication.user.RequestState;
+import org.apache.cocoon.webapps.authentication.user.UserHandler;
import org.apache.cocoon.webapps.session.context.SessionContext;
+import org.apache.cocoon.webapps.session.context.SimpleSessionContext;
import org.apache.cocoon.xml.dom.DOMUtil;
import org.apache.excalibur.source.SourceParameters;
import org.apache.excalibur.source.SourceResolver;
@@ -69,11 +76,9 @@
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
-import java.io.IOException;
-import java.util.Map;
-
/**
* This is the implementation for the authentication context
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id$
*/
@@ -81,49 +86,22 @@
implements SessionContext {
private String name;
+ private UserHandler handler;
private SessionContext authContext;
- private String loadResource;
- private String saveResource;
- private String authLoadResource;
- private String authSaveResource;
- private SourceParameters loadResourceParameters;
- private SourceParameters saveResourceParameters;
- private SourceParameters authLoadResourceParameters;
- private SourceParameters authSaveResourceParameters;
private String handlerName;
private String applicationName;
- public AuthenticationContext(SessionContext context,
- String contextName,
- String handlerName,
- String applicationName,
- SourceResolver resolver,
- ComponentManager manager)
- throws ProcessingException {
- AuthenticationManager authManager = null;
- try {
- authManager =
(AuthenticationManager)manager.lookup(AuthenticationManager.ROLE);
- Handler handler = authManager.getHandler();
- this.name = contextName;
- this.authContext = context;
- this.handlerName = handlerName;
- this.applicationName = applicationName;
- this.authLoadResource = handler.getLoadResource();
- this.authSaveResource = handler.getSaveResource();
- this.authLoadResourceParameters =
handler.getLoadResourceParameters();
- this.authSaveResourceParameters =
handler.getSaveResourceParameters();
- if (this.applicationName != null) {
- ApplicationHandler appHandler =
(ApplicationHandler)handler.getApplications().get(this.applicationName);
- this.loadResource = appHandler.getLoadResource();
- this.saveResource = appHandler.getSaveResource();
- this.loadResourceParameters =
appHandler.getLoadResourceParameters();
- this.saveResourceParameters =
appHandler.getSaveResourceParameters();
- }
+ public AuthenticationContext() {
+ this.name = AuthenticationConstants.SESSION_CONTEXT_NAME;
- } catch (ComponentException ce) {
- throw new ProcessingException("Unable to lookup the resource
connector.", ce);
- } finally {
- manager.release(authManager);
+ RequestState state = RequestState.getState();
+ this.handler = state.getHandler();
+ this.handlerName = this.handler.getHandlerName();
+ this.applicationName = state.getApplicationName();
+ try {
+ this.authContext = new SimpleSessionContext();
+ } catch (ProcessingException pe) {
+ throw new CascadingRuntimeException("Unable to create simple
context.", pe);
}
}
@@ -132,6 +110,7 @@
* In addition a load and a save resource can be provided.
*/
public void setup(String value, String load, String save) {
+ // this is not used, everything is set in the constructor
}
/**
@@ -156,9 +135,9 @@
DocumentFragment frag = null;
- if (path.equals("/") == true) {
+ if ( path.equals("/") ) {
// get all: first authentication then application
- frag = this.authContext.getXML("/" + this.handlerName +
"/authentication");
+ frag = this.authContext.getXML("/authentication");
if (frag != null) {
// now add root node authentication
@@ -174,12 +153,12 @@
if (this.applicationName != null) {
// join
- DocumentFragment appFrag = this.authContext.getXML("/" +
this.handlerName + "/applications/" + this.applicationName);
+ DocumentFragment appFrag =
this.authContext.getXML("/applications/" + this.applicationName);
if (appFrag != null) {
// now add root node application
Node root =
appFrag.getOwnerDocument().createElementNS(null, "application");
Node child;
- while (appFrag.hasChildNodes() == true) {
+ while (appFrag.hasChildNodes() ) {
child = appFrag.getFirstChild();
appFrag.removeChild(child);
root.appendChild(child);
@@ -189,7 +168,7 @@
if (frag == null) {
frag = appFrag;
} else {
- while (appFrag.hasChildNodes() == true) {
+ while (appFrag.hasChildNodes() ) {
child = appFrag.getFirstChild();
appFrag.removeChild(child);
child =
frag.getOwnerDocument().importNode(child, true);
@@ -199,73 +178,27 @@
}
}
- } else if (path.startsWith("/authentication") == true) {
- frag = this.authContext.getXML("/" + this.handlerName + path);
+ } else if (path.startsWith("/authentication") ) {
+ frag = this.authContext.getXML("/" + path);
- } else if (path.equals("/application") == true ||
path.startsWith("/application/") == true) {
+ } else if (path.equals("/application") ||
path.startsWith("/application/") ) {
if (this.applicationName != null) {
String appPath;
- if (path.equals("/application") == true) {
+ if (path.equals("/application")) {
appPath ="/";
} else {
appPath = path.substring("/application".length());
}
- frag = this.authContext.getXML("/" + this.handlerName +
"/applications/" + this.applicationName + appPath);
+ frag = this.authContext.getXML("/applications/" +
this.applicationName + appPath);
}
} else {
- frag = this.authContext.getXML("/" + this.handlerName + path);
+ frag = this.authContext.getXML("/" + path);
}
return frag;
}
/**
- * Convert the authentication XML of a handler to parameters.
- * The XML is flat and consists of elements which all have exactly one
text node:
- * <parone>value_one<parone>
- * <partwo>value_two<partwo>
- * A parameter can occur more than once with different values.
- */
- public void addParametersFromAuthenticationXML(String handlerName,
- String path,
- SourceParameters
parameters)
- throws ProcessingException {
- final DocumentFragment fragment = this.authContext.getXML("/" +
handlerName + "/authentication" + path);
- if (fragment != null) {
- NodeList childs = fragment.getChildNodes();
- if (childs != null) {
- Node current;
- for(int i = 0; i < childs.getLength(); i++) {
- current = childs.item(i);
-
- // only element nodes
- if (current.getNodeType() == Node.ELEMENT_NODE) {
- current.normalize();
- NodeList valueChilds = current.getChildNodes();
- String key;
- StringBuffer valueBuffer;
- String value;
-
- key = current.getNodeName();
- valueBuffer = new StringBuffer();
- for(int m = 0; m < valueChilds.getLength(); m++) {
- current = valueChilds.item(m); // attention:
current is reused here!
- if (current.getNodeType() == Node.TEXT_NODE) {
// only text nodes
- if (valueBuffer.length() > 0)
valueBuffer.append(' ');
- valueBuffer.append(current.getNodeValue());
- }
- }
- value = valueBuffer.toString().trim();
- if (key != null && value != null && value.length() >
0) {
- parameters.setParameter(key, value);
- }
- }
- }
- }
- }
- }
-
- /**
* Set a document fragment at the given path.
* The implementation of this method is context specific.
* Usually all children of the node specified by the path are removed
@@ -277,7 +210,7 @@
if (path == null) {
throw new ProcessingException("setXML: Path is required");
}
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/")) path = '/' + path;
if ( path.equals("/") ) {
// set all is not allowed with "/"
@@ -286,10 +219,10 @@
} else if ( path.startsWith("/authentication") ) {
this.cleanParametersCache();
- this.authContext.setXML('/' + this.handlerName + path, fragment);
+ this.authContext.setXML('/' + path, fragment);
- } else if (path.equals("/application") == true
- || path.startsWith("/application/") == true) {
+ } else if (path.equals("/application")
+ || path.startsWith("/application/") ) {
if (this.applicationName == null) {
throw new ProcessingException("Application is required");
@@ -300,26 +233,14 @@
} else {
appPath = path.substring("/application".length());
}
- this.authContext.setXML("/" + this.handlerName +
"/applications/" + this.applicationName + appPath, fragment);
+ this.authContext.setXML("/applications/" + this.applicationName
+ appPath, fragment);
} else {
- this.authContext.setXML("/" + this.handlerName + path, fragment);
+ this.authContext.setXML("/" + path, fragment);
}
}
/**
- * Set the XML for an application
- */
- public void setApplicationXML(String setHandlerName,
- String setApplicationName,
- String path,
- DocumentFragment fragment)
- throws ProcessingException {
- path = "/" + setHandlerName + "/applications/" + setApplicationName
+ path;
- this.authContext.setXML(path, fragment);
- }
-
- /**
* Append a document fragment at the given path.
* The implementation of this method is context specific.
* Usually the children of the fragment are appended as new children of
the
@@ -332,7 +253,7 @@
if (path == null) {
throw new ProcessingException("appendXML: Path is required");
}
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/") ) path = '/' + path;
if ( path.equals("/") ) {
// set all is not allowed with "/"
@@ -341,24 +262,24 @@
} else if ( path.startsWith("/authentication") ) {
this.cleanParametersCache();
- this.authContext.appendXML('/' + this.handlerName + path,
fragment);
+ this.authContext.appendXML('/' + path, fragment);
- } else if (path.equals("/application") == true
- || path.startsWith("/application/") == true) {
+ } else if (path.equals("/application")
+ || path.startsWith("/application/") ) {
if (this.applicationName == null) {
throw new ProcessingException("Application is required");
}
String appPath;
- if (path.equals("/application") == true) {
+ if (path.equals("/application") ) {
appPath = "/";
} else {
appPath = path.substring("/application".length());
}
- this.authContext.appendXML("/" + this.handlerName +
"/applications/" + this.applicationName + appPath, fragment);
+ this.authContext.appendXML("/applications/" +
this.applicationName + appPath, fragment);
} else {
- this.authContext.appendXML("/" + this.handlerName + path,
fragment);
+ this.authContext.appendXML("/" + path, fragment);
}
}
@@ -373,31 +294,31 @@
if (path == null) {
throw new ProcessingException("removeXML: Path is required");
}
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/") ) path = '/' + path;
- if (path.equals("/") == true) {
+ if (path.equals("/") ) {
this.cleanParametersCache();
- this.authContext.removeXML("/" + this.handlerName);
+ this.authContext.removeXML("/");
- } else if (path.startsWith("/authentication") == true) {
+ } else if (path.startsWith("/authentication") ) {
this.cleanParametersCache();
- this.authContext.removeXML("/" + this.handlerName + path);
+ this.authContext.removeXML("/" + path);
- } else if (path.equals("/application") == true
- || path.startsWith("/application/") == true) {
+ } else if (path.equals("/application")
+ || path.startsWith("/application/") ) {
if (this.applicationName == null) {
throw new ProcessingException("removeXML: Application is
required for path " + path);
}
String appPath;
- if (path.equals("/application") == true) {
+ if (path.equals("/application") ) {
appPath = "/";
} else {
appPath = path.substring("/application".length());
}
- this.authContext.removeXML("/" + this.handlerName +
"/applications/" + this.applicationName + appPath);
+ this.authContext.removeXML("/applications/" +
this.applicationName + appPath);
} else {
- this.authContext.removeXML("/" + this.handlerName + path);
+ this.authContext.removeXML("/" + path);
}
}
@@ -490,36 +411,36 @@
if (path == null) {
throw new ProcessingException("streamXML: Path is required");
}
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/") ) path = '/' + path;
- if (path.equals("/") == true) {
+ if (path.equals("/") ) {
// get all: first authentication then application
contentHandler.startElement(null, "authentication",
"authentication", new AttributesImpl());
- this.authContext.streamXML('/' + this.handlerName +
"/authentication", contentHandler, lexicalHandler);
+ this.authContext.streamXML("/authentication", contentHandler,
lexicalHandler);
contentHandler.endElement(null, "authentication",
"authentication");
if (this.applicationName != null) {
contentHandler.startElement(null, "application",
"application", new AttributesImpl());
- this.authContext.streamXML('/' + this.handlerName +
"/applications/" + this.applicationName, contentHandler, lexicalHandler);
+ this.authContext.streamXML("/applications/" +
this.applicationName, contentHandler, lexicalHandler);
contentHandler.endElement(null, "application",
"application");
}
return true;
- } else if (path.startsWith("/authentication") == true) {
- return this.authContext.streamXML('/' + this.handlerName + path,
contentHandler, lexicalHandler);
+ } else if (path.startsWith("/authentication") ) {
+ return this.authContext.streamXML('/' + path, contentHandler,
lexicalHandler);
- } else if (path.equals("/application") == true ||
path.startsWith("/application/") == true) {
+ } else if (path.equals("/application") ||
path.startsWith("/application/") ) {
if (this.applicationName != null) {
String appPath;
- if (path.equals("/application") == true) {
+ if (path.equals("/application") ) {
appPath ="/";
} else {
appPath = path.substring("/application".length());
}
- return this.authContext.streamXML('/' + this.handlerName +
"/applications/" + this.applicationName + appPath, contentHandler,
lexicalHandler);
+ return this.authContext.streamXML("/applications/" +
this.applicationName + appPath, contentHandler, lexicalHandler);
}
} else {
- return this.authContext.streamXML('/' + this.handlerName + path,
contentHandler, lexicalHandler);
+ return this.authContext.streamXML('/' + path, contentHandler,
lexicalHandler);
}
return false;
}
@@ -535,9 +456,9 @@
SourceResolver resolver,
ComponentManager manager)
throws SAXException, ProcessingException, IOException {
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/") ) path = '/' + path;
- if (path.equals("/") == true) {
+ if (path.equals("/") ) {
// load all: first authentication then application
this.loadAuthenticationXML("/authentication",
parameters,
@@ -587,9 +508,9 @@
SourceResolver resolver,
ComponentManager manager)
throws SAXException, ProcessingException, IOException {
- if (path.startsWith("/") == false) path = '/' + path;
+ if (!path.startsWith("/") ) path = '/' + path;
- if (path.equals("/") == true) {
+ if (path.equals("/") ) {
// save all: first authentication then application
this.saveAuthenticationXML("/authentication",
parameters,
@@ -633,17 +554,7 @@
*/
private void cleanParametersCache()
throws ProcessingException {
- this.authContext.setAttribute("cachedparameters_" +
this.handlerName, null);
- this.authContext.setAttribute("cachedmap_" + this.handlerName, null);
- }
-
- /**
- * Clean the parameters cache
- */
- public void cleanParametersCache(String handlerName)
- throws ProcessingException {
- this.authContext.setAttribute("cachedparameters_" + handlerName,
null);
- this.authContext.setAttribute("cachedmap_" + handlerName, null);
+ this.authContext.setAttribute("cachedmap" , null);
}
/**
@@ -655,7 +566,10 @@
SourceResolver resolver,
ComponentManager manager)
throws ProcessingException {
- if (this.authSaveResource == null) {
+ String authSaveResource =
this.handler.getHandlerConfiguration().getSaveResource();
+ SourceParameters authSaveResourceParameters =
this.handler.getHandlerConfiguration().getSaveResourceParameters();
+
+ if (authSaveResource == null) {
throw new ProcessingException("The context " + this.name + "
does not support saving.");
}
@@ -667,15 +581,14 @@
}
if (parameters != null) {
parameters = (SourceParameters)parameters.clone();
- parameters.add(this.authSaveResourceParameters);
- } else if (this.authSaveResourceParameters != null) {
- parameters =
(SourceParameters)this.authSaveResourceParameters.clone();
+ parameters.add(authSaveResourceParameters);
+ } else if (authSaveResourceParameters != null) {
+ parameters =
(SourceParameters)authSaveResourceParameters.clone();
}
parameters = this.createParameters(parameters,
- this.handlerName,
path,
- null);
- SourceUtil.writeDOM(this.authSaveResource,
+ false);
+ SourceUtil.writeDOM(authSaveResource,
null,
parameters,
fragment,
@@ -693,7 +606,10 @@
SourceResolver resolver,
ComponentManager manager)
throws ProcessingException {
- if (this.authLoadResource == null) {
+ String authLoadResource =
this.handler.getHandlerConfiguration().getLoadResource();
+ SourceParameters authLoadResourceParameters =
this.handler.getHandlerConfiguration().getLoadResourceParameters();
+
+ if (authLoadResource == null) {
throw new ProcessingException("The context " + this.name + "
does not support loading.");
}
@@ -701,17 +617,16 @@
if (parameters != null) {
parameters = (SourceParameters)parameters.clone();
- parameters.add(this.authLoadResourceParameters);
- } else if (this.authLoadResourceParameters != null) {
- parameters =
(SourceParameters)this.authLoadResourceParameters.clone();
+ parameters.add(authLoadResourceParameters);
+ } else if (authLoadResourceParameters != null) {
+ parameters =
(SourceParameters)authLoadResourceParameters.clone();
}
parameters = this.createParameters(parameters,
- this.handlerName,
path,
- null);
+ false);
DocumentFragment frag;
- frag = SourceUtil.readDOM(this.authLoadResource,
+ frag = SourceUtil.readDOM(authLoadResource,
null,
parameters,
resolver);
@@ -730,7 +645,10 @@
SourceResolver resolver,
ComponentManager manager)
throws ProcessingException {
- if (this.loadResource == null) {
+ final ApplicationConfiguration conf =
(ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get(
this.applicationName );
+ String loadResource = conf.getLoadResource();
+ SourceParameters loadResourceParameters =
conf.getLoadResourceParameters();
+ if (loadResource == null) {
throw new ProcessingException("The context " + this.name + "
does not support loading.");
}
// synchronized
@@ -738,16 +656,15 @@
if (parameters != null) {
parameters = (SourceParameters)parameters.clone();
- parameters.add(this.loadResourceParameters);
- } else if (this.loadResourceParameters != null) {
- parameters =
(SourceParameters)this.loadResourceParameters.clone();
+ parameters.add(loadResourceParameters);
+ } else if (loadResourceParameters != null) {
+ parameters =
(SourceParameters)loadResourceParameters.clone();
}
parameters = this.createParameters(parameters,
- this.handlerName,
path,
- this.applicationName);
+ true);
DocumentFragment fragment;
- fragment = SourceUtil.readDOM(this.loadResource,
+ fragment = SourceUtil.readDOM(loadResource,
null,
parameters,
resolver);
@@ -766,7 +683,11 @@
SourceResolver resolver,
ComponentManager manager)
throws ProcessingException {
- if (this.saveResource == null) {
+ final ApplicationConfiguration conf =
(ApplicationConfiguration)this.handler.getHandlerConfiguration().getApplications().get(
this.applicationName );
+ String saveResource = conf.getSaveResource();
+ SourceParameters saveResourceParameters =
conf.getSaveResourceParameters();
+
+ if (saveResource == null) {
throw new ProcessingException("The context " + this.name + "
does not support saving.");
}
// synchronized
@@ -774,21 +695,20 @@
if (parameters != null) {
parameters = (SourceParameters)parameters.clone();
- parameters.add(this.saveResourceParameters);
- } else if (this.saveResourceParameters != null) {
- parameters =
(SourceParameters)this.saveResourceParameters.clone();
+ parameters.add(saveResourceParameters);
+ } else if (saveResourceParameters != null) {
+ parameters =
(SourceParameters)saveResourceParameters.clone();
}
parameters = this.createParameters(parameters,
- this.handlerName,
path,
- this.applicationName);
+ true);
DocumentFragment fragment = this.getXML("/application" + path);
if (fragment == null) {
// create empty fake fragment
fragment = DOMUtil.createDocument().createDocumentFragment();
}
- SourceUtil.writeDOM(this.saveResource,
+ SourceUtil.writeDOM(saveResource,
null,
parameters,
fragment,
@@ -802,29 +722,126 @@
/**
* Build parameters for loading and saving of application data
*/
- public SourceParameters createParameters(SourceParameters parameters,
- String myHandler,
- String path,
- String appName)
+ private SourceParameters createParameters(SourceParameters parameters,
+ String path,
+ boolean appendAppInfo)
throws ProcessingException {
if (parameters == null) parameters = new SourceParameters();
// add all elements from inside the handler data
- this.addParametersFromAuthenticationXML(myHandler,
- "/data",
+ this.addParametersFromAuthenticationXML("/data",
parameters);
// add all top level elements from authentication
- this.addParametersFromAuthenticationXML(myHandler,
- "",
+ this.addParametersFromAuthenticationXML("",
parameters);
// add application and path
- parameters.setSingleParameterValue("handler", myHandler);
- if (appName != null)
parameters.setSingleParameterValue("application", appName);
+ parameters.setSingleParameterValue("handler", this.handlerName);
+ if ( appendAppInfo ) {
+ if (this.applicationName != null)
parameters.setSingleParameterValue("application", this.applicationName);
+ }
if (path != null) parameters.setSingleParameterValue("path", path);
return parameters;
+ }
+
+ /**
+ * Convert the authentication XML of a handler to parameters.
+ * The XML is flat and consists of elements which all have exactly one
text node:
+ * <parone>value_one<parone>
+ * <partwo>value_two<partwo>
+ * A parameter can occur more than once with different values.
+ */
+ private void addParametersFromAuthenticationXML(String path,
+ SourceParameters
parameters)
+ throws ProcessingException {
+ final DocumentFragment fragment =
this.authContext.getXML("/authentication" + path);
+ if (fragment != null) {
+ NodeList childs = fragment.getChildNodes();
+ if (childs != null) {
+ Node current;
+ for(int i = 0; i < childs.getLength(); i++) {
+ current = childs.item(i);
+
+ // only element nodes
+ if (current.getNodeType() == Node.ELEMENT_NODE) {
+ current.normalize();
+ NodeList valueChilds = current.getChildNodes();
+ String key;
+ StringBuffer valueBuffer;
+ String value;
+
+ key = current.getNodeName();
+ valueBuffer = new StringBuffer();
+ for(int m = 0; m < valueChilds.getLength(); m++) {
+ current = valueChilds.item(m); // attention:
current is reused here!
+ if (current.getNodeType() == Node.TEXT_NODE) {
// only text nodes
+ if (valueBuffer.length() > 0)
valueBuffer.append(' ');
+ valueBuffer.append(current.getNodeValue());
+ }
+ }
+ value = valueBuffer.toString().trim();
+ if (key != null && value != null && value.length() >
0) {
+ parameters.setParameter(key, value);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Map getContextInfo()
+ throws ProcessingException {
+ Map map = (Map)this.authContext.getAttribute( "cachedmap" );
+ if (map == null) {
+ map = new HashMap(20);
+ Parameters pars = this.createParameters(null, null,
false).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) map.put(key, value);
+ }
+ }
+ this.authContext.setAttribute("cachedmap", map);
+ }
+ return map;
+ }
+
+ /**
+ * Load XML of an application
+ */
+ public void loadApplicationXML(ApplicationConfiguration appConf,
+ SourceResolver resolver)
+ throws ProcessingException {
+ String loadResource = appConf.getLoadResource();
+ SourceParameters loadResourceParameters =
appConf.getLoadResourceParameters();
+ if ( !this.handler.isApplicationLoaded(appConf) && loadResource !=
null ) {
+ synchronized (this.authContext) {
+
+ SourceParameters parameters;
+ if (loadResourceParameters != null) {
+ parameters =
(SourceParameters)loadResourceParameters.clone();
+ } else {
+ parameters = new SourceParameters();
+ }
+ parameters = this.createParameters(parameters,
+ null,
+ true);
+ DocumentFragment fragment;
+ fragment = SourceUtil.readDOM(loadResource,
+ null,
+ parameters,
+ resolver);
+ this.setXML("/", fragment);
+
+ } // end synchronized
+ }
+ this.handler.setApplicationIsLoaded(appConf);
}
}
1.1
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLogoutAction.java
Index: NewLogoutAction.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.webapps.authentication.acting;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
import org.apache.cocoon.webapps.authentication.components.Manager;
import org.apache.cocoon.webapps.authentication.user.RequestState;
/**
* This action logs the current user out of a given handler
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: NewLogoutAction.java,v 1.1 2003/04/27 14:45:03 cziegeler
Exp $
*/
public final class NewLogoutAction
extends ComposerAction
implements ThreadSafe {
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters par)
throws Exception {
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("BEGIN act resolver="+resolver+
", objectModel="+objectModel+
", source="+source+
", par="+par);
}
int mode;
final String modeString = par.getParameter("mode",
"if-not-authenticated");
if ( modeString.equals("if-not-authenticated") ) {
mode = AuthenticationConstants.LOGOUT_MODE_IF_NOT_AUTHENTICATED;
} else if ( modeString.equalsIgnoreCase("if-unused") ) {
mode = AuthenticationConstants.LOGOUT_MODE_IF_UNUSED;
} else if ( modeString.equalsIgnoreCase("immediately") ) {
mode = AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY;
} else {
throw new ProcessingException("Unknown mode " + modeString);
}
// logout
Manager authManager = null;
try {
RequestState state = RequestState.getState();
authManager = (Manager) this.manager.lookup(Manager.ROLE);
final String handlerName = par.getParameter("handler",
(state == null ?
null : state.getHandlerName()));
if ( null == handlerName )
throw new ProcessingException("LogoutAction requires at least
the handler parameter.");
authManager.logout( handlerName , mode );
} finally {
this.manager.release( (Component)authManager );
}
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("END act map={}");
}
return EMPTY_MAP;
}
}
1.1
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoggedInAction.java
Index: NewLoggedInAction.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.webapps.authentication.acting;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.authentication.components.Manager;
import org.apache.cocoon.webapps.authentication.user.RequestState;
/**
* This action tests if the user is logged in for a given handler.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: NewLoggedInAction.java,v 1.1 2003/04/27 14:45:03
cziegeler Exp $
*/
public final class NewLoggedInAction
extends ComposerAction
implements ThreadSafe {
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters par)
throws Exception {
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("BEGIN act resolver="+resolver+
", objectModel="+objectModel+
", source="+source+
", par="+par);
}
Map map = null;
String handlerName = par.getParameter("handler", null);
Manager authManager = null;
try {
authManager = (Manager) this.manager.lookup(Manager.ROLE);
if (authManager.isAuthenticated(handlerName) ) {
RequestState state = RequestState.getState();
map = state.getHandler().getContext().getContextInfo();
}
} finally {
this.manager.release( (Component)authManager);
}
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("END act map="+map);
}
return map;
}
}
1.1
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewAuthAction.java
Index: NewAuthAction.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.webapps.authentication.acting;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.authentication.components.Manager;
import org.apache.cocoon.webapps.authentication.user.RequestState;
/**
* This is the authentication action
* This action contains the complete configuration for the authentication
* Manager. During configuration the AuthenticationManager class gets this
* configuration to configure the instances properly.
* The main task of this action is to check if the user is authenticated
* using a handler. If not a redirect takes place.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: NewAuthAction.java,v 1.1 2003/04/27 14:45:03 cziegeler
Exp $
*/
public final class NewAuthAction
extends ComposerAction
implements ThreadSafe {
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters par)
throws Exception {
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("BEGIN act resolver="+resolver+
", objectModel="+objectModel+
", source="+source+
", par="+par);
}
String handlerName = null;
String applicationName = null;
Manager authManager = null;
Map map = null;
try {
handlerName = par.getParameter("handler", null);
applicationName = par.getParameter("application", null);
authManager = (Manager) this.manager.lookup( Manager.ROLE );
// do authentication
if ( !authManager.checkAuthentication(redirector, handlerName,
applicationName) ) {
// All events are ignored
// the sitemap.xsl ensures that only the redirect is processed
} else {
RequestState state = RequestState.getState();
map = state.getHandler().getContext().getContextInfo();
}
} finally {
this.manager.release( (Component)authManager );
}
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("END act map="+map);
}
return map;
}
}
1.1
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/acting/NewLoginAction.java
Index: NewLoginAction.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.webapps.authentication.acting;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.ComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.authentication.components.Manager;
import org.apache.cocoon.webapps.authentication.user.RequestState;
import org.apache.excalibur.source.SourceParameters;
/**
* This action logs the current user into a given handler. If the
* authentication is successful, a map is returned with the authentication
* information and a session is created (if it not already exists).
* If the authentication is not successful, the error information is stored
* into the temporary context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: NewLoginAction.java,v 1.1 2003/04/27 14:45:03 cziegeler
Exp $
*/
public final class NewLoginAction
extends ComposerAction
implements ThreadSafe {
public Map act(Redirector redirector,
SourceResolver resolver,
Map objectModel,
String source,
Parameters par)
throws Exception {
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("BEGIN act resolver="+resolver+
", objectModel="+objectModel+
", source="+source+
", par="+par);
}
final String handlerName = par.getParameter("handler", null);
if ( handlerName == null ) {
throw new ProcessingException("LoginAction requires at least the
handler parameter.");
}
// build authentication parameters
SourceParameters authenticationParameters = new SourceParameters();
String[] enum = par.getNames();
if (enum != null) {
for(int i = 0; i < enum.length; i++) {
final String key = enum[i];
if ( key.startsWith("parameter_") ) {
authenticationParameters.setParameter(
key.substring("parameter_".length()),
par.getParameter(key));
}
}
}
Map map = null;
// authenticate
Manager authManager = null;
try {
authManager = (Manager) this.manager.lookup(Manager.ROLE);
if ( authManager.login( handlerName,
par.getParameter("application", null),
authenticationParameters)) {
// success
RequestState state = RequestState.getState();
map = state.getHandler().getContext().getContextInfo();
}
} finally {
this.manager.release( (Component)authManager);
}
if (this.getLogger().isDebugEnabled() ) {
this.getLogger().debug("END act map="+map);
}
return map;
}
}
1.3 +3 -2
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationConstants.java
Index: AuthenticationConstants.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/AuthenticationConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AuthenticationConstants.java 27 Apr 2003 12:52:53 -0000 1.2
+++ AuthenticationConstants.java 27 Apr 2003 14:45:04 -0000 1.3
@@ -59,7 +59,8 @@
*/
public interface AuthenticationConstants {
- /** The name of the session attribute storing the context */
+ /** The name of the session attribute storing the context
+ * FIXME - Remove me*/
String SESSION_ATTRIBUTE_CONTEXT_NAME =
"org.apache.cocoon.webapps.authentication.SessionContext";
/** The name of the authentication context. */
1.6 +13 -5
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java
Index: DefaultAuthenticationManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultAuthenticationManager.java 27 Apr 2003 12:52:53 -0000 1.5
+++ DefaultAuthenticationManager.java 27 Apr 2003 14:45:04 -0000 1.6
@@ -69,7 +69,6 @@
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
-import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
import
org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
import
org.apache.cocoon.webapps.authentication.context.AuthenticationContextProvider;
@@ -78,6 +77,7 @@
import org.apache.cocoon.webapps.authentication.user.UserState;
import org.apache.cocoon.webapps.session.components.SessionManager;
import org.apache.excalibur.source.SourceParameters;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
/**
@@ -102,6 +102,9 @@
/** The authenticator used to authenticate a user */
private Authenticator authenticator;
+ /** The Source Resolver */
+ private SourceResolver resolver;
+
/** Init the class,
* add the provider for the authentication context
*/
@@ -235,7 +238,7 @@
this.updateUserState();
// update RequestState
- RequestState state = new RequestState( handler, applicationName
);
+ RequestState state = new RequestState( handler, applicationName,
this.resolver );
RequestState.setState( state );
}
@@ -271,7 +274,7 @@
redirector.globalRedirect(false,
SourceUtil.appendParameters(redirectURI, parameters));
} else {
// update state
- RequestState state = new RequestState( handler, applicationName
);
+ RequestState state = new RequestState( handler, applicationName,
this.resolver );
RequestState.setState( state );
}
@@ -341,6 +344,7 @@
this.authenticator = new Authenticator();
this.authenticator.enableLogging( this.getLogger() );
this.authenticator.service( this.manager );
+ this.resolver = (SourceResolver)
this.manager.lookup(SourceResolver.ROLE);
}
/* (non-Javadoc)
@@ -351,7 +355,11 @@
this.authenticator.dispose();
this.authenticator = null;
}
- this.manager = null;
+ if ( this.manager != null) {
+ this.manager.release( this.resolver );
+ this.manager = null;
+ this.resolver = null;
+ }
}
}
1.3 +2 -5
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java
Index: Authenticator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Authenticator.java 27 Apr 2003 12:52:53 -0000 1.2
+++ Authenticator.java 27 Apr 2003 14:45:04 -0000 1.3
@@ -257,14 +257,11 @@
while ( applications.hasNext() ) {
ApplicationConfiguration appHandler =
(ApplicationConfiguration)applications.next();
if ( !appHandler.getLoadOnDemand() ) {
- // FIXME - loadApplication
-
//this.loadApplicationXML((SessionContextImpl)this.getSessionManager().getContext(AuthenticationConstants.SESSION_CONTEXT_NAME),
- // appHandler, "/");
+ handler.getContext().loadApplicationXML(
appHandler, this.resolver );
} else {
loaded = false;
}
}
- handler.setApplicationsLoaded( loaded );
} // end sync
}