[jboss-user] [JBoss Seam] - Does #{identity.login} start a long running conversation?

schmatz do-not-reply at jboss.com
Sun Feb 25 07:02:52 EST 2007


Hello guys,

I'm a bit confused. Does #{identity.login} start a long running conversation? I'm just asking because after successfully logging in, my User entity bean which I have outjected in the Authenticator.authenticate() method and injected in my conversational-scoped Stateful EJB still lives after every other click.

I have no @Begin/@End annotations declared myself.

Here's the beginning of my EJB:

@Stateful
  | @Scope(ScopeType.CONVERSATION)
  | @Name("userAction")
  | public class UserActionImpl implements UserAction
  | {
  |     @Logger private Log log;
  |     
  |     @In
  |     FacesMessages facesMessages;
  | 
  |     @In(value="entityManager")
  |     private EntityManager em;
  |    
  |     @In(required=false) @Out(required=false)
  |     private User user;
  | 
  | [...]

And here's my Authenticator class:

@Name("authenticator")
  | public class Authenticator
  | {
  |     @Logger Log log;
  |     
  |     @In
  |     private Identity identity;
  | 
  |     @In(value="entityManager")
  |     private EntityManager entityManager;
  | 
  |     @Out(required=false)
  |     private User user;
  |     
  |     public boolean authenticate()
  |     {
  |         log.info("authenticating #0", identity.getUsername());
  |         
  |         //write your authentication logic here,
  |         //return true if the authentication was
  |         //successful, false otherwise
  | 
  |         try
  |         {
  | 	        user = (User) entityManager.createQuery(
  | 		        "from User where username = :username and password = :password")
  | 		        .setParameter("username", identity.getUsername())
  | 		        .setParameter("password", identity.getPassword())
  | 		        .getSingleResult();
  | 	
  | 	        if( user.getRoles() != null )
  | 	        {
  | 	           for( Role role : user.getRoles() )
  | 	        	   identity.addRole(role.getName());
  | 	        }
  | 	        
  | 	        //FacesMessages.instance().add("Successfully authenticated #0", identity.getUsername());
  | 	        log.info("Successfully authenticated #0", identity.getUsername());
  | 	        return true;
  |         }
  |         catch( NoResultException e )
  |         {
  |         	//FacesMessages.instance().add("Invalid username/password");
  |         	log.info("authentication of #0 failed.", identity.getUsername());
  |         	return false;
  |         }
  |         catch( Exception e )
  |         {
  |         	FacesMessages.instance().add("Unexpected error occurred.");
  |         	log.error("Unexpected error occurred", e);
  |         	return false;
  |         }
  |     }
  | }

Like you can see: it's just out- and injecting the User which I expect to live for only one cycle (when no long running conversation exists). But I can click on my 'show-user-details' form as many times as I want and - magic - every other time the user's properties are displayed. Don't misunderstand me, this is exactly the behaviour I want but I thought I would have to start a long running conversation manually.

Can someone explain that 'magic' to me?

Thanks i.a.,
Mark



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4021943#4021943

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4021943



More information about the jboss-user mailing list