SEC-441: Fix. Added suggested changes.

This commit is contained in:
Luke Taylor 2007-08-30 19:42:35 +00:00
parent 2e8d16c538
commit 8cb836c6cf
2 changed files with 25 additions and 5 deletions

View File

@ -15,6 +15,11 @@
package org.acegisecurity.adapters.jboss; package org.acegisecurity.adapters.jboss;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.acegisecurity.AccountExpiredException; import org.acegisecurity.AccountExpiredException;
import org.acegisecurity.Authentication; import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException; import org.acegisecurity.AuthenticationException;
@ -75,8 +80,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
} }
protected Group[] getRoleSets() throws LoginException { protected Group[] getRoleSets() throws LoginException {
SimpleGroup roles = new SimpleGroup("Roles"); Group roles = new SimpleGroup("Roles");
Group[] roleSets = {roles}; Group callerPrincipalGroup = new SimpleGroup("CallerPrincipal");
if (this.identity instanceof Authentication) { if (this.identity instanceof Authentication) {
Authentication user = (Authentication) this.identity; Authentication user = (Authentication) this.identity;
@ -86,7 +91,9 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
} }
} }
return roleSets; callerPrincipalGroup.addMember(getIdentity());
return new Group[] {roles, callerPrincipalGroup};
} }
protected String[] getUsernameAndPassword() throws LoginException { protected String[] getUsernameAndPassword() throws LoginException {

View File

@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.acegisecurity.adapters.PrincipalAcegiUserToken; import org.acegisecurity.adapters.PrincipalAcegiUserToken;
import org.jboss.security.SimplePrincipal; import org.jboss.security.SimplePrincipal;
import org.jboss.security.SimpleGroup;
import java.io.IOException; import java.io.IOException;
@ -27,6 +28,7 @@ import java.security.Principal;
import java.security.acl.Group; import java.security.acl.Group;
import java.util.Properties; import java.util.Properties;
import java.util.Enumeration;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import javax.security.auth.callback.Callback; import javax.security.auth.callback.Callback;
@ -318,11 +320,23 @@ public class JbossAcegiLoginModuleTests extends TestCase {
assertTrue(adapter.login()); assertTrue(adapter.login());
Group[] result = adapter.getRoleSets(); Group[] result = adapter.getRoleSets();
assertEquals(1, result.length); // SimpleGroup called "Roles" // Expect Roles and CallerPrincipal groups.
assertEquals(2, result.length);
Group roles = result[0]; Group roles = result[0];
assertTrue(roles.isMember(new SimplePrincipal("ROLE_TELLER"))); assertTrue(roles.isMember(new SimplePrincipal("ROLE_TELLER")));
assertTrue(roles.isMember(new SimplePrincipal("ROLE_SUPERVISOR"))); assertTrue(roles.isMember(new SimplePrincipal("ROLE_SUPERVISOR")));
Group callerPrincipalGroup = result[1];
// check the name
assertTrue(callerPrincipalGroup.equals(new SimpleGroup("CallerPrincipal")));
Enumeration members = callerPrincipalGroup.members();
assertTrue("CallerPrincipal group must have exactly one member", members.hasMoreElements());
Principal principal = (Principal) members.nextElement();
if (!(principal instanceof PrincipalAcegiUserToken)) {
fail("Should have returned PrincipalAcegiUserToken");
}
assertTrue("CallerPrincipal group must have exactly one member", !members.hasMoreElements());
} }
//~ Inner Classes ================================================================================================== //~ Inner Classes ==================================================================================================
@ -337,7 +351,6 @@ public class JbossAcegiLoginModuleTests extends TestCase {
} }
private MockCallbackHandler() { private MockCallbackHandler() {
super();
} }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {