我正在测试某些 URL 的安全限制。我觉得网址模式表现得很奇怪。我希望访问限制 ServletSecurityTest(webapproot)/
之后的任何内容。但是,在 websphere 中部署 war 文件后,甚至 ServletSecurityTest(webapproot) 本身也受到限制。为什么 ?
例如:
我希望限制此http//ravi-pc:9080/ServletSecurityTest/testSecurity.do
。这个没关系。但即使是 http//ravi-pc:9080/ServletSecurityTest
也受到限制。为什么?
有什么想法吗?
web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>Servlet Security Resources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Administrator</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>Administrator</role-name>
</security-role>
Servlet
@WebServlet(name="SecurityTestServlet", urlPatterns={"/testSecurity.do"})
public class SecurityTestServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("Only Administrators can see this...");
}
}
最佳答案
<url-pattern>/*</url-pattern>
表示 /
之后的所有 URL .
/testSecurity.do and /testSecurity
两者都属于您指定的模式。
尝试<url-pattern>/*.do</url-pattern>
看看吧。
关于java - 安全约束 <url-pattern> 行为异常 - websphere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270985/