help with Identity.login() and acceptExternallyAuthenticatedPrincipal
hardaur Jun 23, 2009 6:53 PMI've written an application that authenticates to a remote SSO source. I'm getting a good Principal back, but can't seem to set up the session correctly. The code:
package com.mycom.myapp.session.security; import java.security.Principal; import javax.faces.context.FacesContext; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Install; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.Startup; import org.jboss.seam.annotations.intercept.BypassInterceptors; import org.jboss.seam.contexts.Contexts; import org.jboss.seam.log.LogProvider; import org.jboss.seam.log.Logging; import org.jboss.seam.security.Credentials; import org.jboss.seam.security.Identity; import static org.jboss.seam.annotations.Install.APPLICATION; @Name("org.jboss.seam.security.identity") @Scope(ScopeType.SESSION) @Install(precedence = APPLICATION) @BypassInterceptors @Startup public class CustomIdentity extends Identity { private static final LogProvider log = Logging.getLogProvider(CustomIdentity.class); @Override public String login() { try { Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); if (principal != null) { acceptExternallyAuthenticatedPrincipal(principal); } } catch (Exception e) { log.error(e,e); } return "loggedIn"; } @Override public boolean isLoggedIn() { if (! super.isLoggedIn()) login(); return super.isLoggedIn(); } }
I AM getting the principal and login does set the session to logged in, but it's not pulling in roles and the user doesn't seem to be getting into the session. Now, for the roles I figure I'll have to query for the users and add them to the identity manually, no big deal. However, I'm not sure what I need to do to insure the session knows what user is actually logged in (Identity.getUsername() returns null, but Identity.getPrincipal().getName() is correct).
Could somebody please shed some light on what I'm missing here. I'm at the very end of this project and it's getting a little frustrating.
Thanks!
Gerald