luehe 2005/02/18 11:17:57 Modified: catalina/src/share/org/apache/catalina/realm DataSourceRealm.java JAASCallbackHandler.java JAASMemoryLoginModule.java JDBCRealm.java JNDIRealm.java RealmBase.java UserDatabaseRealm.java Log: More logging cleanup Revision Changes Path 1.13 +23 -24 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java Index: DataSourceRealm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- DataSourceRealm.java 3 Feb 2005 15:14:34 -0000 1.12 +++ DataSourceRealm.java 18 Feb 2005 19:17:57 -0000 1.13 @@ -33,6 +33,9 @@ import org.apache.catalina.ServerFactory; import org.apache.catalina.core.StandardServer; import org.apache.catalina.util.StringManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @@ -50,6 +53,7 @@ public class DataSourceRealm extends RealmBase { + private static Log log = LogFactory.getLog(DataSourceRealm.class); // ----------------------------------------------------- Instance Variables @@ -290,7 +294,7 @@ } catch (SQLException e) { // Log the problem for posterity - container.getLogger().error(sm.getString("dataSourceRealm.exception"), e); + log.error(sm.getString("dataSourceRealm.exception"), e); // Return "not authenticated" for this request return (null); @@ -318,8 +322,8 @@ * authenticating this username */ protected Principal authenticate(Connection dbConnection, - String username, - String credentials) throws SQLException{ + String username, + String credentials) throws SQLException{ String dbCredentials = getPassword(dbConnection, username); @@ -332,13 +336,13 @@ validated = (digest(credentials).equals(dbCredentials)); if (validated) { - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(sm.getString("dataSourceRealm.authenticateSuccess", - username)); + if (log.isTraceEnabled()) + log.trace(sm.getString("dataSourceRealm.authenticateSuccess", + username)); } else { - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(sm.getString("dataSourceRealm.authenticateFailure", - username)); + if (log.isTraceEnabled()) + log.trace(sm.getString("dataSourceRealm.authenticateFailure", + username)); return (null); } @@ -368,7 +372,7 @@ } dbConnection.close(); } catch (SQLException e) { - container.getLogger().error(sm.getString("dataSourceRealm.close"), e); // Just log it here + log.error(sm.getString("dataSourceRealm.close"), e); // Just log it here } } @@ -394,7 +398,7 @@ return dataSource.getConnection(); } catch (Exception e) { // Log the problem for posterity - container.getLogger().error(sm.getString("dataSourceRealm.exception"), e); + log.error(sm.getString("dataSourceRealm.exception"), e); } return null; } @@ -450,9 +454,8 @@ return (dbCredentials != null) ? dbCredentials.trim() : null; } catch(SQLException e) { - container.getLogger().error(sm - .getString("dataSourceRealm.getPassword.exception", - username)); + log.error(sm.getString("dataSourceRealm.getPassword.exception", + username)); } finally { try { if (rs != null) { @@ -462,10 +465,8 @@ stmt.close(); } } catch (SQLException e) { - container.getLogger().error(sm - .getString("dataSourceRealm.getPassword.exception", + log.error(sm.getString("dataSourceRealm.getPassword.exception", username)); - } } @@ -538,9 +539,8 @@ } return list; } catch(SQLException e) { - container.getLogger().error(sm - .getString("dataSourceRealm.getRoles.exception", - username)); + log.error(sm.getString("dataSourceRealm.getRoles.exception", + username)); } finally { try { @@ -551,9 +551,8 @@ stmt.close(); } } catch (SQLException e) { - container.getLogger().error(sm - .getString("dataSourceRealm.getRoles.exception", - username)); + log.error(sm.getString("dataSourceRealm.getRoles.exception", + username)); } } 1.7 +3 -3 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JAASCallbackHandler.java Index: JAASCallbackHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JAASCallbackHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JAASCallbackHandler.java 21 Jan 2005 08:41:17 -0000 1.6 +++ JAASCallbackHandler.java 18 Feb 2005 19:17:57 -0000 1.7 @@ -124,8 +124,8 @@ for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { - if (realm.getContainer().getLogger().isTraceEnabled()) - realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username)); + if (log.isTraceEnabled()) + log.trace(sm.getString("jaasCallback.username", username)); ((NameCallback) callbacks[i]).setName(username); } else if (callbacks[i] instanceof PasswordCallback) { final char[] passwordcontents; 1.13 +24 -13 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JAASMemoryLoginModule.java Index: JAASMemoryLoginModule.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JAASMemoryLoginModule.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JAASMemoryLoginModule.java 24 Sep 2004 07:25:07 -0000 1.12 +++ JAASMemoryLoginModule.java 18 Feb 2005 19:17:57 -0000 1.13 @@ -141,7 +141,9 @@ // --------------------------------------------------------- Public Methods public JAASMemoryLoginModule() { - log.debug("MEMORY LOGIN MODULE"); + if (log.isDebugEnabled()) { + log.debug("MEMORY LOGIN MODULE"); + } } /** @@ -168,7 +170,9 @@ committed = false; principal = null; } - log.debug("Abort"); + if (log.isDebugEnabled()) { + log.debug("Abort"); + } return (true); } @@ -186,7 +190,9 @@ * @exception LoginException if the commit fails */ public boolean commit() throws LoginException { - log.debug("commit " + principal); + if (log.isDebugEnabled()) { + log.debug("commit " + principal); + } // If authentication was not successful, just return false if (principal == null) @@ -215,8 +221,8 @@ // Are there any defined security constraints? SecurityConstraint constraints[] = context.findConstraints(); if ((constraints == null) || (constraints.length == 0)) { - if (context.getLogger().isDebugEnabled()) - context.getLogger().debug(" No applicable constraints defined"); + if (log.isDebugEnabled()) + log.debug(" No applicable constraints defined"); return (null); } @@ -228,8 +234,8 @@ uri = RequestUtil.URLDecode(uri); // Before checking constraints String method = request.getMethod(); for (int i = 0; i < constraints.length; i++) { - if (context.getLogger().isDebugEnabled()) - context.getLogger().debug(" Checking constraint '" + constraints[i] + + if (log.isDebugEnabled()) + log.debug(" Checking constraint '" + constraints[i] + "' against " + method + " " + uri + " --> " + constraints[i].included(uri, method)); if (constraints[i].included(uri, method)) { @@ -241,8 +247,8 @@ } // No applicable security constraint was found - if (context.getLogger().isDebugEnabled()) - context.getLogger().debug(" No applicable constraint located"); + if (log.isDebugEnabled()) + log.debug(" No applicable constraint located"); if(results == null) return null; SecurityConstraint [] array = new SecurityConstraint[results.size()]; @@ -265,7 +271,10 @@ */ public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { - log.debug("Init"); + + if (log.isDebugEnabled()) { + log.debug("Init"); + } // Save configuration values this.subject = subject; @@ -318,7 +327,9 @@ // Validate the username and password we have received principal = super.authenticate(username, password); - log.debug("login " + username + " " + principal); + if (log.isDebugEnabled()) { + log.debug("login " + username + " " + principal); + } // Report results based on success or failure if (principal != null) { @@ -376,7 +387,7 @@ digester.parse(file); } catch (Exception e) { log.warn("Error processing configuration file " + - file.getAbsolutePath(), e); + file.getAbsolutePath(), e); return; } finally { digester.reset(); 1.11 +23 -24 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JDBCRealm.java Index: JDBCRealm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JDBCRealm.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JDBCRealm.java 6 Jan 2005 11:33:22 -0000 1.10 +++ JDBCRealm.java 18 Feb 2005 19:17:57 -0000 1.11 @@ -29,6 +29,8 @@ import org.apache.catalina.LifecycleException; import org.apache.catalina.util.StringManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** @@ -50,6 +52,7 @@ public class JDBCRealm extends RealmBase { + private static Log log = LogFactory.getLog(JDBCRealm.class); // ----------------------------------------------------- Instance Variables @@ -354,7 +357,7 @@ } catch (SQLException e) { // Log the problem for posterity - container.getLogger().error(sm.getString("jdbcRealm.exception"), e); + log.error(sm.getString("jdbcRealm.exception"), e); // Close the connection so that it gets reopened next time if (dbConnection != null) @@ -408,13 +411,13 @@ } if (validated) { - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(sm.getString("jdbcRealm.authenticateSuccess", - username)); + if (log.isTraceEnabled()) + log.trace(sm.getString("jdbcRealm.authenticateSuccess", + username)); } else { - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(sm.getString("jdbcRealm.authenticateFailure", - username)); + if (log.isTraceEnabled()) + log.trace(sm.getString("jdbcRealm.authenticateFailure", + username)); return (null); } @@ -458,7 +461,7 @@ try { dbConnection.close(); } catch (SQLException e) { - container.getLogger().warn(sm.getString("jdbcRealm.close"), e); // Just log it here + log.warn(sm.getString("jdbcRealm.close"), e); // Just log it here } finally { this.dbConnection = null; } @@ -538,23 +541,21 @@ return dbCredentials; } catch(SQLException e){ - container.getLogger(). - error(sm.getString("jdbcRealm.getPassword.exception", - username), e); + log.error(sm.getString("jdbcRealm.getPassword.exception", + username), e); } finally { if (rs!=null) { try { rs.close(); } catch(SQLException e) { - container.getLogger().warn(sm.getString("jdbcRealm.abnormalCloseResultSet")); + log.warn(sm.getString("jdbcRealm.abnormalCloseResultSet")); } } try { dbConnection.commit(); } catch (SQLException e) { - container.getLogger(). - warn(sm.getString("jdbcRealm.getPassword.exception", - username)); + log.warn(sm.getString("jdbcRealm.getPassword.exception", + username)); } } @@ -600,23 +601,21 @@ return (roleList); } catch(SQLException e){ - container.getLogger(). - error(sm.getString("jdbcRealm.getRoles.exception", - username)); + log.error(sm.getString("jdbcRealm.getRoles.exception", + username)); } finally { if (rs!=null) { try { rs.close(); } catch(SQLException e) { - container.getLogger().warn(sm.getString("jdbcRealm.abnormalCloseResultSet")); + log.warn(sm.getString("jdbcRealm.abnormalCloseResultSet")); } } try { dbConnection.commit(); } catch (SQLException e) { - container.getLogger(). - warn(sm.getString("jdbcRealm.getRoles.exception", - username)); + log.warn(sm.getString("jdbcRealm.getRoles.exception", + username)); } } @@ -719,7 +718,7 @@ try { open(); } catch (SQLException e) { - container.getLogger().error(sm.getString("jdbcRealm.open"), e); + log.error(sm.getString("jdbcRealm.open"), e); } // Perform normal superclass initialization 1.18 +43 -38 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JNDIRealm.java Index: JNDIRealm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/JNDIRealm.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- JNDIRealm.java 1 Jan 2005 11:08:15 -0000 1.17 +++ JNDIRealm.java 18 Feb 2005 19:17:57 -0000 1.18 @@ -44,6 +44,8 @@ import javax.naming.directory.SearchResult; import org.apache.catalina.LifecycleException; import org.apache.catalina.util.Base64; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** @@ -156,6 +158,9 @@ public class JNDIRealm extends RealmBase { + private static Log log = LogFactory.getLog(JNDIRealm.class); + + // ----------------------------------------------------- Instance Variables /** @@ -819,7 +824,7 @@ throw(e); // log the exception so we know it's there. - container.getLogger().error(sm.getString("jndiRealm.exception"), e); + log.error(sm.getString("jndiRealm.exception"), e); // close the connection so we know it will be reopened. if (context != null) @@ -843,7 +848,7 @@ } catch (NamingException e) { // Log the problem for posterity - container.getLogger().error(sm.getString("jndiRealm.exception"), e); + log.error(sm.getString("jndiRealm.exception"), e); // Close the connection so that it gets reopened next time if (context != null) @@ -902,7 +907,7 @@ } } catch (InvalidNameException ine) { // Log the problem for posterity - container.getLogger().warn(sm.getString("jndiRealm.exception"), ine); + log.warn(sm.getString("jndiRealm.exception"), ine); // ignore; this is probably due to a name not fitting // the search path format exactly, as in a fully- // qualified name being munged into a search path @@ -1074,7 +1079,7 @@ // Check no further entries were found if (results.hasMore()) { - container.getLogger().info("username " + username + " has multiple entries"); + log.info("username " + username + " has multiple entries"); return (null); } @@ -1090,8 +1095,8 @@ name = name.addAll(entryName); String dn = name.toString(); - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(" entry found for " + username + " with dn " + dn); + if (log.isTraceEnabled()) + log.trace(" entry found for " + username + " with dn " + dn); // Get the entry's attributes Attributes attrs = result.getAttributes(); @@ -1140,13 +1145,13 @@ validated = compareCredentials(context, user, credentials); } - if (container.getLogger().isTraceEnabled()) { + if (log.isTraceEnabled()) { if (validated) { - container.getLogger().trace(sm.getString("jndiRealm.authenticateSuccess", - user.username)); + log.trace(sm.getString("jndiRealm.authenticateSuccess", + user.username)); } else { - container.getLogger().trace(sm.getString("jndiRealm.authenticateFailure", - user.username)); + log.trace(sm.getString("jndiRealm.authenticateFailure", + user.username)); } } return (validated); @@ -1177,8 +1182,8 @@ return (false); // Validate the credentials specified by the user - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(" validating credentials"); + if (log.isTraceEnabled()) + log.trace(" validating credentials"); boolean validated = false; if (hasMessageDigest()) { @@ -1230,8 +1235,8 @@ return (false); // Validate the credentials specified by the user - if (container.getLogger().isTraceEnabled()) { - container.getLogger().trace(" validating credentials by binding as the user"); + if (log.isTraceEnabled()) { + log.trace(" validating credentials by binding as the user"); } // Set up security environment to bind as the user @@ -1241,15 +1246,15 @@ // Elicit an LDAP bind operation boolean validated = false; try { - if (container.getLogger().isTraceEnabled()) { - container.getLogger().trace(" binding as " + dn); + if (log.isTraceEnabled()) { + log.trace(" binding as " + dn); } attr = context.getAttributes("", null); validated = true; } catch (AuthenticationException e) { - if (container.getLogger().isTraceEnabled()) { - container.getLogger().trace(" bind attempt failed"); + if (log.isTraceEnabled()) { + log.trace(" bind attempt failed"); } } @@ -1296,8 +1301,8 @@ if (dn == null || username == null) return (null); - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(" getRoles(" + dn + ")"); + if (log.isTraceEnabled()) + log.trace(" getRoles(" + dn + ")"); // Start with roles retrieved from the user entry ArrayList list = user.roles; @@ -1332,13 +1337,13 @@ } - if (container.getLogger().isTraceEnabled()) { + if (log.isTraceEnabled()) { if (list != null) { - container.getLogger().trace(" Returning " + list.size() + " roles"); + log.trace(" Returning " + list.size() + " roles"); for (int i=0; i<list.size(); i++) - container.getLogger().trace( " Found role " + list.get(i)); + log.trace( " Found role " + list.get(i)); } else { - container.getLogger().trace(" getRoles about to return null "); + log.trace(" getRoles about to return null "); } } @@ -1357,8 +1362,8 @@ private String getAttributeValue(String attrId, Attributes attrs) throws NamingException { - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(" retrieving attribute " + attrId); + if (log.isTraceEnabled()) + log.trace(" retrieving attribute " + attrId); if (attrId == null || attrs == null) return null; @@ -1394,8 +1399,8 @@ ArrayList values) throws NamingException{ - if (container.getLogger().isTraceEnabled()) - container.getLogger().trace(" retrieving values for attribute " + attrId); + if (log.isTraceEnabled()) + log.trace(" retrieving values for attribute " + attrId); if (attrId == null || attrs == null) return values; if (values == null) @@ -1425,11 +1430,11 @@ // Close our opened connection try { - if (container.getLogger().isDebugEnabled()) - container.getLogger().debug("Closing directory context"); + if (log.isDebugEnabled()) + log.debug("Closing directory context"); context.close(); } catch (NamingException e) { - container.getLogger().error(sm.getString("jndiRealm.close"), e); + log.error(sm.getString("jndiRealm.close"), e); } this.context = null; @@ -1489,7 +1494,7 @@ connectionAttempt = 1; // log the first exception. - container.getLogger().warn(sm.getString("jndiRealm.exception"), e); + log.warn(sm.getString("jndiRealm.exception"), e); // Try connecting to the alternate url. context = new InitialDirContext(getDirectoryContextEnvironment()); @@ -1516,10 +1521,10 @@ Hashtable env = new Hashtable(); // Configure our directory context environment. - if (container.getLogger().isDebugEnabled() && connectionAttempt == 0) - container.getLogger().debug("Connecting to URL " + connectionURL); - else if (container.getLogger().isDebugEnabled() && connectionAttempt > 0) - container.getLogger().debug("Connecting to URL " + alternateURL); + if (log.isDebugEnabled() && connectionAttempt == 0) + log.debug("Connecting to URL " + connectionURL); + else if (log.isDebugEnabled() && connectionAttempt > 0) + log.debug("Connecting to URL " + alternateURL); env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory); if (connectionName != null) env.put(Context.SECURITY_PRINCIPAL, connectionName); 1.46 +7 -9 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java Index: RealmBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- RealmBase.java 7 Jan 2005 10:06:38 -0000 1.45 +++ RealmBase.java 18 Feb 2005 19:17:57 -0000 1.46 @@ -283,17 +283,15 @@ validated = serverCredentials.equals(credentials); } if(! validated ) { - if (container.getLogger().isTraceEnabled()) { - container.getLogger(). - trace(sm.getString("realmBase.authenticateFailure", - username)); + if (log.isTraceEnabled()) { + log.trace(sm.getString("realmBase.authenticateFailure", + username)); } return null; } - if (container.getLogger().isTraceEnabled()) { - container.getLogger(). - trace(sm.getString("realmBase.authenticateSuccess", - username)); + if (log.isTraceEnabled()) { + log.trace(sm.getString("realmBase.authenticateSuccess", + username)); } return getPrincipal(username); 1.10 +6 -2 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java Index: UserDatabaseRealm.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- UserDatabaseRealm.java 29 Aug 2004 16:46:12 -0000 1.9 +++ UserDatabaseRealm.java 18 Feb 2005 19:17:57 -0000 1.10 @@ -31,6 +31,8 @@ import org.apache.catalina.UserDatabase; import org.apache.catalina.core.StandardServer; import org.apache.catalina.util.StringManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** @@ -48,6 +50,7 @@ public class UserDatabaseRealm extends RealmBase { + private static Log log = LogFactory.getLog(UserDatabaseRealm.class); // ----------------------------------------------------- Instance Variables @@ -221,7 +224,8 @@ Context context = server.getGlobalNamingContext(); database = (UserDatabase) context.lookup(resourceName); } catch (Throwable e) { - container.getLogger().error(sm.getString("userDatabaseRealm.lookup", resourceName), e); + log.error(sm.getString("userDatabaseRealm.lookup", resourceName), + e); database = null; } if (database == null) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]