2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication;
11 import java.io.IOException;
13 import org.apache.sshd.ClientSession;
14 import org.apache.sshd.client.future.AuthFuture;
16 import ch.ethz.ssh2.Connection;
19 * Class Providing username/password authentication option to
20 * {@link org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshHandler}
22 public class LoginPassword extends AuthenticationHandler {
23 private final String username;
24 private final String password;
26 public LoginPassword(String username, String password) {
27 this.username = username;
28 this.password = password;
32 public void authenticate(Connection connection) throws IOException {
33 final boolean isAuthenticated = connection.authenticateWithPassword(username, password);
35 if (!isAuthenticated) {
36 throw new IOException("Authentication failed.");
41 public String getUsername() {
46 public AuthFuture authenticate(final ClientSession session) throws IOException {
47 session.addPasswordIdentity(password);
48 return session.auth();