Search in sources :

Example 1 with InteractiveCallback

use of com.trilead.ssh2.InteractiveCallback in project intellij-community by JetBrains.

the class SshPasswordAuthentication method authenticate.

public void authenticate(final Connection connection) throws AuthenticationException, SolveableAuthenticationException {
    final String password = myPasswordProvider.getPasswordForCvsRoot(myCvsRootAsString);
    if (password == null) {
        throw new SolveableAuthenticationException("Authentication rejected.");
    }
    try {
        final String[] methodsArr = connection.getRemainingAuthMethods(myLogin);
        if ((methodsArr == null) || (methodsArr.length == 0))
            return;
        final List<String> methods = Arrays.asList(methodsArr);
        if (methods.contains(PASSWORD_METHOD)) {
            if (connection.authenticateWithPassword(myLogin, password))
                return;
        }
        if (methods.contains(KEYBOARD_METHOD)) {
            final boolean wasAuthenticated = connection.authenticateWithKeyboardInteractive(myLogin, new InteractiveCallback() {

                public String[] replyToChallenge(String s, String instruction, int numPrompts, String[] strings, boolean[] booleans) throws Exception {
                    final String[] result = new String[numPrompts];
                    if (numPrompts > 0) {
                        Arrays.fill(result, password);
                    }
                    return result;
                }
            });
            if (wasAuthenticated)
                return;
        }
        throw new SolveableAuthenticationException("Authentication rejected.");
    } catch (IOException e) {
        throw new SolveableAuthenticationException(e.getMessage(), e);
    }
}
Also used : InteractiveCallback(com.trilead.ssh2.InteractiveCallback) IOException(java.io.IOException) IOException(java.io.IOException) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException)

Aggregations

InteractiveCallback (com.trilead.ssh2.InteractiveCallback)1 IOException (java.io.IOException)1 AuthenticationException (org.netbeans.lib.cvsclient.connection.AuthenticationException)1