You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by na...@apache.org on 2001/07/06 22:59:35 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/request JDBCRealm.java
nacho 01/07/06 13:59:35
Modified: src/share/org/apache/tomcat/request Tag: tomcat_32
JDBCRealm.java
Log:
Bug# 2149 , 727 ( possibly others )
JDBCRealm did not close all the prepared staments opened,
when trying to reconnect when found a broken DBConnection,
I'ts a problem specillay surfaced when using MySQL..
Reported By :
mark.shotton at micromass.co.uk
andre.gommlich at netkom.de
edwin at finalist.com
kaneda at dedaletechnology.com
Revision Changes Path
No revision
No revision
1.9.2.10 +47 -56 jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/JDBCRealm.java
Index: JDBCRealm.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/JDBCRealm.java,v
retrieving revision 1.9.2.9
retrieving revision 1.9.2.10
diff -u -r1.9.2.9 -r1.9.2.10
--- JDBCRealm.java 2001/04/17 10:43:43 1.9.2.9
+++ JDBCRealm.java 2001/07/06 20:59:34 1.9.2.10
@@ -318,30 +318,14 @@
log(sm.getString("jdbcRealm.authenticateSQLException",
username));
log("SQLException: " + ex);
+ close();
- // Clean up the JDBC objects so that they get recreated next time
- if (preparedAuthenticate != null) {
- try {
- preparedAuthenticate.close();
- } catch (Throwable t) {
- ;
- }
- preparedAuthenticate = null;
- }
- if (dbConnection != null) {
- try {
- dbConnection.close();
- } catch (Throwable t) {
- ;
- }
- dbConnection = null;
- }
-
// Return "not authenticated" for this request
return false;
}
}
+
public synchronized String[] getUserRoles(String username) {
try {
if( !checkConnection()) {
@@ -380,30 +364,15 @@
log(sm.getString("jdbcRealm.getUserRolesSQLException",
username));
log("SQLException: " + ex);
- if (preparedRoles != null) {
- try {
- preparedRoles.close();
- } catch (Throwable t) {
- ;
- }
- preparedRoles = null;
- }
- if (dbConnection != null) {
- try {
- dbConnection.close();
- } catch (Throwable t) {
- ;
- }
- dbConnection = null;
- }
+ close();
}
- return null;
+ return null;
}
public void contextInit(Context ctx)
throws org.apache.tomcat.core.TomcatException {
- // Validate and update our current component state
+ // Validate and update our current component state
if (!started && checkConnection() ) {
started = true;
log(sm.getString("jdbcRealm.started"));
@@ -415,14 +384,7 @@
// Validate and update our current component state
if (started) {
started=false;
- if( dbConnection != null ) {
- try {
- dbConnection.close();
- }
- catch( SQLException ex ) {
- log("dbConnection.close Exception!!!");
- }
- }
+ close();
}
}
@@ -448,8 +410,8 @@
// This realm will use only username and password callbacks
String user=(String)cred.get("username");
String password=(String)cred.get("password");
-
- if( user !=null && password !=null ){
+
+ if( user !=null && password !=null ){
if ( authenticate( user, password ) ) {
if( debug > 0 ) log( "Auth ok, user=" + user );
req.setRemoteUser( user );
@@ -458,8 +420,8 @@
if (ctx != null)
req.setAuthType(ctx.getAuthMethod());
}
- }
- return 0;
+ }
+ return 0;
}
public int authorize( Request req, Response response, String roles[] )
@@ -473,16 +435,16 @@
String userRoles[]=null;
- String user=req.getRemoteUser();
- if( user==null )
+ String user=req.getRemoteUser();
+ if( user==null )
return 401; //HttpServletResponse.SC_UNAUTHORIZED
-
- if( debug > 0 )
+
+ if( debug > 0 )
log( "Controled access for " + user + " " + req + " "
+ req.getContainer() );
-
- userRoles = getUserRoles( user );
- req.setUserRoles( userRoles );
+
+ userRoles = getUserRoles( user );
+ req.setUserRoles( userRoles );
if( debug > 0 ) {
if ((userRoles != null) && (userRoles.length > 0))
@@ -500,7 +462,7 @@
else
log( "UnAuthorized - no roles specified");
}
- return 401; //HttpServletResponse.SC_UNAUTHORIZED
+ return 401; //HttpServletResponse.SC_UNAUTHORIZED
// XXX check transport
}
@@ -527,10 +489,39 @@
}catch (SQLException ex){
log(sm.getString("jdbcRealm.checkConnectionSQLException"));
log ("SQLException: "+ex);
+ close();
return false;
}
catch( ClassNotFoundException ex ) {
throw new RuntimeException("JDBCRealm.checkConnection: " + ex);
+ }
+ }
+
+ private void close() {
+ // Clean up the JDBC objects so that they get recreated next time
+ if (preparedRoles != null) {
+ try {
+ preparedRoles.close();
+ } catch (Throwable t) {
+ ;
+ }
+ preparedRoles = null;
+ }
+ if (preparedAuthenticate != null) {
+ try {
+ preparedAuthenticate.close();
+ } catch (Throwable t) {
+ ;
+ }
+ preparedAuthenticate = null;
+ }
+ if (dbConnection != null) {
+ try {
+ dbConnection.close();
+ } catch (Throwable t) {
+ ;
+ }
+ dbConnection = null;
}
}