-
1. Re: RunAsOperation issue?
shane.bryzak Sep 18, 2008 11:28 PM (in response to zergspirit)This was an oversight, I've updated the docs now. Instead of overriding the getRoles() method, you simply need to call addRole() before calling run(), like this:
new RunAsOperation() { public void execute() { // do stuff here } }.addRole("admin") .run()
-
2. Re: RunAsOperation issue?
zergspirit Sep 19, 2008 10:21 AM (in response to zergspirit)Works perfectly, thanks!
-
3. Re: RunAsOperation issue?
accless Nov 10, 2008 12:40 PM (in response to zergspirit)I have the scenario where i need to add several roles temporarily and the amount of those roles is also dynamically. Is there a convinient way of adding several roles?
(until 2.0 the getRoles-Method was perfect for me)greetings
-
4. Re: RunAsOperation issue?
shane.bryzak Nov 10, 2008 1:30 PM (in response to zergspirit)RunAsOperation op = new RunAsOperation() { public void execute() { // do stuff here } }; for (String role : tempRoles) { op.addRole(role); } op.run();
-
5. Re: RunAsOperation issue?
accless Nov 10, 2008 1:33 PM (in response to zergspirit)That was my idea, too. But the RunAsOperation is ABSTRACT, thats why i cannot store the instanze in a variable!
Greetings
-
6. Re: RunAsOperation issue?
shane.bryzak Nov 11, 2008 3:02 AM (in response to zergspirit)Er, you're right of course. Ok, as a workaround you can try the following code (it's a little messy, sorry) and I'll do something to improve this for the next release.
new RunAsOperation() { public void execute() { for (String role : roles) { for ( Group sg : getSubject().getPrincipals(Group.class) ) { if ( Identity.ROLES_GROUP.equals( sg.getName() ) ) { sg.addMember(new SimplePrincipal(role)); break; } } SimpleGroup roleGroup = new SimpleGroup(Identity.ROLES_GROUP); roleGroup.addMember(new SimplePrincipal(role)); getSubject().getPrincipals().add(roleGroup); } // execute privileged operations here } }.run();
-
7. Re: RunAsOperation issue?
shane.bryzak Nov 11, 2008 3:09 AM (in response to zergspirit)I've just committed a change to SVN, now the addRole() method will add the role directly to the subject. That means, you can simply call addRole() in the execute() method and the role will be properly added to that operation.
-