Wednesday, May 19, 2010

"Autologin" with Seam

Sometimes we've just built our login routine in the traditional Seam way using the Identity instance wired to a form like:

In order to login the user automatically when i.e. clicking on a link we just need to add the following to pages.xml and to our Authenticator

So now the parameters will be automatically propagated by Seam and we can programmatically call login() on the Identity instance. In this example the URL would be /login.seam?username=xxx&password=xxx

Of course we could use the URL rewriter to make Seam react to more RESTful URLs. See the docs for that.


  1. This was very helpful to me...specially how you have implemented autoLogin.

  2. I have a follow up question for you. How would you handle logout? Normally, after logout, you would take user back to sign in page but since autologin is on, user will be automatically logged in again.

  3. Well, maybe it's enough to redirect them to an intermediate page that says "you are now logged out". Or you could make sure that the parameters necessary for the auto login are not present.