views:

409

answers:

2

My webapp needs to auto-login when the user access the app url:

example:

http://myapp/home.xhtml?token={3bcdc006-05fc-4ce1-953a-17375edcf2a2}

on my pages.xml i have the following:
<pages xmlns="http://jboss.com/products/seam/pages"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"

       no-conversation-view-id="/home.xhtml"
       login-view-id="/login.xhtml">

When no conversation is active the default is home.xhtml and when the user reach the home.xhtml with a token parameter i wish that a action be called and log in the user.

any tutorial or example for that?

and if no parameter is called i wish to raise a org.jboss.seam.security.AuthorizationException so the user get redirected to error.xhtml

Thanks in advance

A: 

This is similar to question

get-request-and-session-parameters-and-attributes-from-jsf-pages

Some googling shows you can access request parameters using the faces context and the built in map, param, wich has your request parameters. So, I'd sort of suggest you'd have a request bean that is loaded on the home.xhtml which checks the facesContext and raises an org.jboss.seam.security.AuthorizationException to get JBOSS to handle the login.

FacesContext ctx = FacesContext.getCurrentInstance();
String requestToken = ctx.getApplication().createValueBinding("#{param.token}").getValue(ctx);
Martlark
+3  A: 

Read up on page parameters in the Seam Documentation.

In your pages.xml you would specify something like:

<pages>
      <page view-id="/home.xhtml" action="#{backingBean.checkToken}">
          <param name="token" value="#{backingBean.token}"/>
      </page>
</pages>

This will populate the variable token with the value from the URL and call the checkToken() method. In your checkToken() method you could check if the User is already logged in, and if not then check that the token has been populated, and if not then throw the AuthorizationException

Damo
Looking up on 2.1 docs its just what I needed, thanks for the navigation rule.Perfect answer.
Kamia