【问题标题】:Protected URLs leaking unprotected components of the webapge to unauthenticated users受保护的 URL 将网页中未受保护的组件泄露给未经身份验证的用户
【发布时间】:2011-10-24 07:05:18
【问题描述】:

我相信通过<login-config>+<security-constraint>+ <security-role> 和通过使用<filter> 为JSF 应用程序实现安全性是两种不同的方式!?是吗?

我尝试通过上面的第一种方法(使用<login-config>+<security-constraint>+ <security-role>)实现安全性,但发现我的受保护网页同时使用受保护和不受保护的 HTML 组件,即使向未经身份验证的人提供不受保护的资源用户。

我需要完全保护 URL,以便受保护的 URL 甚至不会将该网页的任何部分泄露给未经身份验证的用户。我该怎么办?

而且,在web.xml 中使用<filter> 的安全实现是一种处理安全的自我管理方式吗?我相信您可以在过滤/捕获每个请求时更细粒度地自定义安全性?

【问题讨论】:

  • 您的安全约束配置示例,以及要授权的 URL 会有所帮助

标签: java security jsf container-managed


【解决方案1】:

这确实是两种截然不同的方式。 <security-constraint> 是容器管理身份验证 (CMS) 的一部分。 Filter 是本地身份验证的一部分。

要通过 CMS 限制对某些资源的访问,您只需设置其 <url-pattern>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Application</web-resource-name>
        <url-pattern>/app/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>someRoleName</role-name>
    </auth-constraint>
</security-constraint>

上面的例子对所有匹配/app/*的URL设置了约束,并且只允许someRoleName的用户访问。

要使用Filter 限制对某些资源的访问,您还必须设置其&lt;url-pattern&gt;

<filter>
    <filter-name>authenticationFilter</filter-name>
    <filter-class>com.example.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>authenticationFilter</filter-name>
    <url-pattern>/app/*</url-pattern>
</filter-mapping>

您只需要在其他地方定义角色,也许作为过滤器的&lt;init-param&gt;

【讨论】:

    猜你喜欢
    • 2014-11-20
    • 1970-01-01
    • 2016-10-28
    • 2018-09-27
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多