nacho 00/12/28 15:59:31 Modified: src/share/org/apache/tomcat/request Tag: tomcat_32 JDBCRealm.java LocalStrings.properties Log: Now is needed to have both a connectionName and a connectionPassword to use the 3 params getConnection method Thanks to David Weinrich [[EMAIL PROTECTED]] for catch this Revision Changes Path No revision No revision 1.9.2.5 +35 -37 jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java Index: JDBCRealm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v retrieving revision 1.9.2.4 retrieving revision 1.9.2.5 diff -u -r1.9.2.4 -r1.9.2.5 --- JDBCRealm.java 2000/12/10 23:36:45 1.9.2.4 +++ JDBCRealm.java 2000/12/28 23:59:31 1.9.2.5 @@ -282,17 +282,9 @@ public synchronized boolean authenticate(String username, String credentials) { try { - // Establish the database connection if necessary - if ((dbConnection == null) || dbConnection.isClosed()) { - log(sm.getString("jdbcRealm.authDBClosed")); - dbConnection = DriverManager.getConnection(connectionURL); - if( (dbConnection == null) || dbConnection.isClosed() ) { - log(sm.getString("jdbcRealm.authDBReOpenFail")); - return false; - } - dbConnection.setReadOnly(true); + if (!checkConnection()) { + return false; } - // Create the authentication search prepared statement if necessary if (preparedAuthenticate == null) { String sql = "SELECT " + userCredCol + " FROM " + userTable + @@ -352,15 +344,8 @@ public synchronized String[] getUserRoles(String username) { try { - if( (dbConnection == null) || dbConnection.isClosed() ) { - log(sm.getString("jdbcRealm.getUserRolesDBClosed")); - - dbConnection = DriverManager.getConnection(connectionURL); - - if( dbConnection == null || dbConnection.isClosed() ) { - log(sm.getString("jdbcRealm.getUserRolesDBReOpenFail")); - return null; - } + if( !checkConnection()) { + return null; } if (preparedRoles == null) { String sql = "SELECT " + roleNameCol + " FROM " + @@ -419,25 +404,8 @@ public void contextInit(Context ctx) throws org.apache.tomcat.core.TomcatException { // Validate and update our current component state - if (!started) { + if (!started && checkConnection() ) { started = true; - try { - Class.forName(driverName); - if ((connectionName == null || connectionName.equals("")) && - (connectionPassword == null || connectionPassword.equals(""))) { - dbConnection = DriverManager.getConnection(connectionURL); - } else { - dbConnection = DriverManager.getConnection(connectionURL, - connectionName, - connectionPassword); - } - } - catch( ClassNotFoundException ex ) { - throw new RuntimeException("JDBCRealm.start.readXml: " + ex); - } - catch( SQLException ex ) { - throw new RuntimeException("JDBCRealm.start.readXml: " + ex); - } } } @@ -445,6 +413,7 @@ throws org.apache.tomcat.core.TomcatException { // Validate and update our current component state if (started) { + started=false; if( dbConnection != null ) { try { dbConnection.close(); @@ -529,6 +498,35 @@ } return 401; //HttpServletResponse.SC_UNAUTHORIZED // XXX check transport + } + + private boolean checkConnection(){ + try { + if( (dbConnection == null) || dbConnection.isClosed() ) { + Class.forName(driverName); + log(sm.getString("jdbcRealm.checkConnectionDBClosed")); + if ((connectionName == null || connectionName.equals("")) || + (connectionPassword == null || connectionPassword.equals(""))) { + dbConnection = DriverManager.getConnection(connectionURL); + } else { + dbConnection = DriverManager.getConnection(connectionURL, + connectionName, + connectionPassword); + } + if( dbConnection == null || dbConnection.isClosed() ) { + log(sm.getString("jdbcRealm.checkConnectionDBReOpenFail")); + return false; + } + } + return true; + }catch (SQLException ex){ + log(sm.getString("jdbcRealm.checkConnectionSQLException")); + log ("SQLException: "+ex); + return false; + } + catch( ClassNotFoundException ex ) { + throw new RuntimeException("JDBCRealm.checkConnection: " + ex); + } } } 1.1.2.1 +2 -4 jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -u -r1.1 -r1.1.2.1 --- LocalStrings.properties 2000/06/10 14:36:12 1.1 +++ LocalStrings.properties 2000/12/28 23:59:31 1.1.2.1 @@ -4,8 +4,6 @@ jdbcRealm.authenticateSQLException=There was an SQLException while in authenticate: {0} jdbcRealm.getUserRolesSQLException=There was an SQLException while in getUserRoles: {0} jdbcRealm.notStarted=This Realm has not yet been started -jdbcRealm.authDBClosed=The database connection is null or was found to be closed. Trying to re-open it. -jdbcRealm.authDBReOpenFail=The re-open on the database failed. The database could be down. -jdbcRealm.getUserRolesDBClosed=The database connection is null or was found to be closed. Trying to re-open it. -jdbcRealm.getUserRolesDBReOpenFail=The re-open on the database failed. The database could be down. +jdbcRealm.checkConnectionDBClosed=The database connection is null or was found to be closed. Trying to re-open it. +jdbcRealm.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.