gpt4 book ai didi

authentication - j_security 检查总是将我重定向到身份验证失败错误页面

转载 作者:行者123 更新时间:2023-11-28 22:31:52 27 4
gpt4 key购买 nike

这是我第一次尝试在 Java Web 应用程序中使用 j_security 检查表单例份验证。我正在使用 Eclipse 3.6 和 Apache Tomcat 6.0.28。

问题描述:当我提交带有有效凭据的登录表单时,j_security 检查将我重定向到 error.html 中定义的错误页面。当我使用无效凭据提交时,它还会将我带到 error.html 页面。这很好,但对于有效用户,我希望在登录后被带到 protected 资源。

login.html

    <!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>
</head>
<body>
<form method=post action="j_security_check">
Username <input type="text" name="j_username"><br />
Password <input type="password" name= "j_password"><br />
<input type="submit" value="submit">
</form>
</body>
</html>

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/ui/index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/security/login.html</form-login-page>
<form-error-page>/security/error.html</form-error-page>
</form-login-config>
</login-config>

<security-constraint>
<display-name>URLsConstraintMechanism</display-name>
<web-resource-collection>
<web-resource-name>clientURL</web-resource-name>
<url-pattern>/ui/*</url-pattern>
<http-method>GET</http-method>
<http-method>PUT</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>


<security-role>
<description>The Only Secure Role</description>
<role-name>tomcat</role-name>
</security-role>

</web-app>

tomcat-users.xml

     <role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>

我也没有在我的 IDE 控制台或 $CATALINA_HOME/logs 文件夹中看到任何错误

我是本论坛的新手,如有遗漏请见谅。我搜索了现有的主题,但到目前为止,没有任何建议对我有用。

最佳答案

要检查的一件事是 tomcat-users.xml 文件,如果您从 eclipse 运行 tomcat,eclipse 会创建一对单独的 server.xmltomcat-users.xml,与tomcat安装目录中默认的不同。通过在“服务器”选项卡下双击您的 tomcat 服务器,检查服务器配置路径,尝试找到正确的配置参数。

还要检查 server.xml 中的 Realm,如果您使用 tomcat-users.xml 文件存储用户和密码,请使用 Memory Realm

<Realm className="org.apache.catalina.realm.MemoryRealm" />

关于authentication - j_security 检查总是将我重定向到身份验证失败错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13503574/

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