You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2002/06/30 22:19:41 UTC

DO NOT REPLY [Bug 10361] New: - JDBCRealm requires restart if JDBC connection fails.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10361>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10361

JDBCRealm requires restart if JDBC connection fails.

           Summary: JDBCRealm requires restart if JDBC connection fails.
           Product: Tomcat 4
           Version: 4.0.3 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Catalina
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: rthomas-contrib@liveintellect.org


If the JDBC connection obtained by JDBCRealm fails in ways other than throwing 
an SQLException (such as would be the case if the database forced the 
connection closed because of an idle timeout, or the database was bounced), 
JDBCRealm doesn't appear to handle any thing other than SQLException and 
remains non-operational until tomcat is restarted.

The current behavior would frustrate users by making their first attempt to log 
into a server with a failed JDBC connection even if they typed their password 
in correctly.  It is also frustrating for the server administrator if the JDBC 
driver does not always wrap other failures and rethrow them as SQLExceptions.

It would be better if JDBCRealm attempted to reconnect within the first call to 
authenticate and made this attempt upon any failure of the "cached" connection 
(i.e. catch Throwable). 

Changes could be as follows (unless someone thinks of a better way):

    public Principal authenticate(String username, String credentials) {
      return authenticate(username, credentials, true);
    }

    private final Principal authenticate(String username, String credentials, 
       boolean firstTry) {

        Connection dbConnection = null;

        try {

            // Ensure that we have an open database connection
            dbConnection = open();

            // Acquire a Principal object for this user
            Principal principal = authenticate(dbConnection,
                                               username, credentials);

            // Release the database connection we just used
            release(dbConnection);

            // Return the Principal (if any)
            return (principal);

        } catch (Throwable t) {
            if (firstTry) { // recurse and try one more time while we're here
              return authenticate(username, password, false);
            }
            else {   // give up and hope something changes before next login
              // Log the problem for posterity
              log(sm.getString("jdbcRealm.exception"), t);

              // Close the connection so that it gets reopened next time
              if (dbConnection != null)
                  close(dbConnection);

              // Return "not authenticated" for this request
              return (null);
            }

        }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>