1

The Tomcat Realm (Forms) authentification in my JSP project worked well before i changed OS to linux, now it doesn't: login is always fails.

IDE is IDEA.

The project uses:

  • 8.0.9 Tomcat JDBCRealm
  • PostgreSql 9.3
  • Postgres JDBC driver is in /WEB-INF/lib dir and visible by Hibernate as org.postgresql.Driver
  • Postgres login&pass are correct and table names are correct too

Changes in 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 &quot;%r&quot; %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&amp;password=123"
           userTable="users" 
           userNameCol="name" 
           userCredCol="pass"
           userRoleTable="user_roles" 
           roleNameCol="role"/>
 </Realm>

... actually, I changed nothing there except moving LockOutRealm to <Host> tag and adding JDBCRealm block into.

The web.xml is correct, because it worked well before...

Why doesn't it work? Maybe it's about linux user's privilege?

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 log:

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
BillHaggerty
  • 6,157
  • 10
  • 35
  • 68
WildDev
  • 2,250
  • 5
  • 35
  • 67
  • 1
    Please provide your error message and the setting ins `pg_hba.conf`. – Erwin Brandstetter Jul 25 '14 at 19:31
  • @ErwinBrandstetter, i added `pg_hba.conf` to the Q as you ask. About error - here's no error. It just redirects me to "login fail" page like i enter wrond pass – WildDev Jul 25 '14 at 19:39
  • 1
    What error message do you see in the database log? – Erwin Brandstetter Jul 25 '14 at 19:42
  • 1
    Obviously you never reach the database. Check your connection settings. Maybe the wrong port? Is Postgres really running on the same machine as your client? [And is Postgres listening?](http://stackoverflow.com/questions/9639080/connecting-cakephp-2-0-with-postgresql/9639288#9639288) – Erwin Brandstetter Jul 25 '14 at 19:50
  • @ErwinBrandstetter, the port 5432 for sure. Postgres and project on single machine. I read links you gave to me, but your post is dissapear:( So could `host` issue be an error? – WildDev Jul 25 '14 at 19:54
  • I deleted my answer because my first lead was wrong. The `host` entry seems right. Check the [new link in my comment about `listen_addresses`](http://stackoverflow.com/questions/9639080/connecting-cakephp-2-0-with-postgresql/9639288#9639288). – Erwin Brandstetter Jul 25 '14 at 19:55
  • Ah, ok. `listen_addresses = '*'` setted up, so i think it do – WildDev Jul 25 '14 at 19:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58022/discussion-between-yamaha-and-erwin-brandstetter). – WildDev Jul 25 '14 at 20:02
  • 2
    "Postgres JDBC driver is in /WEB-INF/lib" No, You need to place it in the lib/ directory of Tomcat, not inside your webapp. – nos Jul 25 '14 at 20:16
  • @nos: I suggest you make that an answer. – Erwin Brandstetter Jul 25 '14 at 20:28

2 Answers2

2

A Realm in Tomcat is managed outside your webapp, so the JDBC driver needs to be available to the Tomcat runtime.

This means you must place the jdbc driver in the $TOMCAT_HOME/lib directory, and not in WEB-INF/lib/ inside your webapp.

nos
  • 223,662
  • 58
  • 417
  • 506
1

It seems like you never reach the database. Is Postgres even listening? Make sure you have set up listen_addresses in postgresql.conf.

More details:

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • thank you for your time! The problem solved by moving `Postgres` driver from `/WEB-INF/lib` to Tomcat's `lib` directory. – WildDev Jul 25 '14 at 20:24