Author: shane.bryzak(a)jboss.com
Date: 2008-05-20 23:47:34 -0400 (Tue, 20 May 2008)
New Revision: 8240
Modified:
trunk/src/main/org/jboss/seam/security/RunAsOperation.java
Log:
change way roles are added to RunAsOperation
Modified: trunk/src/main/org/jboss/seam/security/RunAsOperation.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/RunAsOperation.java 2008-05-20 19:17:15 UTC
(rev 8239)
+++ trunk/src/main/org/jboss/seam/security/RunAsOperation.java 2008-05-21 03:47:34 UTC
(rev 8240)
@@ -2,6 +2,8 @@
import java.security.Principal;
import java.security.acl.Group;
+import java.util.HashSet;
+import java.util.Set;
import javax.security.auth.Subject;
@@ -16,10 +18,13 @@
private Principal principal;
private Subject subject;
+ private Set<String> roles;
+
public RunAsOperation()
{
principal = new SimplePrincipal(null);
subject = new Subject();
+ roles = new HashSet<String>();
}
public abstract void execute();
@@ -34,38 +39,29 @@
return subject;
}
- public String[] getRoles()
+ public RunAsOperation addRole(String role)
{
- return null;
+ roles.add(role);
+ return this;
}
- private boolean addRole(String role)
- {
- for ( Group sg : getSubject().getPrincipals(Group.class) )
- {
- if ( Identity.ROLES_GROUP.equals( sg.getName() ) )
- {
- return sg.addMember(new SimplePrincipal(role));
- }
- }
-
- SimpleGroup roleGroup = new SimpleGroup(Identity.ROLES_GROUP);
- roleGroup.addMember(new SimplePrincipal(role));
- getSubject().getPrincipals().add(roleGroup);
-
- return true;
- }
-
public void run()
- {
- String[] roles = getRoles();
- if (roles != null)
+ {
+ for (String role : roles)
{
- for (String role : getRoles())
+ for ( Group sg : getSubject().getPrincipals(Group.class) )
{
- addRole(role);
+ 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);
+ }
Identity.instance().runAs(this);
}
Show replies by date