Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 56085 invoked from network); 17 Sep 2003 08:44:51 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 17 Sep 2003 08:44:51 -0000 Received: (qmail 53159 invoked by uid 500); 17 Sep 2003 08:44:26 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 53000 invoked by uid 500); 17 Sep 2003 08:44:25 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 52989 invoked by uid 500); 17 Sep 2003 08:44:25 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 52984 invoked from network); 17 Sep 2003 08:44:25 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 17 Sep 2003 08:44:25 -0000 Received: (qmail 56075 invoked by uid 1673); 17 Sep 2003 08:44:49 -0000 Date: 17 Sep 2003 08:44:49 -0000 Message-ID: <20030917084449.56074.qmail@minotaur.apache.org> From: upayavira@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/blocks/authentication-fw/samples/flow sample.js X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N upayavira 2003/09/17 01:44:49 Modified: src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/flow/javascript auth.js src/blocks/authentication-fw/samples sitemap.xmap Added: src/blocks/authentication-fw/samples flow.xmap src/blocks/authentication-fw/samples/flow sample.js Log: Partially working sample using flow and authentication framework Revision Changes Path 1.2 +51 -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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- auth.js 18 Aug 2003 14:08:05 -0000 1.1 +++ auth.js 17 Sep 2003 08:44:49 -0000 1.2 @@ -52,14 +52,61 @@ WARNING - THIS IS EXPERIMENTAL STUFF!!! Use it at your own risk */ - -function isAuthenticated(handler) { +function auth_isAuthenticated(handler) { var authMgr = null; try { - authMgr = cocoon.getComponent(Packagesorg.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE); + // ApplicationName, do we need it? + authMgr = cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE); - return authMgr.isAuthenticated(handler); + return authMgr.isAuthenticated(handler)!=null; + } finally { + cocoon.releaseComponent(authMgr); + } +} + +function auth_login(handler, application, params) { + + 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]); + // } + } + + var authMgr = null; + try { + authMgr = cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE); + return authMgr.login( handler, application, authParams) != null; } finally { cocoon.releaseComponent(authMgr); } } + +function auth_logout(handler, modeString) { + var mode; + if ( modeString == null | modeString == "" || modeString == "if-not-authenticated" ) { + mode = Packages.org.apache.cocoon.webapps.authentication.AuthenticationConstants.LOGOUT_MODE_IF_NOT_AUTHENTICATED; + } else if ( modeString == "if-unused" ) { + mode = Packages.org.apache.cocoon.webapps.authentication.AuthenticationConstants.LOGOUT_MODE_IF_UNUSED; + } else if ( modeString == "immediately" ) { + mode = Packages.org.apache.cocoon.webapps.authentication.AuthenticationConstants.LOGOUT_MODE_IMMEDIATELY; + } else { + throw new Error("Unknown mode"); // " + modeString); + } + + var authMgr = null; + try { + authMgr = cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE); + var state = authMgr.getState(); + + if (handler == null && state!=null) { + handler = state.getHandlerName(); + } + + if ( null == handler ) + throw new Error("LogoutAction requires at least the handler parameter."); + authMgr.logout( handler, mode ); + } finally { + cocoon.releaseComponent(authMgr); + } +} \ No newline at end of file 1.6 +6 -2 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- sitemap.xmap 29 Jul 2003 03:15:45 -0000 1.5 +++ sitemap.xmap 17 Sep 2003 08:44:49 -0000 1.6 @@ -1,12 +1,16 @@ + + + + 1.1 cocoon-2.1/src/blocks/authentication-fw/samples/flow.xmap Index: flow.xmap =================================================================== 1.1 cocoon-2.1/src/blocks/authentication-fw/samples/flow/sample.js Index: sample.js =================================================================== 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 protect() { var handler = cocoon.parameters["handler"]; if (auth_isAuthenticated(handler)) { success(); } else { failure(); } } function login() { var handler = cocoon.parameters["handler"]; if (auth_isAuthenticated(handler)) { success(); } if (auth_login(handler, null, cocoon.parameters)) { success(); } else { failure(); } } function logout() { var handler = cocoon.parameters["handler"]; auth_logout(handler); failure(); } function success() { var internal = cocoon.parameters["protected-internal"]; var redirect = cocoon.parameters["protected-redirect"]; if (internal != null) { cocoon.sendPage(internal); } else if (redirect+"" != "undefined") { cocoon.redirectTo(redirect); //THIS NEEDS TO BE A SESSION AWARE REDIRECT } else { throw new Error("No protected redirection parameter given"); } } function failure() { var internal = cocoon.parameters["failure-internal"]; var redirect = cocoon.parameters["failure-redirect"]; if (internal != null) { cocoon.sendPage(internal); } else if (typeof redirect+"" != "undefined") { cocoon.redirectTo(redirect); //THIS NEEDS TO BE A SESSION AWARE REDIRECT } else { // Why does this throw cause an error? throw new Error("No failure redirection parameter given"); } }