0

I have an app using jsf2, jboss 6.1 and seam 3. I want to do something like this:

if the user tries to access the app and is not authenticated, he should be directed to the login page. If the user, is already logged in even if he types the login url he should be directed to a home page, and not login again. So I put this on faces-config.xml

<navigation-rule>
    <navigation-rule>
    <from-view-id>/login.xhtml</from-view-id>
    <navigation-case>
        <if>#{identity.loggedIn}</if>
        <to-view-id>/user/search.xhtml</to-view-id>
        <redirect>
            <view-param>
                <name>cid</name>
                <value>#{userBean.conversation.id}</value>
            </view-param>
        </redirect>
    </navigation-case>
</navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-action>#{identity.login}</from-action>
        <if>#{identity.loggedIn}</if>
        <to-view-id>/user/search.xhtml</to-view-id>
        <redirect>
            <view-param>
                <name>cid</name>
                <value>#{userBean.conversation.id}</value>
            </view-param>
        </redirect>
    </navigation-case>
    <navigation-case>
        <from-action>#{identity.login}</from-action>
        <from-outcome>failed</from-outcome>
        <to-view-id>/denied.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/login.xhtml</to-view-id>
        <redirect />
    </navigation-case>
</navigation-rule>

But the first rule doesnt work. If the user types the url with the login.xhtml he stays on the page. I need him to be redirected. How can I do that?

Thanks

Kelly

Kelly Goedert
  • 1,027
  • 2
  • 11
  • 37

1 Answers1

0

I think you have to use the seam-faces module. It's integrated with seam-security. You should take à look at this part of the doc.

In my project, I dont use any navigation rules and my Pages configuration object looks like this :

@ViewConfig
public interface Pages {
    static enum Configuration {
        @ViewPattern("/pages/*")
        @LoggedIn
        PRIVATE,

        @UrlMapping(pattern="/pages/home.xhtml")
        @ViewPattern("/login.xhtml")
        @FacesRedirect(false)
        LOGIN,

        @ViewPattern("/*")
        @FacesRedirect
        @LoginView("/login.xhtml")
        ALL;

    }

}

This other question also helped me doing what you need.

Community
  • 1
  • 1
baraber
  • 3,296
  • 27
  • 46