我正在尝试使用Derby网络数据库保护Tomcat的管理员访问权限。为此,我创建了一个具有所有必要的Derby网络数据库。
这是我的server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<Resource auth="Container" driverClassName="org.apache.derby.jdbc.ClientDriver" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" maxActive="20" maxIdle="10" name="jdbc/***" password="***" readOnly="false" type="javax.sql.DataSource" url="jdbc:derby://localhost:1527//***" username="***" validationQuery="SELECT count(*) FROM users"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.DataSourceRealm" dataSourceName="jdbc/***" debug="0" digest="MD5" roleNameCol="ROLENAME" userCredCol="PASSWORD" userNameCol="USERNAME" userRoleTable="***" userTable="USERS"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="***" path="***" reloadable="true" source="org.eclipse.jst.jee.server:tds"/></Host>
</Engine>
</Service>
</Server>
我的context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/***" name="jdbc/***" type="javax.sql.DataSource"/>
</Context>
derbyclient.jar,derbynet.jar,derby.jar位于$ Tomcat目录$ / libs
当我初始化tomcat时,一切似乎都没问题但是如果我尝试访问管理器它会返回以下错误:
ene 26, 2015 4:58:56 PM org.apache.catalina.realm.DataSourceRealm open
SEVERE: Exception performing authentication
java.lang.IllegalStateException: Connection factory returned null from createConnection
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:584)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:388)
at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:284)
at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:573)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
也许缺少了什么?我不知道我做错了什么,因为我在生产服务器上检查了一个类似的配置,没有区别。很明显,Derby网络DB已初始化(我可以用松鼠打开它)
我很感激任何贡献
编辑:
嘿伙计们,配置还可以,但我在资源网址jdbc中遇到错误:derby:// localhost:1527 // C:*** \ derbydb - &gt; JDBC:德比://本地主机:1527 / C:*** \ derbydb
希望我的配置对某人有用