【发布时间】:2013-09-23 09:32:03
【问题描述】:
好的,我之前曾在经典 web.xml 中使用过这种技术,但现在我使用的是 WebApplicationInitializer,无法让它工作。
我的 WebApplicationInitializer 包含以下代码:
HttpConstraintElement constraint = new HttpConstraintElement(
TransportGuarantee.NONE,
new String[]{"sponsorUsers"});
ServletSecurityElement servletSecurity =
new ServletSecurityElement(constraint);
dispatcher.setServletSecurity(servletSecurity);
我正在尝试为 servlet 中的任何资源请求的任何 http 方法要求基本身份验证(用户名+密码)。 我得到的只是一个 403 - 没有提示输入用户名。 我怀疑我需要将 auth-method 设置为 BASIC,就像在 xml 中一样:
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>User Auth</realm-name>
</login-config>
但在 Java 类中看不到等价物。有什么帮助吗?谢谢!
【问题讨论】:
标签: java spring tomcat servlets