首先是一些细节:我在 web.xml 视图中将安全配置如下,将纯副本复制到剪贴板打印?
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/formLoginPage.html</form-login-page>
<form-error-page>/formErrorPage.html</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>MyBeerApp</web-resource-name>
<url-pattern>/web/form.html</url-pattern>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>member</role-name>
</auth-constraint>
<user-data-constraint>
<!--transport-guarantee>CONFIDENTIAL</transport-guarantee-->
</user-data-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>member</role-name>
</security-role>
<security-role>
<role-name>guest</role-name>
</security-role>
在tomcat-user.xml 中如下:查看plaincopy 到剪贴板打印?
<role rolename="member"/>
<role rolename="guest"/>
<user username="vgarg2" password="tomcat" roles="member,guest" />
<user username="vgarg3" password="tomcat" roles="guest" />
文件的位置如下:查看纯副本到剪贴板打印?
<TOMCAT_HOME>\Beer-v1\index.html
<TOMCAT_HOME>\Beer-v1\web\form.html
<TOMCAT_HOME>\Beer-v1\WEB-INF\web.xml
<TOMCAT_HOME>\Beer-v1\WEB-INF\classes\...
form.html 的内容:
查看plaincopy到剪贴板打印?
<html>
<body>
<h1 align="center">Beer Selection Page</h1>
<form method="POST" action="../SelectBeer.do">
Select Beer Characteristics
Color : <select name="color1" size="1">
<option value="light1">Light</option>
<option value="amber1">Amber</option>
<option value="brown1">Brown</option>
<option value="dark1">Dark</option>
</select>
<br/>
Can sizes:
<input type="checkbox" name="sizes" value="12oz">12 oz</input>
<input type="checkbox" name="sizes" value="24oz">24 oz</input>
<input type="checkbox" name="sizes" value="36oz">36 oz</input>
<br/>
<center>
<input type="submit"/>
</center>
</form>
</body>
<html>
现在我的问题是去“http://localhost:8080/Beer-v1/web/form.html”的请求没有受到限制。当我从 /web/form.html 向“http://localhost:8080/Beer-v1/SelectBeer.do”提交请求时,它会检查身份验证并询问 ID/密码信息。
如果我禁用安全约束,应用程序可以正常工作。
这里出了什么问题?