home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / authentication.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  40.6 KB  |  766 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
  18. <document>
  19.     <header>
  20.         <title>Authentication Framework</title>
  21.         <authors>
  22.             <person name="Carsten Ziegeler" email="cziegeler@s-und-n.de"/>
  23.         </authors>
  24.     </header>
  25.     <body>
  26.   <s1 title="Introduction">
  27.      <p>One central point in building a web application is authentication and authorization. The Cocoon
  28.         authentication framework is a flexible module for authentication, authorization and user management. 
  29.         A user can be legitimated using any information available via any source, e.g. an existing database,
  30.         LDAP or the file system. With this mechanism it is very easy to use an exisiting user
  31.         management/authentication system within Cocoon.</p>
  32.      <p>The basic concept of the authentication framework is to protect documents generated by Cocoon. 
  33.         By document we refer to the result of a request to Cocoon, this can either be the result
  34.         of a pipeline or of a reader defined in the sitemap.</p>
  35.      <p>A document is protected by a so called (authentication) handler. A document is associated to a 
  36.        defined handler to be protected. A user can only request this document if he is authenticated 
  37.        against this handler.</p>
  38.      <p>A handler can be used to protect several documents in the same way. If a user is authenticated 
  39.         he can access all these documents. It is possible to use different handlers, to product documents 
  40.         in different ways.</p>
  41.      <p>The use of the authentication framework and its components is described in the following
  42.         chapters.</p>
  43.      <note>As you will see, the user management of the authentication framework is very flexible.
  44.        You can design your application without taking into account, which backend is used for the 
  45.        user management. This can be the file-system, a SQL database, an XML database, a LDAP directory, 
  46.        just anything. Simply by developing the <em>authentication resource</em>, you can connect to any 
  47.        system. And another advantage is the flexible switching between user databases. You can for example 
  48.        use the file-system for the development process and switch than later on to a LDAP system on the 
  49.        production system. This can be done by simply changing the <em>authentication resource</em>. If you 
  50.        test this resource on your production system, you don't have to test your whole application again. 
  51.        (Although in general this might be a good idea...).
  52.      </note>
  53.   </s1>
  54.   <s1 title="Sitemap-Components">
  55.      <p>The authentication Framework adds some actions to the sitemap: the <em>auth-protect</em>
  56.         action, the <em>auth-login</em> action, the <em>auth-logout</em> action
  57.         and the <em>auth-loggedIn</em> action. The <em>authentication-manager</em> gets
  58.         the configuration for the authentication framework and the actions controle the pipelines. 
  59.         The <em>auth-login</em> and the <em>auth-logout</em> action control the
  60.         authentication whereas the <em>auth-loggedIn</em> action controls the application
  61.         flow.</p>
  62.   </s1>
  63.   <s1 title="Protecting Documents">
  64.      <p>One feature of the framework is the user authentication. A document can be
  65.         accessible for everyone or it can be protected using this framework. The process of
  66.         requesting a document can be described as follows:</p>
  67.      <ol>
  68.         <li>The user request a document (original document).
  69.         </li>
  70.         <li>The authentication framework checks if this document is protected. If no protection
  71.           is specified, the response to the request is this original document.
  72.         </li>
  73.         <li>If the document is protected, the framework checks, if the user is
  74.           authenticated to view it.
  75.         </li>
  76.         <li>If the user is authenticated, the response is the original
  77.           document. If not the framework redirects to a special redirect-to document. This
  78.           redirect-to document is freely configurable and can for example contain
  79.           information about the unauthorized access and in addition a login form.
  80.         </li>
  81.         <li>Using the login form an authentication resource can be called
  82.           with the corresponding user information (e.g. user id and password). This
  83.           authentication resource uses the framework for the authentication process.
  84.         </li>
  85.         <li>In case of a successful authentication the framework can redirect to
  86.           the original document (or to any configured start document).
  87.         </li>
  88.         <li>If the authentication fails another document is invoked by
  89.           the framework displaying information to the user.
  90.         </li>
  91.      </ol>
  92.      <p>This process is only one example for a use-case of the framework. It
  93.         can be configured for any authentication scheme. All resources are freely
  94.         configurable.</p>
  95.      <s2 title="The Authentication handler">
  96.         <p>The basic object for authentication is the so called (authentication)
  97.           handler. It controlles the access to the documents. Each document in the
  98.           sitemap can be related to exactly one authentication handler. All documents belonging
  99.           to the same handler are protected in the same way. If a user has access to the
  100.           handler, the user has the same access rights for all documents of this
  101.           handler.</p>
  102.         <p>Each authentication handler needs the following mandatory
  103.           configuration:</p>
  104.         <ul>
  105.           <li>A unique name.
  106.           </li>
  107.           <li>The authentication resource: A Cocoon pipeline trying to authenticate a user.
  108.               (We will see later on, that there are more possibilities than using a pipeline).
  109.           </li>
  110.           <li>The redirect-to document: This document is displayed when a not 
  111.               authorized user tries to access a protected document.
  112.           </li>
  113.         </ul>
  114.      </s2>
  115.      <s2 title="The Configuration of a Handler">
  116.         <p>So let's have a look at the configuration. A handler can be configured in the sitemap.
  117.         It is a so-called component configuration for the authentication manager. This
  118.         configuration takes place in the <em>map:pipelines</em> section of a sitemap:</p>
  119. <source>
  120. <map:sitemap>
  121.     ...component definitions...
  122.  
  123. <map:pipelines>
  124.   <map:component-configurations>
  125.     <authentication-manager>
  126.       <handlers>
  127.         <handler name="portalhandler">
  128.           <redirect-to uri="cocoon:/sunspotdemoportal"/>
  129.           <authentication uri="cocoon:raw:/sunrise-authuser"/>
  130.         </handler>
  131.       </handlers>
  132.     </authentication-manager>
  133.   </map:component-configurations>
  134. <map:pipeline>
  135.    ... document pipelines following here:
  136. </source>
  137.         <p>Using a unique name for each handler (only alphabetical characters
  138.           and digits are allowed for the handler name), the framework manages different
  139.           handlers. So various parts of the sitemap can be protected in different ways.
  140.         </p>
  141.         <p>A handler is inherited to a sub sitemap. Each sub sitemap can define
  142.            its own handlers. These handlers are only available to the sub sitemap
  143.            (and of course to its sub sitemaps). However, it is not possible to
  144.            redefine (overwrite) a previously defined handler in a sub sitemap.</p>
  145.      </s2>
  146.      <s2 title="Protecting Documents">
  147.         <p>A document can be protected by associating it to a defined handler.
  148.         This is done by using the <em>auth-protect</em> action and the handler parameter:</p>
  149. <source><map:match pattern="protectedresource">
  150.   <map:act type="auth-protect">
  151.     <map:parameter name="handler" value="portalhandler"/>
  152.     <map:generate src="source/resource.xml"/>
  153.     <map:serialize type="xml"/>
  154.   </map:act>
  155. </map:match></source>
  156.         <p>If this document is requested, the action checks if the user is authenticated against the
  157.            defined handler. If not, the action automatically redirects to the <em>redirect-to</em> document 
  158.            configured in the handler. (In the example above this is the pipeline defined by <em>cocoon:/sunspotdemoportal</em>.</p>
  159.         <p>If the user is authenticated, the commands inside the <em>map:act</em> will be execute and
  160.            the user gets the document itself.</p>
  161.         <p>So, the <em>auth-protect</em> action must be included in the pipeline of the
  162.           document. It gets the handler information as a parameter. If the pipeline does 
  163.           not use the <em>auth-protect</em> action or the parameter <em>handler</em> is missing, 
  164.           the document is accessible by any user.</p>
  165.         <note>You will see learn later on how to efficiently protect several documents with a handler.</note>
  166.      </s2>
  167.      <s2 title="The redirect-to document">
  168.         <p>If the requested document is not accessible to the user, the authentication framework
  169.           redirects to the configured <em>redirect-to</em> document. This document is a mandatory
  170.           configuration of the authentication handler as we have seen above.</p>
  171.         <p>This <em>redirect-to</em> document is an unprotected pipeline in the
  172.           sitemap. For tracking which document was originally requested by the user, 
  173.           the <em>redirect-to</em> pipeline gets the request parameter <em>resource</em> 
  174.           with that value. In addition all parameters specified inside the <em>redirect-to</em> 
  175.           tag of the handler configuration are passed to the pipeline as well.</p>
  176.         <p>For example, the <em>redirect-to</em> document can contain a form for the user
  177.           authentication. This form should invoke the real authentication process that is
  178.           described below. However, the document you show when an unauthorized access
  179.           is made, can be controlled by you by defining this <em>redirect-to</em>
  180.           document.</p>
  181.      </s2>
  182.      </s1>
  183.      <s1 title="Authenticating a User">
  184.         <p>Usually, the <em>redirect-to</em> document of a handler contains a form for the user 
  185.            to authenticate. But of course, you are not limited to this. No matter how the
  186.            <em>redirect-to</em> document looks like, the user has "somewhere" the abilitiy
  187.            to authenticate, so in most cases the user has a form where he can enter
  188.            his information (e.g. user name and password). You have to write a pipeline
  189.            presenting this form to the user. When the form is submitted, the authentication
  190.            process has to be started inside the authentication framework. As a submit
  191.            of a form invokes a request to Cocoon, a pipeline in the sitemap is triggered.
  192.            We refer to this pipeline with <em>login pipeline</em>.</p>
  193.      <s2 title="The Login Process">
  194.         <p>The authentication process is started by invoking the <em>auth-login</em> action.
  195.           So, the <em>login pipeline</em> has to contain this action:</p>
  196.         <source><map:match pattern="login">
  197.   <map:act type="auth-login">
  198.     <map:parameter name="handler" value="portalhandler"/>
  199.     <map:parameter name="parameter_userid" value="{request-param:name}"/>
  200.     <map:parameter name="parameter_password" value="{request-param:password}"/>
  201.     <map:redirect-to uri="authentication-successful"/>
  202.   </map:act>
  203.   <!-- authentication failed: -->
  204.   <map:generate src="auth_failed.xml"/>
  205.   <map:transform src="tohtml.xsl"/>
  206.   <map:serialize/>
  207. </map:match></source>
  208.         <p>The <em>auth-login</em> action uses the handler parameter to call the
  209.           <em>authentication resource</em> of this handler. This <em>authentication resource</em> needs to
  210.           know the information provided by the user, e.g. in the form. For each piece of information an own
  211.           parameter is created. The name of this parameter has to start with "parameter_". 
  212.           So in the example above, the <em>authentication resource</em> gets two parameters: userid and password. As
  213.           the values of these parameters were sent by a form they need to be passed on
  214.           to the <em>authentication resource</em>. If you use "{request-param:...}" for the value of a
  215.           parameter, the <em>auth-login</em> action will pass the actual value of that request
  216.           parameter to the <em>authentication resource</em> (by using the input modules concept
  217.           of Cocoon).</p>
  218.         <note>You might be wondering why we explicitly pass the request parameters on to the
  219.           internal pipeline call. Note that the <em>authentication resource</em> of the
  220.           portalhandler is defined by <em>cocoon:raw</em>. By using this, no request
  221.           parameter of the original request is passed on to the internal pipeline by
  222.           default and therefore we have to define them explicitly. If you use
  223.           <em>cocoon:</em> then the parameters of the form are by default passed on
  224.           to the <em>authentication resource</em> and we could omit the parameter definition
  225.           from above. But we feel that it is safer to explicitly define them.</note>
  226.         <p>If the user is not already authenticated with this handler, the framework calls
  227.           the <em>authentication resource</em> and passes it the parameters. If this
  228.           authentication is successful, the action returns a map and the sitemap
  229.           commands inside the <em>map:act</em> are executed. A session is created on
  230.           the server (if not already done) as well.</p>
  231.         <p>If the authentication fails, the action does not deliver a map and
  232.         therefore the commands inside the <em>map:act</em> are skipped. The error
  233.           information delivered by the <em>authentication resource</em> is stored into the
  234.           <em>temporary</em> context. So you can get the information using either the
  235.           <em>session transformer</em> or the <em>session-context input module</em>.</p>
  236.         <note>As you can see from the example above, you are not limited in defining
  237.           the information the user has to provide. This can be either one field, two or
  238.           as many fields as you need.</note>
  239.      </s2>
  240.      <s2 title="The authentication resource">
  241.         <p>The last chapter described the authentication process but left out
  242.           details about the authentication itself. This chapter closes this gap.</p>
  243.         <p>The authentication can be done by different components:</p>
  244.         <ul>
  245.           <li>A sitemap resource (pipeline).
  246.           </li>
  247.           <li>A distant resource, e.g. requested via HTTP.
  248.           </li>
  249.           <li>A java class.
  250.           </li>
  251.         </ul>
  252.         <p>The first two are actually similar as in both cases a URI is called. So we
  253.           will talk about them in the next chapter. Authentication using a java class
  254.           is the topic of the following chapter.</p>
  255.         <s3 title="Using a URI as the authentication resource">
  256.         <p>Using this flexible approach nearly any kind of authentication is
  257.           possible (e.g. database, LDAP). The <em>authentication resource</em> is another
  258.           mandatory configuration of the authentication handler:</p>
  259.         <source><autentication-manager>
  260.   <handlers>
  261.     <!-- Now follows the handlers configuration -->
  262.     <handler name="portalhandler">
  263.       <!-- The login resource -->
  264.       <redirect-to uri="cocoon:/sunspotdemoportal"/>
  265.       <authentication uri="cocoon:raw:/sunrise-authuser"/>
  266.     </handler>
  267.   </handlers>
  268. </autentication-manager></source>
  269.         <p>If the <em>authentication resource</em> is a sitemap resource or a remote
  270.           resource, this resource is requested by the framework with the given parameters from
  271.           the <em>auth-login</em> action (see previous chapter). In addition all parameters inside 
  272.           the <em>authentication</em> tag of the handler configuration are passed to the resource. 
  273.           The response of this resource must contain valid XML conforming to the following scheme:</p>
  274.         <source><authentication>
  275.     <ID>Unique ID of the user in the system</ID>
  276.     <role>rolename</role> <!-- optional -->
  277.     <data>
  278.         Any additional optional information can be supplied here. 
  279.         This will be stored in the session for later retrieval
  280.     </data>
  281. </authentication></source>
  282.         <p>The XML is very simply, only the root element <em>authentication</em> and the <em>ID</em>
  283.          element with a valid unique ID for the user in this handler is required. Everything else is optional.
  284.         </p>
  285.         <p>The framework checks the response of the authentication resource for the
  286.           given scheme: the root node must be named <em>authentication</em> and one child called
  287.           <em>ID</em> must be present. In this case the authentication is successfull and
  288.           the framework creates an authentication session context and stores the XML inside.</p>
  289.         <p>The mandatory information inside this XML scheme, the <em>ID</em> tag, is
  290.           an unique identification for the given user inside the web application or
  291.           more precisly inside this handler. The <em>role</em> is optional and can for example 
  292.           be used for categorizing users and displaying different functionality inside the Cocoon portal
  293.           engine).</p>
  294.         <note>As stated, the <em>role</em> element is optional, you can use your own
  295.         categorization and exchange it with a <em>roles</em> element or a <em>group</em>
  296.         element or leave it out, if you don't need it. In addition you can add any
  297.         other element there as well and access the information later on.</note>
  298.         <p>Using the <em>data</em> node the <em>authentication resource</em> can pass any
  299.           information of the user into the session. From there you can retrieve the
  300.           information as long as the session is valid.</p>
  301.         <p>If the authentication is not successful, the resource must create
  302.           an XML with the root node <em>authentication</em>, but of course without
  303.           the <em>ID</em> tag. In addition a <em>data</em> node can be added containing 
  304.           more information about the unsuccessful attempt. This data
  305.           node is then stored into the <em>temporay</em> context (see previous
  306.           chapter).</p>
  307.         <note>It is advisable to make an internal pipeline for the <em>authentication resource</em>.
  308.            An internal pipeline is not directly accessible by a user.</note>
  309.         </s3>
  310.         <s3 title="Using a Java class as the authentication resource">
  311.         <p>Using a class is an alternative for using a pipeline.
  312.            You can define this class in the handler configuration as an attribute
  313.            <em>authenticator</em> of the <em>authentication</em> element, e.g.:</p>
  314.         <source><autentication-manager>
  315.   <handlers>
  316.     <!-- Now follows the handlers configuration -->
  317.     <handler name="portalhandler">
  318.       <!-- The login resource -->
  319.       <redirect-to uri="cocoon:/sunspotdemoportal"/>
  320.       <authentication authenticator="mypkg.MyAuthenticator"/>
  321.     </handler>
  322.   </handlers>
  323. </autentication-manager></source>
  324.            <p>This class must conform to the <em>Authenticator</em> interface. This
  325.             interface provides a method that tries to authenticate a User and 
  326.             delivers XML that is stored in the session on success. So, the behaviour 
  327.             is similar to the pipeline.</p>
  328.         </s3>
  329.      </s2>
  330.      <s2 title="Logging out">
  331.         <p>The logout process is triggered by the "auth-logout"
  332.           action:</p>
  333.         <source><map:act type="auth-logout">
  334.   <map:parameter name="handler" value="unique"/>
  335. </map:act></source>
  336.         <p>This action logs the user out of the given handler and removes all
  337.           information about this handler stored in the session.</p>
  338.      </s2>
  339.   </s1>
  340.   <s1 title="User Management">
  341.      <p>In addition to the authentication the framework manages all kinds of
  342.         information belonging to the user in XML format. For this reason the framework
  343.         creates an own session context called <em>authentication</em>. All information 
  344.         is stored in this context.</p>
  345.      <p>The authentication information (the "authentication" scheme retrieved
  346.         from the authentication resource) is stored in this context, so you can
  347.         retrieve and change the information using the session transformer and the
  348.         usual getxml, setxml etc. commands, so we suggest you to read the session
  349.         context document.</p>
  350.      <note>The <em>authentication</em> context is only available to the
  351.        <em>session transformer</em> if the pipeline, the transformer is
  352.        running in, is associated to the (authentication) handler. Or putting
  353.        it in other words: you have to use the <em>auth-project</em> action
  354.        in that pipeline. Otherwise the <em>authentication</em> context
  355.        is not available.</note>
  356.      <s2 title="Getting information from the context">
  357.         <p>Each information from within the context is gettable using an XML
  358.           tag:</p>
  359.         <source><session:getxml context="authentication" path="/authentication/ID"/> <!-- Get the ID -->
  360. <session:getxml context="authentication" path="/authentication/data/username"/></source>
  361.         <p>The path expression is an absolute XPath-like expression where only
  362.           concrete nodes and attributes are allowed. The session transformer replaced
  363.           the tag with the value of the first node found in the context, this can either
  364.           be text or XML.</p>
  365.      </s2>
  366.      <s2 title="Setting information in the context">
  367.         <p>Using another tag information can be stored into the
  368.           context:</p>
  369.         <source><session:setxml context="authentication" path="/authentication/data/usersername">
  370.     Mr. Sunshine
  371. </session:setxml></source>
  372.         <p>Again the path is an absolute XPath-like expression where only
  373.           concrete nodes and attributes are allowed. If the requested node exists,
  374.           the framework changes the value of that node. If the node does not exists, the framework
  375.           adds it to the context with the given value.</p>
  376.         <p>The tag is removed from the resource.</p>
  377.      </s2>
  378.   </s1>
  379.   <s1 title="Application Management">
  380.      <p>A very useful feature for building and maintaining web applications
  381.         is the application management. It allows to configure different
  382.         applications and to manage the user data for these applications.</p>
  383.      <s2 title="Configuring an Application">
  384.         <p>A "authentication" application is related to one authentication handler, so an
  385.           application is part of the authentication handler configuration:</p>
  386.         <source><autentication-manager>
  387.     <handlers>
  388.         <handler name="unique">
  389.              ....redirect-to/authentication configuration
  390.              <applications> <!-- the applications for this handler -->
  391.                  <application name="unique">
  392.                      <load uri="loadapp"/> <!-- optional -->
  393.                      <save uri="saveapp"/> <!-- optional -->
  394.                  </application>
  395.              </applications>
  396.         </handler>
  397.     </handlers>
  398. </autentication-manager></source>
  399.         <p>A configuration for an application consists of a unique name (only
  400.           alphabetical characters and digits are allowed for the application name) and
  401.           optional load and save resources. The application configuration can contain
  402.           application specific configuration values for the various parts of the
  403.           application, e.g. information for a portal.</p>
  404.         <p>On a successful authentication the framework invokes for each application
  405.           of the handler the load resource (if present). The content or result of the
  406.           load resource is stored into the session context.</p>
  407.         <p>The user does not always visit all sides or all applications at
  408.           once. So it is not necessary to load all applications in advance when not all
  409.           information is needed. Each application can specify if the data is loaded on
  410.           successful authentication or the first time needed:</p>
  411.         <source>....<application name="unique" loadondemand="true"/>...</source>
  412.         <p>The load resource gets several parameters: all values of the
  413.           subnodes of the "authentication" node from the authentication context (e.g. ID, role
  414.           etc.) and the parameter "application" with the unique name of the application.
  415.           This unique name must not contain one of the characters '_', ':' or '/'.</p>
  416.  
  417.         <p>In addition the load and save resource get all parameters specified
  418.           inside the load / save tag of the handler configuration.</p>
  419.      </s2>
  420.      <s2 title="Configuring the resources">
  421.         <p>For managing the application the framework needs to know to which
  422.           application a resource belongs. So in addition to the handler parameter the
  423.           auth-protect action gets the application name as a second parameter:</p>
  424.         <source><map:match pattern="protectedresource">
  425.   <map:action type="auth-protect">
  426.     <map:parameter name="handler" value="unique handler name"/>
  427.     <map:parameter name="application" value="unique application name"/>
  428.     
  429.     <map:generate src="source/resource.xml"/>
  430.             ...
  431.   </map:action>
  432. </map:match>
  433. </source>
  434.         <p>With this mechanism each application resource can easily access its
  435.           and only its information. If a resource has no "application" parameter it can
  436.           not access information of any application.</p>
  437.      </s2>
  438.      <s2 title="Getting, setting and saving application information">
  439.         <p>Analogue to the access of the authentication data a resource can
  440.           access its application data:</p>
  441.         <source><session:getxml context="authentication" path="/application/username"/>
  442. <session:setxml context="authentication"  path="/application/shoppingcart"><item1/><item2/></session:setxml></source>
  443.         <p>The path underlies the same restrictions and rules as always, but
  444.           it has to start with "/application/". </p>
  445.      </s2>
  446.   </s1>
  447.   <s1 title="Module Management">
  448.      <p>In addition to the application management the framework offers a facility
  449.         called module management. It enhances the application management by the
  450.         possibility to configure components for the application. For example the Cocoon
  451.         portal engine needs information about where the portal profile
  452.         for the user is retrieved from, where the layout is stored etc. Now each portal
  453.         needs this information. Assuming that a portal is an application each
  454.         application needs this information. As only the portal engine itself knows what
  455.         information it needs, the module management is a standarized way for
  456.         configuring such components.</p>
  457.      <p>The module configuration is part of the application
  458.         configuration:</p>
  459.      <source><autentication-manager>
  460.   <handlers>
  461.     <handler name="unique">
  462.       ....redirect-to/authentication configuration
  463.       <applications>  <!-- the applications for this handler -->
  464.         <application name="unique">
  465.           ...
  466.           <configuration name="portal">
  467.             ...portal configuration
  468.           </configuration>
  469.         </application>
  470.       </applications>
  471.     </handler>
  472.   </handlers>
  473. </autentication-manager></source>
  474.      <p>So whenever the portal engine is asked to build the portal it can
  475.         easily retrieve its configuration from the current application by getting the
  476.         module configuration named "portal".</p>
  477.   </s1>
  478.   <s1 title="User Administration">
  479.      <p>Using the framework it is possible to add new roles to the system and to
  480.         add new users. For this purpose, there are several optional entries for the
  481.         authentication handler which provide the needed functionality:</p>
  482.      <source><autentication-manager>
  483.   <handlers>
  484.     <handler name="unique">
  485.              ...redirect-to/authentication configuration...
  486.  
  487.       <!-- Optional resource for loading user information -->
  488.       <load-users uri="cocoon:raw://financeresource-sunrise-loaduser"/>
  489.  
  490.       <!-- Optional resource for loading roles information-->
  491.       <load-roles uri="cocoon:raw://financeresource-sunrise-roles"/>
  492.  
  493.       <!-- Optional resource for creating a new user -->
  494.       <new-user uri="cocoon:raw://financeresource-sunrise-newuser"/>
  495.  
  496.       <!-- Optional resource for creating a new role -->
  497.       <new-role uri="cocoon:raw://financeresource-sunrise-newrole"/>
  498.  
  499.       <!-- Optional resource for changing user information -->
  500.       <change-user uri="cocoon:raw://financeresource-sunrise-newuser"/>
  501.  
  502.       <!-- Optional resource for deleting a role -->
  503.       <delete-role uri="cocoon:raw://financeresource-sunrise-delrole"/>
  504.  
  505.       <!-- Optional resource for deleting a user-->
  506.       <delete-user uri="cocoon:raw://financeresource-sunrise-deluser"/>
  507.     </handler>
  508.   </handlers>
  509. </autentication-manager></source>
  510.      <p>The entries are described in the following subchapters. All tags can
  511.         have additional parameter definitions which are passed to the given resource,
  512.         e.g:</p>
  513.      <source><!-- Optional resource for deleting a user-->
  514. <delete-user uri="cocoon:raw://financeresource-sunrise-deluser">
  515.   <connection>database</connection>
  516.   <url>db:usertable</url>
  517. </delete-user></source>
  518.      <s2 title="Getting Roles">
  519.         <p>The <em>load-roles</em> resource is invoked from the framework whenever
  520.           it needs information about the available roles. This resource gets the
  521.           parameter "type" with the value "roles" and should deliver an XML schema with
  522.           the root node "roles" and for each role a subelement "role" with a text child
  523.           of the rolename:</p>
  524.         <source><roles>
  525.   <role>admin</role>
  526.   <role>guest</role>
  527.   <role>user</role>
  528. </roles></source>
  529.      </s2>
  530.      <s2 title="Getting Users">
  531.         <p>The <em>load-users</em> resource is called whenever information
  532.           about the available users is needed. There are three different uses of this
  533.           resource:</p>
  534.         <ul>
  535.           <li>Loading all users: The resource gets the parameter "type"
  536.              with the value "users". It should then deliver all users in the system.
  537.           </li>
  538.           <li>Loading all users of one role. The resource gets the
  539.              parameters "type" with the value "users" and "role" with the rolename.
  540.           </li>
  541.           <li>Load information of one user. The resource gets the
  542.              parameters "type" with the value "user", "role" with the rolename and "ID" with
  543.              the authentication ID of the user.
  544.           </li>
  545.         </ul>
  546.         <p>The XML format of the resource should look like the
  547.           following:</p>
  548.         <source><users>
  549.   <user>
  550.     <ID>authentication ID</ID>
  551.     <role>rolename</role>
  552.     <data>
  553.        ... application specific data ...
  554.     </data>
  555.   </user>
  556.   <user>
  557.     ...
  558.   </user>
  559.     ...
  560. </users></source>
  561.      </s2>
  562.      <s2 title="Creating a new role">
  563.         <p>The <em>new-role</em> resource creates a new role in the system. It
  564.           gets the parameters "type" with the value "role" and "role" with the new
  565.           rolename.</p>
  566.      </s2>
  567.      <s2 title="Creating a new user">
  568.         <p>The <em>new-user</em> resource creates a new user with a role. It
  569.           gets the parameters <em>"type"</em> with the value <em>"user"</em>,
  570.           <em>"role"</em> with the rolename and <em>"ID"</em> with the new ID for this
  571.           user.</p>
  572.      </s2>
  573.      <s2 title="Changing information of a user">
  574.         <p>The <em>change-user</em> resources changes information of a user.
  575.           It gets the parameters "type" with the value "user", "role" with the rolename
  576.           and "ID" with the ID of the user. In addition all - application specific -
  577.           information of this user is send as parameters.</p>
  578.      </s2>
  579.      <s2 title="Delete a user">
  580.         <p>The <em>delete-user</em> resource should delete a user. It gets the
  581.           parameters "type" with the value "user", "role" with the rolename and "ID" with
  582.           the ID of the user.</p>
  583.      </s2>
  584.      <s2 title="Delete a role">
  585.         <p>The <em>delete-role</em> resources deletes a role. It gets the
  586.           parameters "type" with the value "role" and "role" with the rolename .</p>
  587.      </s2>
  588.   </s1>
  589.   <s1 title="Configuration Summary">
  590.      <p>Here is a brief summary of the authentication handler configuration: </p>
  591.  
  592.      <source><autentication-manager>
  593.   <handlers>
  594.     <handler name="unique">
  595.       <!-- The redirect-to resource -->
  596.       <redirect-to uri="cocoon:raw://loginpage"/>
  597.       <!-- Authentication resource -->
  598.       <authentication uri="cocoon:raw://authenticationresource"/>
  599.  
  600.       <load uri="cocoon:raw://authenticationsaveresource">
  601.         <!-- optional parameters -->
  602.       </load>
  603.       <!-- optional save resource -->
  604.       <save uri="cocoon:raw://authenticationsaveresource">
  605.         <!-- optional parameters -->
  606.       </save>
  607.  
  608.       <applications>
  609.         <!-- the applications for this handler -->
  610.         <application name="unique">
  611.  
  612.           <!-- Loading/Saving -->
  613.           <load uri="cocoon:raw://loadapp">
  614.             <!-- optional -->
  615.             <!-- optional parameters -->
  616.           </load>
  617.           <save uri="cocoon:raw://saveapp">
  618.             <!-- optional -->
  619.             <!-- optional parameters -->
  620.           </save>
  621.           <!-- module configurations: -->
  622.  
  623.           <configuration name="portal">
  624.             ...portal configuration
  625.           </configuration>
  626.         </application>
  627.       </applications>
  628.  
  629.     </handler>
  630.   </handlers>
  631. </autentication-manager></source>
  632.   </s1>
  633.   <s1 title="Pipeline Patterns">
  634.      <p>As explained in the previous chapters, the framework uses the <em>auth-protect</em>
  635.         action for authentication and protecting documents. This chapter shows some
  636.         common used pipeline patterns for using this framework.</p>
  637.      <s2 title="Single protected document">
  638.         <p>For protecting a document with an authentication handler only the <em>auth-protect</em>
  639.           action with the parameter configuration for the handler is required.</p>
  640.         <p>Pattern:</p>
  641.         <ol>
  642.           <li>Pipeline matching
  643.           </li>
  644.           <li>Using the <em>auth-protect</em> action for protecting
  645.           </li>
  646.         </ol>
  647.         <p>Example:</p>
  648.         <source><map:match pattern="protected">
  649.   <map:act type="auth-protect">  <!-- protect the resource -->
  650.     <map:parameter name="handler" value="myhandler"/>
  651.  
  652.     <map:generate src="resource.xml"/>
  653.     <map:transform src="toHTML"/>
  654.     <map:serialize/>
  655.   </map:act>
  656. </map:match></source>
  657.         <p>It is very important that the <em>auth-protect</em> action wrapps the real
  658.           pipeline, as the pipeline is only invoked if the action grants access. The
  659.           matching must be done before the action is checked as the action performs a
  660.           redirect for this document.</p>
  661.      </s2>
  662.      <s2 title="Multiple protected documents">
  663.         <p>Often you want to protect a bunch of documents in the same way. One
  664.           solution is to use the single protected document pattern for each document.
  665.           With the multiple protected document pattern you only have to use the action
  666.           once for all documents and not within each document pipeline.</p>
  667.         <p>The prerequisite for this is a common matching pattern for the
  668.           documents:</p>
  669.         <ol>
  670.           <li>Pipeline pattern matching
  671.           </li>
  672.           <li>Using the <em>auth-protect</em> action for protection
  673.           </li>
  674.           <li>Pipeline matching
  675.           </li>
  676.         </ol>
  677.         <p>Example:</p>
  678.         <source><map:match pattern="protected-*">
  679.   <map:act type="auth-protect"> <!-- protect the resource -->
  680.     <map:parameter name="handler" value="myhandler"/>
  681.  
  682.     <map:match pattern="protected-first">
  683.       <map:generate src="resource1.xml"/>
  684.       <map:transform src="toHTML"/>
  685.       <map:serialize/>
  686.     </map:match>
  687.         ....
  688.     <map:match pattern="protected-second">
  689.       <map:generate src="resource2.xml"/>
  690.       <map:transform src="toHTML"/>
  691.       <map:serialize/>
  692.     </map:match>
  693.   
  694.   </map:act>
  695. </map:match></source>
  696.         <p>Very important - as explained with the single document pattern - is
  697.           the leading match before the action is performed. The second match is required
  698.           to check which pipeline to use.</p>
  699.      </s2>
  700.      <s2 title="Controlling the Application Flow">
  701.         <p>If you want to create documents which behave different wheather you
  702.           are logged in or not, the <em>auth-loggedIn</em> action is the component to
  703.           controll your application flow. This action checks if the user is authenticated
  704.           for a given handler and calls all sitemap components inside the <em>act</em>
  705.           tag.</p>
  706.         <source><map:match pattern="startpage">
  707.  
  708.   <map:act type="auth-loggedIn">  <!-- check authentication -->
  709.     <map:parameter name="handler" value="myhandler"/>
  710.  
  711.     <map:redirect-to uri="loggedInStartPage"/>
  712.   </map:act>
  713.  
  714.   <map:generate src="startpage.xml"/>
  715.   <map:transform src="toHTML"/>
  716.   <map:serialize/>
  717. </map:match></source>
  718.         <p>In the example above, if the user is already logged he is
  719.           redirected to the <em>loggedInStartPage</em> document. If he is not logged in
  720.           for the given handler, the usual start page is generated.</p>
  721.         <p>The <em>auth-protect</em> action returns - if the user is logged in for the
  722.           given handler - all values from the context to the sitemap, e.g. ID, role etc.
  723.           These values can be used within the other components:</p>
  724.         <source><map:match pattern"protected">
  725.   <map:act type="auth-protect">  <!-- protect the resource -->
  726.     <map:parameter name="handler" value="myhandler"/>
  727.  
  728.     <!-- Append the ID of the user to the file name -->
  729.     <map:generate src="resource_{ID}.xml"/>
  730.     <map:transform src="toHTML"/>
  731.     <map:serialize/>
  732.  
  733.   </map:act>
  734. </map:match></source>
  735.         <p>But the <em>auth-loggedIn</em> action does not give the included pipeline
  736.           access to the authentication context belonging to the handler. If you want this, you
  737.           have to nest the <em>auth-protect</em> action inside!</p>
  738.         <source><map:match pattern"start">
  739.  
  740.   <map:act type="auth-loggedIn">  <!-- check authentication -->
  741.     <map:parameter name="handler" value="myhandler"/>
  742.  
  743.     <map:act type="auth-protect">  <!-- give access to the context -->
  744.       <map:parameter name="handler" value="myhandler"/>
  745.  
  746.       <map:generate src="getinfofromcontext.xml"/>
  747.       <map:transform type="session"/>
  748.       <map:transform src="toHTML"/>
  749.       <map:serialize/>
  750.     </map:act>
  751.   </map:act>
  752.  
  753. </map:match></source>
  754.      </s2>
  755.      <s2 title="Session Handling">
  756.       <p>If a user is authenticated the user has a session. However, care has to be taken that
  757.         the session tracking works, which means that Cocoon can detect that a follow up request
  758.         of the user belongs to the same session.</p>
  759.       <p>The easiest way is to use the <em>encodeURL</em> transformer as the last transformation
  760.         step in your pipeline. For more information about session handling, have a look in 
  761.         the <link href="session.html">chapter about sessions</link>.</p>
  762.      </s2>
  763.   </s1>
  764. </body>
  765. </document>
  766.