You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Roel Croonenberghs <Ro...@sofico.be> on 2006/09/14 16:45:41 UTC

authentication

Hello,

I want to use authentication in cocoon so I can limit some users to view 
certein pages.
But I have a problem;
when I access foo-loginpage I get a form where i can introduce my username 
and password. when i click "login". I get a blank page. and this as url in 
my browser 
http://localhost:8080/extranet/foo-login?resource=foo-protected


What am I doing wrong?


I have thsi code in my sitemap;

<map:action name="auth-protect" 
src="org.apache.cocoon.webapps.authentication.acting.AuthAction"/>
                <map:action name="auth-login" 
src="org.apache.cocoon.webapps.authentication.acting.LoginAction"/>
                <map:action name="auth-logout" 
src="org.apache.cocoon.webapps.authentication.acting.LogoutAction"/>
                <map:action name="auth-loggedIn" 
src="org.apache.cocoon.webapps.authentication.acting.LoggedInAction"/>
 
<authentication-manager>
                        <handlers>
 
                                <handler name="foo-handler" 
xmlns:map="http://apache.org/cocoon/sitemap/1.0" 
xmlns:sunshine="http://sunshine.sundn.de/sunshine/1.0">
                                                 <redirect-to 
uri="cocoon://foo-loginpage"/>
                                                 <authentication 
uri="cocoon:raw://foo-authuser" />
                                </handler>
 
                        </handlers>
    </authentication-manager>


<map:match pattern="foo-loginpage">
              <map:generate src="src/user/loginpage.xml" />
              <map:transform src="src/user/loginpage.xsl" />
              <map:transform type="encodeURL" />
              <map:serialize />
       </map:match>
 
       <map:match pattern="foo-login">
                                  <map:act type="auth-login">
                                    <map:parameter name="handler" 
value="foo-handler"/>
                                    <map:parameter name="parameter_name" 
value="request:name"/>
                                    <map:parameter 
name="parameter_password" value="request:password"/>
                                    <!-- If the authentication is 
successfull then this redirect will be performed -->
                                    <map:redirect-to uri="create_ticket"/>
                                  </map:act>
                                  <!-- authentication failed: -->
                                  <map:generate src="login-failed.xml"/>
                                  <map:transform src="login-failed.xsl"/>
                                 <map:serialize/>
      </map:match>
 
 
  <map:match pattern="foo-authuser">
                                    <map:generate 
src="scr/user/foo-user.xml" />
                                    <map:transform 
src="scr/user/foo-user.xsl">
                                       <map:parameter 
name="use-request-parameters" value="true" />
                                    </map:transform>
                                    <map:serialize type = "xml" />
      </map:match>

   <map:match pattern="foo-protected">
                                   <map:act type="auth-protect">
                                       <map:parameter name="handler" 
value="foo-handler"/>
                                       <map:generate 
src="foo-resource.xml"/>
                                   </map:act>
                                   <map:transform src = 
"foo-resource.xsl"/>
                                   <map:serialize />
      </map:match>
 



and i got this info in 
foo-user.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<authentication>
    <ID>roel</ID>
    <password>roel</password>
    <role>admin</role> <!-- optional -->
    <data>
        Any additional optional information can be supplied here. 
        This will be stored in the session for later retrieval
    </data>
</authentication>


and in foo-user.xsl

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="password"/>
<xsl:param name="name"/>

<xsl:template match="authentication">

<authentication>

 <xsl:apply-templates select="users"/>

</authentication>
</xsl:template>

<xsl:template match="users">

<xsl:apply-templates select="user"/>

</xsl:template>

<xsl:template match="user">

<xsl:if test="normalize-space(name) = $name and normalize-space(password) 
= $password">

 <ID><xsl:value-of select="name"/></ID>
 <role><xsl:value-of select="role"/></role>
 <data>
  <name><xsl:value-of select="name"/></name>
  <role><xsl:value-of select="role"/></role>
  <ID><xsl:value-of select="name"/></ID>
  <user><xsl:value-of select="name"/></user>
 </data>
</xsl:if>
</xsl:template>

</xsl:stylesheet>


loginpage.xml
<?xml version="1.0"?>
<content>
 <form>
  <url>foo-login?resource=foo-protected</url>
  <field name="name" type="text" length="24" description="User"/>
  <field name="password"    type="password" length="10" 
description="Password"/>
 </form>
</content>


loginpage.xsl

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="content">
 <html>
  <form method="post" target="_top"><xsl:attribute 
name="action"><xsl:value-of 
select="normalize-space(form/url)"/></xsl:attribute>
        <table>
          <xsl:apply-templates select="form/field"/><br/>
  </table>
  <input type="submit" value="Login"></input>
 </form>
 </html>
</xsl:template>


<xsl:template match="field">
 <tr>
  <td>
   <font face="Arial, Helvetica, sans-serif" size="2"><xsl:value-of 
select="@description"/>:</font>
  </td>
  <td>
   <input>
    <xsl:attribute name="name"><xsl:value-of 
select="@name"/></xsl:attribute>
    <xsl:attribute name="type"><xsl:value-of 
select="@type"/></xsl:attribute>
    <xsl:attribute name="size"><xsl:value-of 
select="@length"/></xsl:attribute>
   </input>
  </td>
 </tr>

</xsl:template>

<!-- Copy all and apply templates -->

<xsl:template match="@*|node()">
   <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
   </xsl:copy>
  </xsl:template>

</xsl:stylesheet>




thank you

roel