You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2019/02/12 08:17:26 UTC

[mina-sshd] 02/02: Declare KeyboardInteractiveAuthenticator#generateChallenge as throws Exception

This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit c56ac6b324e6a10abb6aaec7715ff278a858286e
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Mon Feb 11 08:55:00 2019 +0200

    Declare KeyboardInteractiveAuthenticator#generateChallenge as throws Exception
---
 .../DefaultKeyboardInteractiveAuthenticator.java        | 14 ++++++++------
 .../auth/keyboard/KeyboardInteractiveAuthenticator.java | 17 +++++++++++++----
 .../auth/keyboard/UserAuthKeyboardInteractive.java      |  4 ++--
 .../org/apache/sshd/common/auth/AuthenticationTest.java | 15 +++++++++++----
 .../test/java/org/apache/sshd/server/ServerTest.java    |  6 ++++--
 5 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
index 32bfeac..70156e9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
@@ -56,11 +56,13 @@ public class DefaultKeyboardInteractiveAuthenticator
     }
 
     @Override
-    public InteractiveChallenge generateChallenge(ServerSession session, String username, String lang, String subMethods) {
+    public InteractiveChallenge generateChallenge(
+            ServerSession session, String username, String lang, String subMethods)
+                throws Exception {
         PasswordAuthenticator auth = session.getPasswordAuthenticator();
         if (auth == null) {
             if (log.isDebugEnabled()) {
-                log.debug("generateChallenge({}) no password authenticator", session);
+                log.debug("generateChallenge({})[{}] no password authenticator", session, username);
             }
             return null;
         }
@@ -78,7 +80,7 @@ public class DefaultKeyboardInteractiveAuthenticator
         PasswordAuthenticator auth = session.getPasswordAuthenticator();
         if (auth == null) {
             if (log.isDebugEnabled()) {
-                log.debug("authenticate({}) no password authenticator", session);
+                log.debug("authenticate({})[{}] no password authenticator", session, username);
             }
             return false;
         }
@@ -91,10 +93,10 @@ public class DefaultKeyboardInteractiveAuthenticator
         try {
             return auth.authenticate(username, responses.get(0), session);
         } catch (Error e) {
-            log.warn("authenticate({}) failed ({}) to consult password authenticator: {}",
-                    session, e.getClass().getSimpleName(), e.getMessage());
+            log.warn("authenticate({})[{}] failed ({}) to consult password authenticator: {}",
+                session, username, e.getClass().getSimpleName(), e.getMessage());
             if (log.isDebugEnabled()) {
-                log.debug("authenticate(" + session + ") authenticator failure details", e);
+                log.debug("authenticate(" + session + ")[" + username + "] authenticator failure details", e);
             }
 
             throw new RuntimeSshException(e);
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/KeyboardInteractiveAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/KeyboardInteractiveAuthenticator.java
index cdf2928..5b78ead 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/KeyboardInteractiveAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/KeyboardInteractiveAuthenticator.java
@@ -35,12 +35,16 @@ public interface KeyboardInteractiveAuthenticator {
      */
     KeyboardInteractiveAuthenticator NONE = new KeyboardInteractiveAuthenticator() {
         @Override
-        public InteractiveChallenge generateChallenge(ServerSession session, String username, String lang, String subMethods) {
+        public InteractiveChallenge generateChallenge(
+                ServerSession session, String username, String lang, String subMethods)
+                    throws Exception {
             return null;
         }
 
         @Override
-        public boolean authenticate(ServerSession session, String username, List<String> responses) throws Exception {
+        public boolean authenticate(
+                ServerSession session, String username, List<String> responses)
+                    throws Exception {
             return false;
         }
 
@@ -59,8 +63,11 @@ public interface KeyboardInteractiveAuthenticator {
      * @param subMethods Sub-methods hints sent by the client
      * @return The {@link InteractiveChallenge} - if {@code null} then authentication
      * attempt via &quot;keyboard-interactive&quot; method is rejected
+     * @throws Exception If unable to generate the challenge
      */
-    InteractiveChallenge generateChallenge(ServerSession session, String username, String lang, String subMethods);
+    InteractiveChallenge generateChallenge(
+        ServerSession session, String username, String lang, String subMethods)
+            throws Exception;
 
     /**
      * Called to authenticate the response to the challenge(s) sent previously
@@ -74,5 +81,7 @@ public interface KeyboardInteractiveAuthenticator {
      * @return {@code true} if responses have been validated
      * @throws Exception if bad responses and server should terminate the connection
      */
-    boolean authenticate(ServerSession session, String username, List<String> responses) throws Exception;
+    boolean authenticate(
+        ServerSession session, String username, List<String> responses)
+            throws Exception;
 }
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
index e7b9b63..e032473 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
@@ -63,7 +63,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
         if (auth == null) {
             if (debugEnabled) {
                 log.debug("doAuth({}@{})[methods={}, lang={}] - no interactive authenticator to generate challenge",
-                          username, session, subMethods, lang);
+                      username, session, subMethods, lang);
             }
             return false;
         }
@@ -83,7 +83,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
         if (challenge == null) {
             if (debugEnabled) {
                 log.debug("doAuth({}@{})[methods={}, lang={}] - no interactive challenge generated",
-                          username, session, subMethods, lang);
+                      username, session, subMethods, lang);
             }
             return false;
         }
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 466afd7..d1992d5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -343,7 +343,9 @@ public class AuthenticationTest extends BaseTestSupport {
             sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE);
             sshd.setKeyboardInteractiveAuthenticator(new DefaultKeyboardInteractiveAuthenticator() {
                 @Override
-                public InteractiveChallenge generateChallenge(ServerSession session, String username, String lang, String subMethods) {
+                public InteractiveChallenge generateChallenge(
+                        ServerSession session, String username, String lang, String subMethods)
+                            throws Exception {
                     assertEquals("Mismatched user language",
                             PropertyResolverUtils.getStringProperty(
                                 client,
@@ -373,7 +375,9 @@ public class AuthenticationTest extends BaseTestSupport {
                 }
 
                 @Override
-                public boolean authenticate(ServerSession session, String username, List<String> responses) throws Exception {
+                public boolean authenticate(
+                        ServerSession session, String username, List<String> responses)
+                            throws Exception {
                     return super.authenticate(session, username, responses);
                 }
 
@@ -434,13 +438,16 @@ public class AuthenticationTest extends BaseTestSupport {
         sshd.setKeyboardInteractiveAuthenticator(new KeyboardInteractiveAuthenticator() {
             @Override
             public InteractiveChallenge generateChallenge(
-                    ServerSession session, String username, String lang, String subMethods) {
+                    ServerSession session, String username, String lang, String subMethods)
+                        throws Exception {
                 assertEquals("Unexpected challenge call", 1, genCount.incrementAndGet());
                 return challenge;
             }
 
             @Override
-            public boolean authenticate(ServerSession session, String username, List<String> responses) throws Exception {
+            public boolean authenticate(
+                    ServerSession session, String username, List<String> responses)
+                        throws Exception {
                 assertEquals("Unexpected authenticate call", 1, authCount.incrementAndGet());
                 assertEquals("Mismatched number of responses", GenericUtils.size(rspMap), GenericUtils.size(responses));
 
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index fefd7b1..224bfa2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -771,7 +771,8 @@ public class ServerTest extends BaseTestSupport {
         sshd.setKeyboardInteractiveAuthenticator(new KeyboardInteractiveAuthenticator() {
             @Override
             public InteractiveChallenge generateChallenge(
-                    ServerSession session, String username, String lang, String subMethods) {
+                    ServerSession session, String username, String lang, String subMethods)
+                        throws Exception {
                 challengeCount.incrementAndGet();
                 outputDebugMessage("generateChallenge(%s@%s) count=%s", username, session, challengeCount);
                 return null;
@@ -819,7 +820,8 @@ public class ServerTest extends BaseTestSupport {
         sshd.setKeyboardInteractiveAuthenticator(new KeyboardInteractiveAuthenticator() {
             @Override
             public InteractiveChallenge generateChallenge(
-                    ServerSession session, String username, String lang, String subMethods) {
+                    ServerSession session, String username, String lang, String subMethods)
+                        throws Exception {
                 return challenge;
             }