Declare KeyboardInteractiveAuthenticator#generateChallenge as throws Exception
authorLyor Goldstein <lgoldstein@apache.org>
Mon, 11 Feb 2019 06:55:00 +0000 (08:55 +0200)
committerLyor Goldstein <lgoldstein@apache.org>
Tue, 12 Feb 2019 08:17:19 +0000 (10:17 +0200)
sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/DefaultKeyboardInteractiveAuthenticator.java
sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/KeyboardInteractiveAuthenticator.java
sshd-core/src/main/java/org/apache/sshd/server/auth/keyboard/UserAuthKeyboardInteractive.java
sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java

index 32bfeac..70156e9 100644 (file)
@@ -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);
index cdf2928..5b78ead 100644 (file)
@@ -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;
 }
index e7b9b63..e032473 100644 (file)
@@ -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;
         }
index 466afd7..d1992d5 100644 (file)
@@ -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));
 
index fefd7b1..224bfa2 100644 (file)
@@ -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;
             }