upayavira 2003/09/20 14:22:33
Modified:
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
DefaultAuthenticationManager.java
src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/flow/javascript
auth.js
src/blocks/authentication-fw/samples flow.xmap sitemap.xmap
src/blocks/authentication-fw/samples/flow sample.js
Log:
Fixing the flow authentication sample further. It now works, but:
1) Going to 'login' page when already authenticated should take you to the
protected page, but doesn't.
2) Clicking 'protected' when not logged in gives an exception
Revision Changes Path
1.16 +28 -12
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultAuthenticationManager.java 12 Jul 2003 18:39:49 -0000 1.15
+++ DefaultAuthenticationManager.java 20 Sep 2003 21:22:33 -0000 1.16
@@ -307,18 +307,20 @@
UserHandler handler = this.getUserHandler( handlerName );
final boolean authenticated = ( handler != null );
if ( !authenticated ) {
- // create parameters
- SourceParameters parameters = config.getRedirectParameters();
- if (parameters == null) parameters = new SourceParameters();
- final Request request = this.getRequest();
- String resource = request.getRequestURI();
- if (request.getQueryString() != null) {
- resource += '?' + request.getQueryString();
+ if (redirector != null) {
+ // create parameters
+ SourceParameters parameters = config.getRedirectParameters();
+ if (parameters == null) parameters = new SourceParameters();
+ final Request request = this.getRequest();
+ String resource = request.getRequestURI();
+ if (request.getQueryString() != null) {
+ resource += '?' + request.getQueryString();
+ }
+
+ parameters.setSingleParameterValue("resource", resource);
+ final String redirectURI = config.getRedirectURI();
+ redirector.globalRedirect(false,
SourceUtil.appendParameters(redirectURI, parameters));
}
-
- parameters.setSingleParameterValue("resource", resource);
- final String redirectURI = config.getRedirectURI();
- redirector.globalRedirect(false,
SourceUtil.appendParameters(redirectURI, parameters));
} else {
// update state
RequestState state = new RequestState( handler, applicationName
);
@@ -329,6 +331,20 @@
return authenticated;
}
+ public String getForwardingURI(String handlerName) throws
ProcessingException {
+ HandlerConfiguration config = this.getHandlerConfiguration(
handlerName );
+ SourceParameters parameters = config.getRedirectParameters();
+ if (parameters == null) parameters = new SourceParameters();
+ final Request request = this.getRequest();
+ String resource = request.getRequestURI();
+ if (request.getQueryString() != null) {
+ resource += '?' + request.getQueryString();
+ }
+
+ parameters.setSingleParameterValue("resource", resource);
+ final String redirectURI = config.getRedirectURI();
+ return SourceUtil.appendParameters(redirectURI, parameters);
+ }
/* (non-Javadoc)
* @see
org.apache.cocoon.webapps.authentication.components.Manager#isAuthenticated(java.lang.String)
*/
1.3 +26 -4
cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/flow/javascript/auth.js
Index: auth.js
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/flow/javascript/auth.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- auth.js 17 Sep 2003 08:44:49 -0000 1.2
+++ auth.js 20 Sep 2003 21:22:33 -0000 1.3
@@ -52,13 +52,35 @@
WARNING - THIS IS EXPERIMENTAL STUFF!!! Use it at your own risk
*/
+
+function auth_checkAuthentication(handler, application) {
+
+ var authMgr = null;
+ var authenticated = false;
+ try {
+ authMgr =
cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE);
+
+ // do authentication
+ authenticated = authMgr.checkAuthentication(null, handler,
application);
+ if (authenticated) {
+ state = authMgr.getState();
+ map = state.getHandler().getContext().getContextInfo();
+ } else {
+ cocoon.redirectTo(authMgr.getForwardingURI(handler));
+ }
+ } finally {
+ cocoon.releaseComponent(authMgr);
+ }
+ return authenticated;
+}
+
function auth_isAuthenticated(handler) {
var authMgr = null;
try {
// ApplicationName, do we need it?
authMgr =
cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE);
- return authMgr.isAuthenticated(handler)!=null;
+ return authMgr.isAuthenticated(handler);
} finally {
cocoon.releaseComponent(authMgr);
}
@@ -68,9 +90,9 @@
var authParams = new
Packages.org.apache.excalibur.source.SourceParameters();
for (var name in params) {
-// if ((""+name.substring(0,10)) == "parameters_")) {
- authParams.setParameter(name, params[name]);
- // }
+ if (name.substring(0,10).equals("parameter_")) {
+ authParams.setParameter(name.substring(10), params[name]);
+ }
}
var authMgr = null;
1.2 +8 -10 cocoon-2.1/src/blocks/authentication-fw/samples/flow.xmap
Index: flow.xmap
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/samples/flow.xmap,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- flow.xmap 17 Sep 2003 08:44:49 -0000 1.1
+++ flow.xmap 20 Sep 2003 21:22:33 -0000 1.2
@@ -40,11 +40,9 @@
<!-- Simple login page -->
<!-- ================= -->
<map:match pattern="login">
- <!-- if we are already logged in, redirect to the protected document
-->
- <map:call function="protect">
- <map:parameter name="handler" value="flowdemohandler"/>
+ <map:call function="isLoggedIn">
+ <map:parameter name="protected-redirect" value="protected"/>
<map:parameter name="failure-internal" value="internal/login"/>
- <map:parameter name="protected-internal" value="protected"/>
</map:call>
</map:match>
@@ -55,9 +53,9 @@
<!-- try to login -->
<map:call function="login">
<map:parameter name="handler" value="flowdemohandler"/>
- <map:parameter name="name" value="{request-param:username}"/>
- <map:parameter name="protected-internal" value="protected"/>
- <map:parameter name="failure-internal" value="login"/>
+ <map:parameter name="parameter_name"
value="{request-param:username}"/>
+ <map:parameter name="protected-redirect" value="protected"/>
+ <map:parameter name="failure-redirect" value="login"/>
</map:call>
</map:match>
@@ -68,7 +66,7 @@
<map:call function="protect">
<map:parameter name="handler" value="flowdemohandler"/>
<map:parameter name="protected-internal"
value="internal/protected"/>
- <map:parameter name="failure-internal" value="login"/>
+ <map:parameter name="failure-redirect" value="login"/>
</map:call>
</map:match>
@@ -78,7 +76,7 @@
<map:match pattern="do-logout">
<map:call function="logout">
<map:parameter name="handler" value="flowdemohandler"/>
- <map:parameter name="failure-internal" value="login"/>
+ <map:parameter name="failure-redirect" value="login"/>
</map:call>
</map:match>
</map:pipeline>
1.7 +5 -1
cocoon-2.1/src/blocks/authentication-fw/samples/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/samples/sitemap.xmap,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sitemap.xmap 17 Sep 2003 08:44:49 -0000 1.6
+++ sitemap.xmap 20 Sep 2003 21:22:33 -0000 1.7
@@ -26,6 +26,10 @@
</map:component-configurations>
<map:pipeline>
+ <map:match pattern="flow/**">
+ <map:mount src="flow.xmap" uri-prefix="flow" check-reloads="true"/>
+ </map:match>
+
<map:match pattern="">
<map:redirect-to uri="login"/>
</map:match>
1.2 +14 -8
cocoon-2.1/src/blocks/authentication-fw/samples/flow/sample.js
Index: sample.js
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/authentication-fw/samples/flow/sample.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sample.js 17 Sep 2003 08:44:49 -0000 1.1
+++ sample.js 20 Sep 2003 21:22:33 -0000 1.2
@@ -1,13 +1,19 @@
cocoon.load("resource://org/apache/cocoon/webapps/authentication/flow/javascript/auth.js");
-// @TODO@ Get parameter_ removal working in auth.js
-// @TODO@ Get flow redirects to be session aware
-// @TODO@ Sort out error on clicking login when already logged in
+function isLoggedIn() {
+ var handler = cocoon.parameters["handler"];
+
+ if (auth_isAuthenticated(handler)) {
+ success();
+ } else {
+ failure();
+ }
+}
function protect() {
var handler = cocoon.parameters["handler"];
- if (auth_isAuthenticated(handler)) {
+ if (auth_checkAuthentication(handler,"")) {
success();
} else {
failure();
@@ -40,8 +46,8 @@
if (internal != null) {
cocoon.sendPage(internal);
- } else if (redirect+"" != "undefined") {
- cocoon.redirectTo(redirect); //THIS NEEDS TO BE A SESSION AWARE REDIRECT
+ } else if (redirect != null) {
+ cocoon.redirectTo(redirect);
} else {
throw new Error("No protected redirection parameter given");
}
@@ -54,8 +60,8 @@
if (internal != null) {
cocoon.sendPage(internal);
- } else if (typeof redirect+"" != "undefined") {
- cocoon.redirectTo(redirect); //THIS NEEDS TO BE A SESSION AWARE REDIRECT
+ } else if (redirect != null) {
+ cocoon.redirectTo(redirect);
} else {
// Why does this throw cause an error?
throw new Error("No failure redirection parameter given");