cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Created: Pipeline Patterns
Date Tue, 16 Aug 2005 13:27:55 GMT
A new document has been created.

http://cocoon.zones.apache.org/daisy/documentation/672.html

Document ID: 672
Branch: main
Language: default
Name: Pipeline Patterns
Document Type: Document
Created: 8/16/05 1:27:43 PM
Creator (owner): Helma
State: publish

Parts
=====

Content
-------
Mime type: text/xml
Size: 5387 bytes
Content:
<html>
<body>

<p>As explained in the previous chapters, the framework uses the
<em>auth-protect</em> action for authentication and protecting documents. This
chapter shows some commonly used pipeline patterns.</p>

<h2>Single protected document</h2>

<p>For protecting a document with an authentication handler only the
<em>auth-protect</em> action with the parameter configuration for the handler
is
required.</p>

<p>Pattern:</p>

<ol>
<li>Pipeline matching</li>
<li>Using the <em>auth-protect</em> action for protecting</li>
</ol>

<p>Example:</p>

<pre>&lt;map:match pattern="protected"&gt;
  &lt;map:act type="auth-protect"&gt;  &lt;!-- protect the resource --&gt;
    &lt;map:parameter name="handler" value="myhandler"/&gt;

    &lt;map:generate src="resource.xml"/&gt;
    &lt;map:transform src="toHTML"/&gt;
    &lt;map:serialize/&gt;
  &lt;/map:act&gt;
&lt;/map:match&gt;</pre>

<p>It is very important that the <em>auth-protect</em> action wraps the
real
pipeline, as the pipeline is only invoked if the action grants access. The
matching must be done before the action is checked as the action performs a
redirect for this document.</p>

<h2>Multiple protected documents</h2>

<p>Often you want to protect a bunch of documents in the same way. One solution
is to use the single protected document pattern for each document. With the
multiple protected document pattern you only have to use the action once for all
documents and not within each document pipeline.</p>

<p>The prerequisite for this is a common matching pattern for the documents:</p>

<ol>
<li>Pipeline pattern matching</li>
<li>Using the <em>auth-protect</em> action for protection</li>
<li>Pipeline matching</li>
</ol>

<p>Example:</p>

<pre>&lt;map:match pattern="protected-*"&gt;
  &lt;map:act type="auth-protect"&gt; &lt;!-- protect the resource --&gt;
    &lt;map:parameter name="handler" value="myhandler"/&gt;

    &lt;map:match pattern="protected-first"&gt;
      &lt;map:generate src="resource1.xml"/&gt;
      &lt;map:transform src="toHTML"/&gt;
      &lt;map:serialize/&gt;
    &lt;/map:match&gt;
        ....
    &lt;map:match pattern="protected-second"&gt;
      &lt;map:generate src="resource2.xml"/&gt;
      &lt;map:transform src="toHTML"/&gt;
      &lt;map:serialize/&gt;
    &lt;/map:match&gt;
  
  &lt;/map:act&gt;
&lt;/map:match&gt;</pre>

<p>Very important - as explained with the single document pattern - is the
leading match before the action is performed. The subsequent matches are
required to check which pipeline to use.</p>

<h2>Controlling the Application Flow</h2>

<p>If you want to create documents which behave different depending if you are
logged in or not, the <em>auth-loggedIn</em> action is the component to use to
control your application flow. This action checks if the user is authenticated
for a given handler and calls all sitemap components inside the <em>act</em>
tag.</p>

<pre>&lt;map:match pattern="startpage"&gt;

  &lt;map:act type="auth-loggedIn"&gt;  &lt;!-- check authentication --&gt;
    &lt;map:parameter name="handler" value="myhandler"/&gt;

    &lt;map:redirect-to uri="loggedInStartPage"/&gt;
  &lt;/map:act&gt;

  &lt;map:generate src="startpage.xml"/&gt;
  &lt;map:transform src="toHTML"/&gt;
  &lt;map:serialize/&gt;
&lt;/map:match&gt;</pre>

<p>In the example above, if the user is already logged he is redirected to the
<em>loggedInStartPage</em> document. If he is not logged in for the given
handler, the usual start page is generated.</p>

<p>The <em>auth-protect</em> action returns - if the user is logged in for
the
given handler - all values from the context to the sitemap, e.g. ID, role etc.
These values can be used within the other components:</p>

<pre>&lt;map:match pattern"protected"&gt;
  &lt;map:act type="auth-protect"&gt;  &lt;!-- protect the resource --&gt;
    &lt;map:parameter name="handler" value="myhandler"/&gt;

    &lt;!-- Append the ID of the user to the file name --&gt;
    &lt;map:generate src="resource_{ID}.xml"/&gt;
    &lt;map:transform src="toHTML"/&gt;
    &lt;map:serialize/&gt;

  &lt;/map:act&gt;
&lt;/map:match&gt;</pre>

<p>But the <em>auth-loggedIn</em> action does not give the included pipeline
access to the authentication context belonging to the handler. If you want this,
you have to nest the <em>auth-protect</em> action inside!</p>

<pre>&lt;map:match pattern"start"&gt;

  &lt;map:act type="auth-loggedIn"&gt;  &lt;!-- check authentication --&gt;
    &lt;map:parameter name="handler" value="myhandler"/&gt;

    &lt;map:act type="auth-protect"&gt;  &lt;!-- give access to the context --&gt;
      &lt;map:parameter name="handler" value="myhandler"/&gt;

      &lt;map:generate src="getinfofromcontext.xml"/&gt;
      &lt;map:transform type="session"/&gt;
      &lt;map:transform src="toHTML"/&gt;
      &lt;map:serialize/&gt;
    &lt;/map:act&gt;
  &lt;/map:act&gt;

&lt;/map:match&gt;</pre>

<h2>Session Handling</h2>

<p>If a user is authenticated, the user has a session. However, care has to be
taken that the session tracking works, which means that Cocoon can detect that a
follow up request of the user belongs to the same session.</p>

<p>The easiest way is to use the <em>encodeURL</em> transformer as the last
transformation step in your pipeline. For more information about session
handling, have a look in the <a href="daisy:607">chapter about sessions</a>.</p>

</body>
</html>

Collections
===========
The document belongs to the following collections: documentation

Mime
View raw message