You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by hussayn <hu...@saxess.com> on 2008/09/13 12:00:14 UTC

Authentication-block: how to access user credentials from flowscript ?

Hi;

I installed the cocoon-authentication block (cocoon-2.2).
The installation looks like it was successfull, my pages
are secured and i get the login-mask as expected.

Now i want to create a flow-script, where i want to access the
current credentials (i.e. the current userId) and pass this information
to a .jx script for display.

I followed the description in

http://cocoon.apache.org/2.2/blocks/auth/1.0/1318_1_1.html

and created an initial flow script as follows:

function bookingPage() 
{
   var appMan = cocoon.getComponent(ApplicationManager.class.getName());
   if ( appMan.isLoggedIn("cocoon-app") ) 
   {
      cocoon.sendPageAndWait("booking.jx", {} );
   } 
   else
   {
      // No, not logged in
   }

}

I get a runtime error:

Caused by: org.mozilla.javascript.EvaluatorException: 
"file:///d:/booking.js", line 3: missing name after . operator
"file:///d:/booking.js", line 1: Compilation produced 1 syntax errors.

So what is wrong in this line:
var appMan = cocoon.getComponent(ApplicationManager.class.getName()); 

How to proceed ?
And then after i got this initial setup running, how would i have to call
for the userId ?
Is there something like appMan.getUserId() or similar ? Is there some
documentation about the
authentication-api available? and how the data is accessible from a
flowscript ?

thanks in advance,
regards, hussayn
-- 
View this message in context: http://www.nabble.com/Authentication-block%3A-how-to-access-user-credentials-from-flowscript---tp19469122p19469122.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Re: Authentication-block: how to access user credentials from flowscript ?

Posted by Benjamin Boksa <ma...@boksa.de>.
>> I use the following code to access the currently authenticated User  
>> in
>> flowscript:
>>
>>    var appUtil =
>> cocoon.createObject('org.apache.cocoon.auth.ApplicationUtil');
>>    var user = appUtil.getUser();
>>
>> The last call returns an instance of my User object which implements
>> the org.apache.cocoon.auth.User interface. Using that interface you
>> should be able to develop a specific User class for your application.
>> A good starting point are Alessandro's examples [1].
>>
>
> Thank you very much for this information. That worked out of the box.
> I only needed to tweek my setup a bit for my purposes:
>
> I added this to my test-application context : (don't worry,
> the final application will use another authentication class ;-)

Take a look at the auth package's source. You'll find some useful  
interfaces and classes there. The rest should be a bit of spring  
configuration and a few lines of code :-)

Good luck / Viel Glück

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


Re: Authentication-block: how to access user credentials from flowscript ?

Posted by hussayn <hu...@saxess.com>.
Hi, Benjamin

Benjamin Boksa-2 wrote:
> 
> I use the following code to access the currently authenticated User in  
> flowscript:
> 
>     var appUtil =  
> cocoon.createObject('org.apache.cocoon.auth.ApplicationUtil');
>     var user = appUtil.getUser();
> 
> The last call returns an instance of my User object which implements  
> the org.apache.cocoon.auth.User interface. Using that interface you  
> should be able to develop a specific User class for your application.  
> A good starting point are Alessandro's examples [1].
> 

Thank you very much for this information. That worked out of the box.
I only needed to tweek my setup a bit for my purposes:

I added this to my test-application context : (don't worry, 
the final application will use another authentication class ;-)

===== application-context.xml ===================================

  <bean name="org.apache.cocoon.auth.SecurityHandler/simple"
                       
class="org.apache.cocoon.auth.impl.SimpleSecurityHandler"
                        scope="singleton">
        <property name="userProperties">
                <value>
                        manager=mana
                        manager.roles=admin_admin
                        manager.name=King Salomon
                </value>
        </property>
  </bean>

  <bean name="org.apache.cocoon.auth.Application/cocoon-app"
                       
class="org.apache.cocoon.auth.impl.StandardApplication"
                        scope="singleton">

  <property name="securityHandler"
ref="org.apache.cocoon.auth.SecurityHandler/simple"/>

==== end application-context.xml
=============================================

I needed the user's true name, so i simply added another property
"manager.name=<full name>"
to the security-handler bean above. And i was able to retrieve the full name
from within the flowscript
below:

function bookingPage() 
{
    var appUtil =
cocoon.createObject('org.apache.cocoon.auth.ApplicationUtil');
    var user    = appUtil.getUser();
    var userName= user.getAttribute("name");
    cocoon.sendPage("booking.jx", { userId: user.id, userName: userName } );
}

It works like a charm! Thanks again!

regards,
hussayn

-- 
View this message in context: http://www.nabble.com/Authentication-block%3A-how-to-access-user-credentials-from-flowscript---tp19469122p19491431.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Re: Authentication-block: how to access user credentials from flowscript ?

Posted by Benjamin Boksa <ma...@boksa.de>.
> How to proceed ?
> And then after i got this initial setup running, how would i have to  
> call
> for the userId ?
> Is there something like appMan.getUserId() or similar ? Is there some
> documentation about the
> authentication-api available? and how the data is accessible from a
> flowscript ?


Hi Hussayn,

I use the following code to access the currently authenticated User in  
flowscript:

    var appUtil =  
cocoon.createObject('org.apache.cocoon.auth.ApplicationUtil');
    var user = appUtil.getUser();

The last call returns an instance of my User object which implements  
the org.apache.cocoon.auth.User interface. Using that interface you  
should be able to develop a specific User class for your application.  
A good starting point are Alessandro's examples [1].

HTH

Benjamin

[1] http://devel.alessandro.vincelli.name/item/28.html	

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