gpt4 book ai didi

java - protected URL 将网页中未 protected 组件泄露给未经身份验证的用户

转载 作者:行者123 更新时间:2023-12-02 01:07:23 27 4
gpt4 key购买 nike

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

我尝试通过上述第一种方法(使用 <login-config> + <security-constraint> + <security-role> )来实现安全性,但发现使用 protected 和不 protected HTML 组件的 protected 网页甚至会向未经身份验证的资源提供不 protected 资源用户。

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

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

最佳答案

这确实是两种截然不同的方式。 <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 限制对某些资源的访问,你必须设置它的<url-pattern>还有:

<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>

您只需在其他地方定义角色,也许是 <init-param>过滤器。

关于java - protected URL 将网页中未 protected 组件泄露给未经身份验证的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7872265/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com