Fix possible NPE
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 25 Feb 2009 15:46:46 +0000 (15:46 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 25 Feb 2009 15:46:46 +0000 (15:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@747834 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/realm/DataSourceRealm.java
java/org/apache/catalina/realm/JDBCRealm.java
java/org/apache/catalina/realm/MemoryRealm.java

index 9288ff7..c6ec6e9 100644 (file)
@@ -270,8 +270,9 @@ public class DataSourceRealm
      */
     public Principal authenticate(String username, String credentials) {
        
-       // No user - can't possibly authenticate, don't bother the database then
-       if (username == null) {
+       // No user or no credentials
+        // Can't possibly authenticate, don't bother the database then
+       if (username == null || credentials == null) {
                return null;
        }
         
index 7cd17d0..05fd1fa 100644 (file)
@@ -393,9 +393,10 @@ public class JDBCRealm
                                                String username,
                                                String credentials) {
 
-        // No user - can't possibly authenticate
-        if (username == null) {
-            return (null);
+        // No user or no credentials
+        // Can't possibly authenticate, don't bother the database then
+        if (username == null || credentials == null) {
+            return null;
         }
 
         // Look up the user's credentials
index ca1f70c..343a8d4 100644 (file)
@@ -147,7 +147,7 @@ public class MemoryRealm  extends RealmBase {
         GenericPrincipal principal = principals.get(username);
 
         boolean validated = false;
-        if (principal != null) {
+        if (principal != null && credentials != null) {
             if (hasMessageDigest()) {
                 // Hex hashes should be compared case-insensitive
                 validated = (digest(credentials)