cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upayav...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/authentication-fw/samples/flow sample.js
Date Wed, 17 Sep 2003 08:44:49 GMT
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 @@
   <?xml version="1.0"?>
   
   <!--+
  -    | Authentiction block samples sitemap.
  +    | Authentication block samples sitemap.
       |
       | CVS $Id$
       +-->
   
   <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  +
  +  <map:flow language="javascript">
  +     <map:script src="flow/sample.js"/>
  +  </map:flow>
   
   <!-- =========================== Pipelines ================================= -->
     <map:pipelines>
  
  
  
  1.1                  cocoon-2.1/src/blocks/authentication-fw/samples/flow.xmap
  
  Index: flow.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <!--+
      | Authentication (with flow) block samples sitemap.
      |
      | CVS $Id: flow.xmap,v 1.1 2003/09/17 08:44:49 upayavira Exp $
      +-->
  
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
    <map:components>
      <map:transformers default="xslt">
        <map:transformer name="jxpath" src="org.apache.cocoon.transformation.JXTemplateTransformer"
logger="jxpath.sitemap.transformer"/>
      </map:transformers>
    </map:components>
  
    <map:flow language="javascript">
       <map:script src="flow/sample.js"/>
    </map:flow>
  
  <!-- =========================== Pipelines ================================= -->
    <map:pipelines>
      <map:component-configurations>
        <authentication-manager>
          <handlers>
            <handler name="flowdemohandler">
              <redirect-to uri="cocoon:/login"/>
              <authentication uri="cocoon:raw:/authenticate"/>
            </handler>
          </handlers>
        </authentication-manager>
      </map:component-configurations>
  
      <map:pipeline>
        <map:match pattern="">
          <map:redirect-to uri="login" session="true"/>
        </map:match>
  
        <!-- ================= -->
        <!-- 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:parameter name="failure-internal" value="internal/login"/>
            <map:parameter name="protected-internal" value="protected"/>
          </map:call>
        </map:match>
  
        <!-- ========================================= -->
        <!-- Form target which performs auth service   -->
        <!-- ========================================= -->
        <map:match pattern="do-login">
          <!-- 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:call>
        </map:match>
  
        <!-- ================ -->
        <!-- Protected area   -->
        <!-- ================ -->
        <map:match pattern="protected">
          <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:call>
        </map:match>
  
        <!-- ========================================= -->
        <!-- Logout link which invalidates the session -->
        <!-- ========================================= -->
        <map:match pattern="do-logout">
          <map:call function="logout">
            <map:parameter name="handler" value="flowdemohandler"/>
            <map:parameter name="failure-internal" value="login"/>
          </map:call>
        </map:match>
      </map:pipeline>
  
      <map:pipeline internal-only="true">
        <!-- This is the authentication respource -->
        <map:match pattern="authenticate">
          <map:generate src="docs/userlist.xml"/>
          <map:transform src="stylesheets/authenticate.xsl">
            <map:parameter name="use-request-parameters" value="true"/>
          </map:transform>
          <map:serialize type="xml"/>
        </map:match>
      </map:pipeline>
  
      <map:pipeline internal-only="true">
        <map:match pattern="internal/login">
          <map:generate src="docs/login.xml"/>
          <map:transform src="stylesheets/simple-page2html.xsl"/>
          <map:transform type="encodeURL"/>
          <map:serialize/>
        </map:match>
        
        <map:match pattern="internal/protected">
          <map:generate src="docs/protected.xml"/>
          <map:transform type="session"/>
          <map:transform src="stylesheets/simple-page2html.xsl"/>
          <map:transform type="encodeURL"/>
          <map:serialize/>
        </map:match>
      </map:pipeline>  
  
    </map:pipelines>
  </map:sitemap>
  
  
  
  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");
    }
  }
  
  
  

Mime
View raw message