使用BASIC身份验证集中保护所有tomcat webapps

Axe*_*ine 7 java tomcat http basic-authentication tomcat6

我有一个包含三个webapps的Tomcat 6服务器:一个自定义的ROOT,Jenkins和Nexus.

我想使用BASIC身份验证来集中保护所有三个(server.xml?).

如何在修改或配置Web应用程序的情况下实现此目的?

Axe*_*ine 7

首先,我尝试(没有成功)在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)


Sha*_*sky 6

想到两种方式:

  1. 您可以修改conf/context.xml,它将包含在所有 Web应用程序中,并在其中插入身份验证指令.缺点是,据我所知,您无法从身份验证中排除一个Web应用程序,并且所有Web应用程序将共享相同的角色要求(尽管这听起来像您需要的)
  2. 您可以通过apache或在Tomcat前运行的其他一些Web服务器来实现安全性.这是有道理的,特别是如果你已经有一个.