Axe*_*ine 7 java tomcat http basic-authentication tomcat6
我有一个包含三个webapps的Tomcat 6服务器:一个自定义的ROOT,Jenkins和Nexus.
我想使用BASIC身份验证来集中保护所有三个(server.xml?).
如何在不修改或配置Web应用程序的情况下实现此目的?
首先,我尝试(没有成功)在conf/context.xml中包含BasicAuthenticator阀门.这似乎没有任何影响.
最后,我通过将此片段添加到conf/web.xml来使其工作(保护所有webapps):
<security-constraint>
<web-resource-collection>
<web-resource-name>Basic Authentication</web-resource-name>
<!--Here wildcard entry defines authentication is needed for whole app -->
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>myrole</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<description>My role</description>
<role-name>myrole</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)
想到两种方式: