Authentication Tomcat 7:针对多个Web应用程序使用多个UserDatabaseRealms进行身份验证

Authentication Tomcat 7:针对多个Web应用程序使用多个UserDatabaseRealms进行身份验证,authentication,tomcat,Authentication,Tomcat,在同一台服务器上,我需要部署同一webapp的两个版本(一个用于生产,另一个用于验证) 这两个webapp使用不同数据库的身份验证。 我正在努力为这两个应用程序实现两个不同的上下文 我在server.xml中实现了以下代码,但身份验证不再有效: <Context path="http://localhost:8080/myapp1" docBase="/path/webapps/myapp1.war" debug="0" privileged="true">

在同一台服务器上,我需要部署同一webapp的两个版本(一个用于生产,另一个用于验证)

这两个webapp使用不同数据库的身份验证。 我正在努力为这两个应用程序实现两个不同的上下文

我在server.xml中实现了以下代码,但身份验证不再有效:

        <Context path="http://localhost:8080/myapp1" docBase="/path/webapps/myapp1.war" debug="0" privileged="true">

          <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->

        <Realm className="org.apache.catalina.realm.LockOutRealm">
            <!-- This Realm uses the UserDatabase configured in the global JNDI
            resources under the key "UserDatabase".  Any edits
            that are performed against this UserDatabase are immediately
            available for use by the Realm.  -->
            <Realm className="org.apache.catalina.realm.JDBCRealm"
                driverName="org.postgresql.Driver" digest="MD5"
                connectionURL="jdbc:postgresql://localhost/postgres_prod?user=postgres&amp;password=postgres"
                userTable="utilisateurs" userNameCol="login" userCredCol="password"
                userRoleTable="user_roles" roleNameCol="role_name" resourceName="UserDatabase"/>


            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
        </Realm>
    </Context>

    <Context path="http://localhost:8080/myapp2" docBase="/path/webapps/myapp2.war" debug="0" privileged="true">

          <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->

        <Realm className="org.apache.catalina.realm.LockOutRealm">
            <!-- This Realm uses the UserDatabase configured in the global JNDI
            resources under the key "UserDatabase".  Any edits
            that are performed against this UserDatabase are immediately
            available for use by the Realm.  -->
            <Realm className="org.apache.catalina.realm.JDBCRealm"
                driverName="org.postgresql.Driver" digest="MD5"
                connectionURL="jdbc:postgresql://localhost/postgres_val?user=postgres&amp;password=postgres"
                userTable="utilisateurs" userNameCol="login" userCredCol="password"
                userRoleTable="user_roles" roleNameCol="role_name" resourceName="UserDatabase"/>


            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
        </Realm>
    </Context>

我不明白是否需要在web.xml或tomcat-users.xml中更改其他内容。 当我只使用一个应用程序测试身份验证时(当我不需要上下文标记时),身份验证就可以工作


提前感谢您的帮助

我在两个应用程序的Context.xml文件中移动了两个Context标记的内容。 另一个解决的问题是:使用server.xml中的这部分代码,我无法作为tomcat管理器登录