在同一台服务器上,我需要部署同一个 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&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&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中的其他内容。当我只使用一个应用程序测试它时(当我不需要上下文标签时),身份验证工作。
预先感谢您的帮助 !