You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2016/07/06 10:23:40 UTC

cassandra git commit: Add username to AuthenticationException messages

Repository: cassandra
Updated Branches:
  refs/heads/trunk b4192e63b -> 5fae533f3


Add username to AuthenticationException messages

Patch by Geoffrey Yu; reviewed by Sam Tunnicliffe for CASSANDRA-12076


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5fae533f
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5fae533f
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5fae533f

Branch: refs/heads/trunk
Commit: 5fae533f3ead3d91317752f83826fbada98b2ec9
Parents: b4192e6
Author: Geoffrey Yu <ge...@apple.com>
Authored: Wed Jun 22 18:06:58 2016 -0700
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Wed Jul 6 10:37:30 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                                  | 1 +
 src/java/org/apache/cassandra/auth/CassandraLoginModule.java | 2 +-
 .../org/apache/cassandra/auth/PasswordAuthenticator.java     | 8 ++++----
 3 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5fae533f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 80e1b05..4dd29ab 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.10
+ * Add supplied username to authentication error messages (CASSANDRA-12076)
  * Remove pre-startup check for open JMX port (CASSANDRA-12074)
 
 3.9

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5fae533f/src/java/org/apache/cassandra/auth/CassandraLoginModule.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/CassandraLoginModule.java b/src/java/org/apache/cassandra/auth/CassandraLoginModule.java
index 2ccf962..d208300 100644
--- a/src/java/org/apache/cassandra/auth/CassandraLoginModule.java
+++ b/src/java/org/apache/cassandra/auth/CassandraLoginModule.java
@@ -145,7 +145,7 @@ public class CassandraLoginModule implements LoginModule
         AuthenticatedUser user = authenticator.legacyAuthenticate(credentials);
         // Only actual users should be allowed to authenticate for JMX
         if (user.isAnonymous() || user.isSystem())
-            throw new AuthenticationException("Invalid user");
+            throw new AuthenticationException(String.format("Invalid user %s", user.getName()));
 
         // The LOGIN privilege is required to authenticate - c.f. ClientState::login
         if (!DatabaseDescriptor.getRoleManager().canLogin(user.getPrimaryRole()))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5fae533f/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java b/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
index 3714523..74eb10d 100644
--- a/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
+++ b/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
@@ -87,7 +87,7 @@ public class PasswordAuthenticator implements IAuthenticator
         {
             String hash = cache.get(username);
             if (!BCrypt.checkpw(password, hash))
-                throw new AuthenticationException("Username and/or password are incorrect");
+                throw new AuthenticationException(String.format("Provided username %s and/or password are incorrect", username));
 
             return new AuthenticatedUser(username);
         }
@@ -95,13 +95,13 @@ public class PasswordAuthenticator implements IAuthenticator
         {
             // the credentials were somehow invalid - either a non-existent role, or one without a defined password
             if (e.getCause() instanceof NoSuchCredentialsException)
-                throw new AuthenticationException("Username and/or password are incorrect");
+                throw new AuthenticationException(String.format("Provided username %s and/or password are incorrect", username));
 
             // an unanticipated exception occured whilst querying the credentials table
             if (e.getCause() instanceof RequestExecutionException)
             {
                 logger.trace("Error performing internal authentication", e);
-                throw new AuthenticationException(e.getMessage());
+                throw new AuthenticationException(String.format("Error during authentication of user %s : %s", username, e.getMessage()));
             }
 
             throw new RuntimeException(e);
@@ -180,7 +180,7 @@ public class PasswordAuthenticator implements IAuthenticator
 
         String password = credentials.get(PASSWORD_KEY);
         if (password == null)
-            throw new AuthenticationException(String.format("Required key '%s' is missing", PASSWORD_KEY));
+            throw new AuthenticationException(String.format("Required key '%s' is missing for provided username %s", PASSWORD_KEY, username));
 
         return authenticate(username, password);
     }