You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Fabrizio Scarcello <fa...@gmail.com> on 2010/06/11 16:45:36 UTC

Managing users and permissions programatically

Hi,
i would like to know if there is a way to manage users and permissions
programmatically (maybe there is a service that expose the necessary
methods?)...

The issue i have to resolve is this: a user has to register and create a new
account; i send him a mail with a confirmation link, and when he clicks on
the link he visits a page that should create his account. But the user is
not authenticated, so i can't post to the Sling REST services...
So i'm thinking to create the account in a programmatic way...
Is that possible? Are there other ways to resolve this situation?

Thanks and greetings,
Fabrizio Scarcello.

Re: Managing users and permissions programatically

Posted by Fabrizio Scarcello <fa...@gmail.com>.
I created this Jira issue:
https://issues.apache.org/jira/browse/SLING-1555

I proposed a quick way to realize the OSGI services, by simply mapping the
REST services with standard jcr classes.
In the case it's preferable to expose a dedicated API, i can propose one...

Greetings,
Fabrizio.

On 6/11/10 11:32 AM, Fabrizio Scarcello wrote:
> > Thank you for the quick response.. :-)
> > Ok, i understood i can use directly the Jackrabbit UserManager... that's
> > already good.. :-)
> > But can i also use the jackrabbit.usermanager and
> jackrabbit.accessmanager
> > bundles (they are already installed...)?
> > Is there a way to invoke the same methods that reply to the POST
> requests,
> > in a programmatic way (maybe an OSGI service..)?
> Not at present. These bundles don't expose any services. If this is
> something of interest to you, I'd suggest filing a JIRA. If possible,
> include a proposed API.
>
> Justin
>
> >
> > Many thanks,
> > Fabrizio.
> >
> > 2010/6/11 Justin Edelson <ju...@gmail.com>
> >
> >> On 6/11/10 10:45 AM, Fabrizio Scarcello wrote:
> >>> Hi,
> >>> i would like to know if there is a way to manage users and permissions
> >>> programmatically (maybe there is a service that expose the necessary
> >>> methods?)...
> >>>
> >>> The issue i have to resolve is this: a user has to register and create
> a
> >> new
> >>> account; i send him a mail with a confirmation link, and when he clicks
> >> on
> >>> the link he visits a page that should create his account. But the user
> is
> >>> not authenticated, so i can't post to the Sling REST services...
> >>> So i'm thinking to create the account in a programmatic way...
> >>> Is that possible? Are there other ways to resolve this situation?
> >>>
> >>> Thanks and greetings,
> >>> Fabrizio Scarcello.
> >>>
> >> Yes. You can use the Jackrabbit UserManager to do this from a
> >> script/servlet.
> >>
> >> You can use org.apache.sling.jcr.base.util.AccessControlUtil to easily
> >> get to the UserManager, e.g.
> >>
> >> Session session = repository.loginAdministrative(null);
> >> UserManager userManager = AccessControlUtil.getUserManager(session);
> >> User user = userManager.createUser(username, password);
> >> session.logout();
> >>
> >> I would suggest looking at the source of the jackrabbit.usermanager
> >> bundle. You will probably want to follow what is done there with respect
> >> to crypting the password and setting additional properites on the user
> >> nodes.
> >>
> >> With respect to permissions, the same thing is true, but you would use
> >> the AccessControlManager (Jackrabbit specific pre-JCR 2). Again, the
> >> jackrabbit.accessmanager bundle is a good point of reference for how to
> >> use this API.
> >>
> >> Justin
> >>
> >
>
>

Re: Managing users and permissions programatically

Posted by Justin Edelson <ju...@gmail.com>.
On 6/11/10 11:32 AM, Fabrizio Scarcello wrote:
> Thank you for the quick response.. :-)
> Ok, i understood i can use directly the Jackrabbit UserManager... that's
> already good.. :-)
> But can i also use the jackrabbit.usermanager and jackrabbit.accessmanager
> bundles (they are already installed...)?
> Is there a way to invoke the same methods that reply to the POST requests,
> in a programmatic way (maybe an OSGI service..)?
Not at present. These bundles don't expose any services. If this is
something of interest to you, I'd suggest filing a JIRA. If possible,
include a proposed API.

Justin

> 
> Many thanks,
> Fabrizio.
> 
> 2010/6/11 Justin Edelson <ju...@gmail.com>
> 
>> On 6/11/10 10:45 AM, Fabrizio Scarcello wrote:
>>> Hi,
>>> i would like to know if there is a way to manage users and permissions
>>> programmatically (maybe there is a service that expose the necessary
>>> methods?)...
>>>
>>> The issue i have to resolve is this: a user has to register and create a
>> new
>>> account; i send him a mail with a confirmation link, and when he clicks
>> on
>>> the link he visits a page that should create his account. But the user is
>>> not authenticated, so i can't post to the Sling REST services...
>>> So i'm thinking to create the account in a programmatic way...
>>> Is that possible? Are there other ways to resolve this situation?
>>>
>>> Thanks and greetings,
>>> Fabrizio Scarcello.
>>>
>> Yes. You can use the Jackrabbit UserManager to do this from a
>> script/servlet.
>>
>> You can use org.apache.sling.jcr.base.util.AccessControlUtil to easily
>> get to the UserManager, e.g.
>>
>> Session session = repository.loginAdministrative(null);
>> UserManager userManager = AccessControlUtil.getUserManager(session);
>> User user = userManager.createUser(username, password);
>> session.logout();
>>
>> I would suggest looking at the source of the jackrabbit.usermanager
>> bundle. You will probably want to follow what is done there with respect
>> to crypting the password and setting additional properites on the user
>> nodes.
>>
>> With respect to permissions, the same thing is true, but you would use
>> the AccessControlManager (Jackrabbit specific pre-JCR 2). Again, the
>> jackrabbit.accessmanager bundle is a good point of reference for how to
>> use this API.
>>
>> Justin
>>
> 


Re: Managing users and permissions programatically

Posted by Fabrizio Scarcello <fa...@gmail.com>.
Thank you for the quick response.. :-)
Ok, i understood i can use directly the Jackrabbit UserManager... that's
already good.. :-)
But can i also use the jackrabbit.usermanager and jackrabbit.accessmanager
bundles (they are already installed...)?
Is there a way to invoke the same methods that reply to the POST requests,
in a programmatic way (maybe an OSGI service..)?

Many thanks,
Fabrizio.

2010/6/11 Justin Edelson <ju...@gmail.com>

> On 6/11/10 10:45 AM, Fabrizio Scarcello wrote:
> > Hi,
> > i would like to know if there is a way to manage users and permissions
> > programmatically (maybe there is a service that expose the necessary
> > methods?)...
> >
> > The issue i have to resolve is this: a user has to register and create a
> new
> > account; i send him a mail with a confirmation link, and when he clicks
> on
> > the link he visits a page that should create his account. But the user is
> > not authenticated, so i can't post to the Sling REST services...
> > So i'm thinking to create the account in a programmatic way...
> > Is that possible? Are there other ways to resolve this situation?
> >
> > Thanks and greetings,
> > Fabrizio Scarcello.
> >
> Yes. You can use the Jackrabbit UserManager to do this from a
> script/servlet.
>
> You can use org.apache.sling.jcr.base.util.AccessControlUtil to easily
> get to the UserManager, e.g.
>
> Session session = repository.loginAdministrative(null);
> UserManager userManager = AccessControlUtil.getUserManager(session);
> User user = userManager.createUser(username, password);
> session.logout();
>
> I would suggest looking at the source of the jackrabbit.usermanager
> bundle. You will probably want to follow what is done there with respect
> to crypting the password and setting additional properites on the user
> nodes.
>
> With respect to permissions, the same thing is true, but you would use
> the AccessControlManager (Jackrabbit specific pre-JCR 2). Again, the
> jackrabbit.accessmanager bundle is a good point of reference for how to
> use this API.
>
> Justin
>

Re: Managing users and permissions programatically

Posted by Justin Edelson <ju...@gmail.com>.
On 6/11/10 10:45 AM, Fabrizio Scarcello wrote:
> Hi,
> i would like to know if there is a way to manage users and permissions
> programmatically (maybe there is a service that expose the necessary
> methods?)...
> 
> The issue i have to resolve is this: a user has to register and create a new
> account; i send him a mail with a confirmation link, and when he clicks on
> the link he visits a page that should create his account. But the user is
> not authenticated, so i can't post to the Sling REST services...
> So i'm thinking to create the account in a programmatic way...
> Is that possible? Are there other ways to resolve this situation?
> 
> Thanks and greetings,
> Fabrizio Scarcello.
> 
Yes. You can use the Jackrabbit UserManager to do this from a
script/servlet.

You can use org.apache.sling.jcr.base.util.AccessControlUtil to easily
get to the UserManager, e.g.

Session session = repository.loginAdministrative(null);
UserManager userManager = AccessControlUtil.getUserManager(session);
User user = userManager.createUser(username, password);
session.logout();

I would suggest looking at the source of the jackrabbit.usermanager
bundle. You will probably want to follow what is done there with respect
to crypting the password and setting additional properites on the user
nodes.

With respect to permissions, the same thing is true, but you would use
the AccessControlManager (Jackrabbit specific pre-JCR 2). Again, the
jackrabbit.accessmanager bundle is a good point of reference for how to
use this API.

Justin