-
1. Re: Where do I put actor.setId when using jaas authentication?
brieweb Sep 3, 2012 11:56 PM (in response to brieweb)I added the following to components.xml and it worked.
<event type="org.jboss.seam.security.postAuthenticate">
<action execute="#{authenticator.authenticate}"/>
</event>
Changed the authenticator bean to work as the postAuthenticate bean. I hope this doesn't create confusion.
import java.util.Enumeration;
import java.util.Iterator;
import javax.ejb.Stateless;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.bpm.Actor;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.SimpleGroup;
import org.jboss.seam.security.SimplePrincipal;
@Stateless
@Name("authenticator")
public class AuthenticatorBean implements Authenticator
{
@Logger private Log log;
@In Identity identity;
@In Credentials credentials;
@In private Actor actor;
public boolean authenticate()
{
log.info("authenticating {0}", identity.getPrincipal().getName());
//actor.setId(identity.getUsername());
actor.setId(identity.getPrincipal().getName());
Iterator principleItr = identity.getSubject().getPrincipals().iterator();
while(principleItr.hasNext()){
Object principle = principleItr.next();
if (principle instanceof SimpleGroup){
SimpleGroup simpleGroup = (SimpleGroup) principle;
Enumeration simpleGroupMembers = simpleGroup.members();
while(simpleGroupMembers.hasMoreElements()){
SimplePrincipal aPrincipal = (SimplePrincipal)simpleGroupMembers.nextElement();
actor.getGroupActorIds().add(aPrincipal.getName());
}
}
}
return true;
}
}