web.xml に次のものがあるwebappの場合testapp
(とりわけ)
<security-constraint>
<web-resource-collection>
<web-resource-name>My JSP</web-resource-name>
<url-pattern>*.secured</url-pattern>
<url-pattern>/login</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>mobileusers</role-name>
</auth-constraint>
<!--
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
-->
</security-constraint>
<login-config>
<auth-method>DIGEST</auth-method>
<realm-name>Identity</realm-name>
</login-config>
<security-role>
<description>
No Description
</description>
<role-name>mobileusers</role-name>
</security-role>
次の 2 つの Tomcat レルム構成を検討してください。
構成 1 - JDBC レルム:
の.../webapps/testapp/META-INF/context.xml
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionName="mysqluser"
connectionPassword="redacted"
connectionURL="jdbc:mysql://192.168.1.5/testdb?autoReconnectForPools=true&characterEncoding=UTF-8"
digest="MD5"
userTable="Users"
userNameCol="name"
userCredCol="password"
userRoleTable="Users"
roleNameCol="roleName"
/>
構成 2 - データソース レルム:
で.../webapps/testapp/META-INF/context.xml
:
<Realm className="org.apache.catalina.realm.DataSourceRealm"
digest="MD5"
userTable="Users"
userNameCol="name"
userCredCol="password"
userRoleTable="Users"
roleNameCol="roleName"
dataSourceName="jdbc/testDB"
/>
そしてで.../conf/context.xml
:
<Resource
name="jdbc/testDB"
auth="Container"
type="javax.sql.DataSource"
removeAbandoned="true"
removeAbandonedTimeout="15"
maxActive="5"
maxIdle="5"
maxWait="7000"
username="mysqluser"
password="redacted"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.1.5/testdb?autoReconnectForPools=true&characterEncoding=UTF-8"
factory="com.mycompany.util.configuration.customfactory"
validationQuery="SELECT '1';"
testOnBorrow="true"/>
はっきりしない理由により、構成 1 は機能しますが、構成 2 は機能しません。構成 2 の Context.xml リソースを使用して、あらゆる場所でコード内の MySQL に接続していることに注意してください。これはうまく機能します。ただし、Tomcat レルムがそれを使用しようとすると、構成 1 と同じことを行っているように見えても、認証は常に失敗します。
これがなぜなのか、誰にも洞察がありますか?