You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Zamek <za...@vili.pmmf.hu> on 2004/02/25 17:42:00 UTC

getting username from session after authentication

Hello All,

I need authenticated user's name in my xsl stylesheet to make different 
menus.
There is a session transformer in my sitemap.xmap:

   <map:match pattern="*.html">
       <map:aggregate element="office:document">
         <map:part src="zip://content.xml@{1}.sxw"/>
         <map:part src="zip://meta.xml@{1}.sxw"/>
         <map:part src="zip://styles.xml@{1}.sxw"/>
       </map:aggregate>

       <map:transform type="session"/>
       <map:transform src="../style/ooo2html.xsl">

         <map:parameter name="username" value="{session-context:user}"/> 
<----------------------- Here is my trying to get username

         <map:parameter name="template" value="nomenu.xml"/>
         <map:parameter name="doc_name" value="{1}"/>
         <map:parameter name="metaFileURL" value="zip://meta.xml@{1}.sxw"/>
         <map:parameter name="stylesFileURL" 
value="zip://styles.xml@{1}.sxw"/>
         <map:parameter name="absoluteSourceDirRef" value="{1}.sxw"/>
       </map:transform>

       <map:serialize type="html"/>
   </map:match>


and username variable is empty when I logged in :-(

How can I retrieve logged username in my sitemap or my stylesheet?

users.xml is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- $Id: userlist.xml,v 1.1 2003/03/09 00:02:23 pier Exp $ Description: All 
users -->
<authentication>
  <users>
    <user>
     <name>cocoon</name>
    </user>
    <user>
     <name>guest</name>
    </user>
  </users>
</authentication>


-- 
thx,
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: getting username from session after authentication

Posted by Zamek <za...@vili.pmmf.hu>.
Hi All,
On Friday 27 February 2004 14.45, Laurent Trillaud wrote:
> Declare this match in you sitemap
>             <map:match pattern="session-account.ccn">
>                 <map:act type="auth-protect">
>                     <map:parameter name="handler" value="demohandler" />
>
>                     <map:generate src="session-account.xml"/>
>                     <map:transform type="session"/>
>                     <map:serialize type="xml" />
>                 </map:act>
>             </map:match>
> with the following session-account.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <doc xmlns:session="http://apache.org/cocoon/session/1.0">
> 	<session:getxml context="authentication" path="/"/>
> </doc>
> You should see something like
> <doc>
>  <authenticate>
>   <ID>MyLoginName</ID>
>   ... and so on depends of your authenticate.xsl
>   ... the tag ID depends also of your authenticate.xsl
>  </authenticate>
> </doc>
Yes I see this:
<page>
  <doc>
    <authentication>
      <ID>guest</ID>
      <type>cocoon.authentication</type>
      <media>html</media>
    </authentication>
  </doc>
  <doc>
    <authenticate>
      <ID>MyLoginName</ID>
  ... and so on depends of your authenticate.xsl
  ... the tag ID depends also of your authenticate.xsl    
    </authenticate>
  </doc>
</page>

It means there is original authenticating context merged your xml.

> Assuming that the login is store in the ID tag. To access it use the
> following pipeline
> <map:match pattern="show-login">
>  <map:generate src="dummy.xml"/>
>  <map:transform src="xml2html.xsl">
>   <map:parameter name="username" value="{ID}"/
>  </map:transform>
>  <map:serialize type="html"/>
> </map:match>

Sorry username is empty :-(

-- 
thx,
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: getting username from session after authentication

Posted by Laurent Trillaud <lt...@jouve.fr>.
Zoltan
I give you a sample to see what you have in your context authentication. It
will help you to find the path to retrieve your login.
Declare this match in you sitemap
            <map:match pattern="session-account.ccn">
                <map:act type="auth-protect">
                    <map:parameter name="handler" value="demohandler" />
                    
                    <map:generate src="session-account.xml"/>
                    <map:transform type="session"/>
                    <map:serialize type="xml" />
                </map:act>
            </map:match>
with the following session-account.xml
<?xml version="1.0" encoding="UTF-8"?>
<doc xmlns:session="http://apache.org/cocoon/session/1.0">
	<session:getxml context="authentication" path="/"/>
</doc>
You should see something like
<doc>
 <authenticate>
  <ID>MyLoginName</ID>
  ... and so on depends of your authenticate.xsl
  ... the tag ID depends also of your authenticate.xsl
 </authenticate>
</doc>
Assuming that the login is store in the ID tag. To access it use the
following pipeline
<map:match pattern="show-login">
 <map:generate src="dummy.xml"/>
 <map:transform src="xml2html.xsl"> 
  <map:parameter name="username" value="{ID}"/
 </map:transform>            
 <map:serialize type="html"/>
</map:match>
Hope, that will be useful.
Laurent Trillaud

> Thanks for response, but I am a beginner in Cocoon and I don´t understand
> it, or it doesn´t works for me. :-(
> My goal is make different menus depending to valid users or anonymous
> user.
> I would like to make it my xsl if it possible.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: getting username from session after authentication

Posted by Zamek <za...@vili.pmmf.hu>.
Hi All,

On Thursday 26 February 2004 10.34, Laurent Trillaud wrote:
> Zoltan
> I guess that the authenticate action is missing. The authentication
> context isn't loaded
> Try this stuff
> <map:match pattern="*.html">
>   <map:act type="auth-protect">
>     blah blah
>     <map:parameter name="username" value="{name}"/>
>     blah blah
>   </map:act>
> </map:match>
>
> {name} or {user/name} that depend what you have done in the handler
> authentication uri.

Thanks for response, but I am a beginner in Cocoon and I don´t understand 
it, or it doesn´t works for me. :-(
My goal is make different menus depending to valid users or anonymous user.
I would like to make it my xsl if it possible.

I made a short test, please check and modify it:
my sitemap.xmap:
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

  <map:pipelines>
    <map:component-configurations>
      <authentication-manager>
        <handlers>
          <handler name="demohandler">
            <redirect-to uri="cocoon:/login"/>
            <authentication uri="cocoon:raw:/authenticate"/>
          </handler>
        </handlers>
      </authentication-manager>
    </map:component-configurations>

    <map:pipeline caching="off">
      
      <map:match pattern="">
        <map:redirect-to uri="index.html"/>
      </map:match>

      <map:match pattern="index.html">
        <map:generate src="index.xml"/>
        <map:transform src="stylesheets/simple-page2html.xsl"/>
        <map:transform type="encodeURL"/>
        <map:serialize/>
      </map:match>
      
      <map:match pattern="login">
        <map:act type="auth-loggedIn">
          <map:parameter name="handler" value="demohandler"/> 
          <map:redirect-to uri="index.html"/>
        </map:act> 
        <map:generate src="public/login.xml"/>
	<map:transform type="session"/>
        <map:transform src="stylesheets/simple-page2html.xsl">
	  <map:parameter name="use-request-parameter" value="true"/>
	</map:transform>
        <map:transform type="encodeURL"/>
        <map:serialize/>
      </map:match>

      <map:match pattern="do-login">
        <map:act type="auth-login">
          <map:parameter name="handler" value="demohandler"/>
          <map:parameter name="parameter_name" 
value="{request-param:username}"/>
          <map:redirect-to uri=""/>
        </map:act>
        <map:redirect-to uri="login"/>
      </map:match>

      <map:match pattern="protected-*">
        <map:act type="auth-protect">
          <map:parameter name="handler" value="demohandler"/> 	    
	  <map:parameter name="username" value="{username}"/> <------------------ 
here is your stuff 
	  <map:match pattern="protected-*.html">
            <map:generate src="private/{1}.xml"/>
	    <map:transform type="session"/>
            <map:transform src="stylesheets/simple-page2html.xsl"/>
            <map:transform type="encodeURL"/>
            <map:serialize/>
	  </map:match>
        </map:act>
        <map:redirect-to uri="login"/>
      </map:match>

      <map:match pattern="*.html">
        <map:generate src="public/{1}.xml"/>
        <map:transform type="session"/>
        <map:transform src="stylesheets/simple-page2html.xsl"/>
        <map:transform type="encodeURL"/>
        <map:serialize/>
      </map:match>
      <map:match pattern="do-logout">
        <map:act type="auth-protect">
          <map:parameter name="handler" value="demohandler"/> 
          <map:act type="auth-logout"/>
          <map:redirect-to uri="index.html"/>
        </map:act>
        <map:redirect-to uri="index.html"/>
      </map:match>
    </map:pipeline>

    <map:pipeline internal-only="true">
      <!-- This is the authentication resource -->
      <map:match pattern="authenticate">
        <map:generate src="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:pipelines>
</map:sitemap>

-- 
many thanks,
Zoltan Zidarics programmer
PTE University Pecs, Hungary
icq: 43288694


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: getting username from session after authentication

Posted by Laurent Trillaud <lt...@jouve.fr>.
Zoltan
I guess that the authenticate action is missing. The authentication context
isn't loaded
Try this stuff
<map:match pattern="*.html">
  <map:act type="auth-protect">
    blah blah
    <map:parameter name="username" value="{name}"/>
    blah blah
  </map:act>
</map:match>

{name} or {user/name} that depend what you have done in the handler
authentication uri.

Laurent Trillaud

> -----Message d'origine-----
> De : Zamek [mailto:zamek@vili.pmmf.hu]
> Envoyé : mercredi 25 février 2004 17:42
> À : users@cocoon.apache.org
> Objet : getting username from session after authentication
> 
> Hello All,
> 
> I need authenticated user's name in my xsl stylesheet to make different
> menus.
> There is a session transformer in my sitemap.xmap:
> 
>    <map:match pattern="*.html">
>        <map:aggregate element="office:document">
>          <map:part src="zip://content.xml@{1}.sxw"/>
>          <map:part src="zip://meta.xml@{1}.sxw"/>
>          <map:part src="zip://styles.xml@{1}.sxw"/>
>        </map:aggregate>
> 
>        <map:transform type="session"/>
>        <map:transform src="../style/ooo2html.xsl">
> 
>          <map:parameter name="username" value="{session-context:user}"/>
> <----------------------- Here is my trying to get username
> 
>          <map:parameter name="template" value="nomenu.xml"/>
>          <map:parameter name="doc_name" value="{1}"/>
>          <map:parameter name="metaFileURL"
> value="zip://meta.xml@{1}.sxw"/>
>          <map:parameter name="stylesFileURL"
> value="zip://styles.xml@{1}.sxw"/>
>          <map:parameter name="absoluteSourceDirRef" value="{1}.sxw"/>
>        </map:transform>
> 
>        <map:serialize type="html"/>
>    </map:match>
> 
> 
> and username variable is empty when I logged in :-(
> 
> How can I retrieve logged username in my sitemap or my stylesheet?
> 
> users.xml is:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!-- $Id: userlist.xml,v 1.1 2003/03/09 00:02:23 pier Exp $ Description:
> All
> users -->
> <authentication>
>   <users>
>     <user>
>      <name>cocoon</name>
>     </user>
>     <user>
>      <name>guest</name>
>     </user>
>   </users>
> </authentication>
> 
> 
> --
> thx,
> Zoltan Zidarics programmer
> PTE University Pecs, Hungary
> icq: 43288694
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org