我的JSP项目中的Tomcat Realm (Forms)身份验证在我将操作系统更改为linux之前工作得很好,现在它不工作了:登录总是失败。
IDE是IDEA.
项目使用:
- Tomcat JDBCRealm
- PostgreSql 9.3
- Postgres JDBC驱动程序在/WEB-INF/lib目录中,并且在Hibernate中可见为
org.postgresql.Driver
- Postgres login&pass是正确的,表名也是正确的
server.xml的修改:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm
className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Realm
className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://localhost:5432/postgres?user=postgres&password=123"
userTable="users"
userNameCol="name"
userCredCol="pass"
userRoleTable="user_roles"
roleNameCol="role"/>
</Realm>
…实际上,除了将LockOutRealm
移动到<Host>
标签并将JDBCRealm
块添加到。
web.xml
是正确的,因为它之前工作得很好…
为什么不工作?也许是关于linux用户的特权吗?
pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres md5
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Postgres日志:
2014-07-25 19:52:17 MSK LOG: database system was shut down at 2014-07-25 19:52:07 MSK
2014-07-25 19:52:17 MSK LOG: database system is ready to accept connections
2014-07-25 19:52:17 MSK LOG: autovacuum launcher started
2014-07-25 19:53:57 MSK LOG: incomplete startup packet
2014-07-25 19:53:59 MSK LOG: incomplete startup packet
2014-07-25 22:39:38 MSK LOG: unexpected EOF on client connection with an open transaction
2014-07-25 22:42:15 MSK LOG: unexpected EOF on client connection with an open transaction
Tomcat中的Realm是在web应用程序之外管理的,因此JDBC驱动程序需要对Tomcat运行时可用。
这意味着您必须将jdbc驱动程序放在$TOMCAT_HOME/lib
目录中,而不是WEB-INF/lib/中。
似乎您从未访问过数据库。Postgres在听吗?确保在postgresql.conf
中设置了listen_addresses
。
更多细节:
- 连接cakephp 2.0和PostgreSQL
- pg_hba.conf文件出错