You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Ben Short <be...@benshort.co.uk> on 2009/10/13 14:32:23 UTC

Retriving details about the current user

Hi,

Is it possible to retrieve details about the user making the request?

Example:

I want to allow users to register on my site. This will result in a
user node being created under /users possible with the node name equal
to their email address. For instance /users/john.doh@email.com.

Once the user has registered and signed in they would be able to
access/edit content under their node accessible via link on a webpage.
While generating these links in my GET.jsp how can I find the
john.doh@email.com of the user making the request?

The users email address may not be the best node name probably better
to user first and last name or a unique user name. In fact looking at
the jackrabbit-usermanager bundel the name of the user supplied when
creating the user would be a good node name. But I digress.

How to get the username of the user making the request in my jsp file?

Regards

Ben Short

Re: Retriving details about the current user

Posted by Ben Short <be...@benshort.co.uk>.
Thanks Alexander thats exactly what I needed.

2009/10/13 Alexander Klimetschek <ak...@day.com>:
> On Tue, Oct 13, 2009 at 14:32, Ben Short <be...@benshort.co.uk> wrote:
>> How to get the username of the user making the request in my jsp file?
>
> When logged in to the JCR (which is the default way in Sling), you can
> get the user id from the current session:
>
> session.getUserID();
>
> To get the session, you can do two things:
>
> Session session = currentNode.getSession();
> Session session = resourceResolver.adaptTo(Session.class);
>
> See also http://cwiki.apache.org/SLING/scripting-variables.html
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Re: Retriving details about the current user

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Oct 13, 2009 at 14:32, Ben Short <be...@benshort.co.uk> wrote:
> How to get the username of the user making the request in my jsp file?

When logged in to the JCR (which is the default way in Sling), you can
get the user id from the current session:

session.getUserID();

To get the session, you can do two things:

Session session = currentNode.getSession();
Session session = resourceResolver.adaptTo(Session.class);

See also http://cwiki.apache.org/SLING/scripting-variables.html

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com