gpt4 book ai didi

java - 安全约束不适用于 FORM 身份验证方法

转载 作者:行者123 更新时间:2023-12-02 06:56:11 27 4
gpt4 key购买 nike

我想使用 Glassfish 3.1.2 实现基于表单的身份验证。我的目标是使/faces/user 文件夹中的内容仅在登录后可用,因此从此文件夹中检索任何页面都应重定向到登录页面。不幸的是,重定向不起作用。

我在 web.xml 中使用以下配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/signin.xhtml</form-login-page>
<form-error-page>/faces/error.xhtml</form-error-page>
</form-login-config>
</login-config>


<security-role>
<description/>
<role-name>users</role-name>
</security-role>


<security-constraint>
<display-name>Restricted to users</display-name>
<web-resource-collection>
<web-resource-name>Restricted Access</web-resource-name>
<url-pattern>/faces/user/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>users</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>

</web-app>

问题是,我可以直接打开http://domain.com/faces/user/dashboard.xhtml并查看内容。没有显示登录表单!

如果我改变

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/faces/signin.xhtml</form-login-page>
<form-error-page>/faces/error.xhtml</form-error-page>
</form-login-config>
</login-config>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>jdbc-realm</realm-name>
</login-config>

显示了 HTML 身份验证,但我无法访问 http://domain.com/faces/user/dashboard.xhtml没有提供正确的凭据。

我的安全限制出了什么问题?

感谢任何帮助。提前致谢

最佳答案

您仍然需要提供基于表单的身份验证的领域:

<login-config>
<auth-method>FORM</auth-method>
<realm-name>jdbc-realm</realm-name>
<form-login-config>
<form-login-page>/faces/signin.xhtml</form-login-page>
<form-error-page>/faces/error.xhtml</form-error-page>
</form-login-config>
</login-config>

关于java - 安全约束不适用于 FORM 身份验证方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17317699/

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