【问题标题】:Glassfish Security Realms and Rewrite rules with PrettyFacesGlassfish 安全领域和使用 PrettyFaces 重写规则
【发布时间】:2015-07-12 04:22:30
【问题描述】:

我在保护我的应用程序页面时遇到问题。这是我的 PrettyFaces 重写规则:

<url-mapping id="cms"> 
      <pattern value="/administrator" /> 
      <view-id value="/faces/backend/index.xhtml" />
</url-mapping>

这是我在 web.xml 中的安全配置:

<security-constraint>
    <display-name>Admin Pages</display-name>
    <web-resource-collection>
        <web-resource-name>Protected Admin Area</web-resource-name>
        <description/>
        <url-pattern>/faces/backend/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>HEAD</http-method>
        <http-method>PUT</http-method>
        <http-method>OPTIONS</http-method>
        <http-method>TRACE</http-method>
        <http-method>DELETE</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>admin</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>JDBCRealm</realm-name>
    <form-login-config>
        <form-login-page>/faces/login/login.xhtml</form-login-page>
        <form-error-page>/faces/login/loginerror.xhtml</form-error-page>
    </form-login-config>
</login-config>

如您所见,我想保护以下所有视图:

 /faces/backend/*

但问题是这样的。当我去 url (rewrite) 比如:

 http://mydomain/administrator

应用程序应重定向到登录页面,因为此 url 导致 /faces/backend/* 下的安全视图。但是用户可以在这个页面上进入。

当我使用 url 时:

 http://mydomain/faces/backend/index.xhtml

安全工作正确。但我也想确保重写规则。如何解决?我将不胜感激。

【问题讨论】:

    标签: jakarta-ee jsf-2 url-rewriting glassfish prettyfaces


    【解决方案1】:

    我更喜欢这样保护资源:

    1. 所有 .xhtml 资源都放在/WEB-INF/views (它们变得无法通过直接链接访问)

    2. 我所有的 sequrity 设置都使用了重写的 URL

    <web-resource-collection>  
      <web-resource-name>protected-pages</web-resource-name>  
      <url-pattern>/administration/*</url-pattern>  
      <url-pattern>/moderation/*</url-pattern>
    </web-resource-collection>
    

    或者您可以使用多个 url 模式来保护您的资源(但这不是最佳解决方案)

      <url-pattern>/faces/backend/*</url-pattern>
      <url-pattern>/administrator</url-pattern>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多