You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Nicolas Antoniazzi <ni...@gmail.com> on 2011/06/01 11:21:25 UTC
Perform a specific operation as a privileged user
Hello,
I do not know exactly how to run a specific operation during my process as a
priviliged user.
Here is my example where I am logged as a normal user
public void createMyEntity() {
myDao.insert(entityToSave); // Operation that can be performed by a normal
user
if(entityToSave.hasSpecialProperty()) {
myDao.updateSpecialProperty(entityToSave); // Operation that has to be
performed by special user
}
}
I wanted to use SecurityUtil.getSubject().runAs(), but I do not know how to
retrieve PrincipalCollections associated to my special user.
How could I do this ?
Thanks,
Nicolas.
Re: Perform a specific operation as a privileged user
Posted by Les Hazlewood <lh...@apache.org>.
Hi Nicolas,
Yep, this is the recommended approach!
Cheers,
Les
On Wed, Jun 1, 2011 at 6:27 AM, Nicolas Antoniazzi
<ni...@gmail.com> wrote:
> I found my answer :
> PrincipalCollection pc = new SimplePrincipalCollection(myUserId, "myRealm");
> SecurityUtils.getSubject().runAs(pc);
> 2011/6/1 Nicolas Antoniazzi <ni...@gmail.com>
>>
>> Hello,
>> I do not know exactly how to run a specific operation during my process as
>> a priviliged user.
>> Here is my example where I am logged as a normal user
>> public void createMyEntity() {
>> myDao.insert(entityToSave); // Operation that can be performed by a
>> normal user
>>
>> if(entityToSave.hasSpecialProperty()) {
>> myDao.updateSpecialProperty(entityToSave); // Operation that has to be
>> performed by special user
>> }
>> }
>> I wanted to use SecurityUtil.getSubject().runAs(), but I do not know how
>> to retrieve PrincipalCollections associated to my special user.
>> How could I do this ?
>> Thanks,
>> Nicolas.
Re: Perform a specific operation as a privileged user
Posted by Nicolas Antoniazzi <ni...@gmail.com>.
I found my answer :
PrincipalCollection pc = new SimplePrincipalCollection(myUserId, "myRealm");
SecurityUtils.getSubject().runAs(pc);
2011/6/1 Nicolas Antoniazzi <ni...@gmail.com>
> Hello,
>
> I do not know exactly how to run a specific operation during my process as
> a priviliged user.
> Here is my example where I am logged as a normal user
>
> public void createMyEntity() {
> myDao.insert(entityToSave); // Operation that can be performed by a
> normal user
>
> if(entityToSave.hasSpecialProperty()) {
> myDao.updateSpecialProperty(entityToSave); // Operation that has to be
> performed by special user
> }
> }
>
> I wanted to use SecurityUtil.getSubject().runAs(), but I do not know how to
> retrieve PrincipalCollections associated to my special user.
> How could I do this ?
>
> Thanks,
>
> Nicolas.
>