通过简单地将此添加到web.xml来实现基于official tutorial表单的身份验证:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginform.html</form-login-page>
<form-error-page>/loginerror.html</form-error-page>
</form-login-config>
</login-config>
我这样做了,但部署时会忽略web.xml。
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ig
nored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specifi
ed as 'true')
loginForm.jsp是这样的:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>loginForm.jsp</title>
</head>
<body>
<h2>Please login to add employees</h2>
<form action="j_security_check" method=post>
<p><strong>Username: </strong>
<input type="text" name="j_username" size="25">
<p><p><strong>Password: </strong>
<input type="password" size="15" name="j_password">
<p><p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
完整的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"
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_2_5.xsd">
<display-name>form_auth</display-name>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginform.html</form-login-page>
<form-error-page>/loginerror.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
</web-app>
如何实现基于表单的身份验证?
答案 0 :(得分:0)
对我来说太短了。触发基于表单的登录没有安全约束,因此从不使用它。
否则,没有任何内容,没有servlet,没有默认页面。我想web.xml解析器会优化登录配置,因为它永远不会被触发,然后你会留下一个空的描述符 - 然后被忽略。
尝试在&#34; /&#34;上添加安全约束。路径或某个子路径,然后尝试使用浏览器访问它。这应该会触发您的表单登录配置。
更新:你可以在你提到的JBoss教程中找到安全约束描述以及如何在#34;基于表单的登录&#34;之前的一章。 https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Security_Guide/Web_Content_Security_Constraints.html