2012-07-17 97 views
0

我使用JSF2有一个应用程序时,JBoss 6.1和缝3.我想要做这样的事情:JSF2导航问题

如果用户试图访问应用程序,未通过身份验证

,他应该被引导到登录页面。如果用户已经登录,即使他输入登录网址,他也应该被定向到主页,而不是再次登录。所以我把它放在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> 

但是第一条规则不起作用。如果用户使用login.xhtml键入网址,则他会保留在页面上。我需要他重定向。我怎样才能做到这一点?

感谢

凯利

回答

0

我认为你必须使用缝面模块。它与煤层安全相结合。 你应该看看this part of the doc

在我的项目,我不使用任何导航规则和我的网页配置对象看起来是这样的:

@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还帮我做你所需要的。