yap*_*m01 2 java authentication servlets forms-authentication java-ee
我正在尝试基于表单的身份验证,但是我不知道为什么,在登录页面上输入正确的用户名/密码后,它将重定向我到错误页面而不是index.jsp。
当我输入:
http://localhost:8080/<context>/secure/index.jsp
Run Code Online (Sandbox Code Playgroud)
我得到登录页面。但是,当我输入用户名/密码(manager / manager)时,它将带我到error.html而不是index.jsp。
WEB.XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>FormBasedAuthentication</display-name>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/error.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>role1</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>SecurePages</web-resource-name>
<description>Security constraint for JSP resources</description>
<url-pattern>/secure/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>role1</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
TOMCAT-USER.XML:
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<role rolename="manager-jmx"/>
<role rolename="role1"/>
<user username="manager" password="manager" roles="role1"/>
</tomcat-users>
Run Code Online (Sandbox Code Playgroud)
在成功的身份验证和对/ secure / *的请求之间发生了一些错误。例如,可能是未为特定的HTTP方法配置过滤器,或者servlet引发了异常,在这种情况下,该异常可能与auth失败相混淆。如果您是我,请使用一个临时servlet(或jsp:error.jsp)替换error.html,以仔细检查请求,以获取有关失败原因的详细信息。这些请求属性应进行检查:
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
String exceptionType = (String) request.getAttribute("javax.servlet.error.exception_type");
String errorMsg = (String) request.getAttribute("javax.servlet.error.message");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4049 次 |
| 最近记录: |