X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fssh%2Fthreads%2FSocketThread.java;h=d159f59f1a2cedcefeca01bf24b93854c4fa269b;hb=bedd5051e2605b9e03fbd89acfbeced9ab252287;hp=15d99a44ee4db4a7b31bd0ee2fd6abd25476079c;hpb=a5e62959e0939658650a8e04c032ef4cafaf3600;p=controller.git diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java index 15d99a44ee..d159f59f1a 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.netconf.ssh.threads; @@ -13,7 +20,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import javax.annotation.concurrent.ThreadSafe; -import org.opendaylight.controller.netconf.ssh.authentication.RSAKey; +import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,27 +37,38 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser private long sessionId; private String currentUser; private final String remoteAddressWithPort; + private final AuthProvider authProvider; - public static void start(Socket socket, InetSocketAddress clientAddress, long sessionId) throws IOException{ - Thread netconf_ssh_socket_thread = new Thread(new SocketThread(socket,clientAddress,sessionId)); + public static void start(Socket socket, + InetSocketAddress clientAddress, + long sessionId, + AuthProvider authProvider) throws IOException{ + Thread netconf_ssh_socket_thread = new Thread(new SocketThread(socket,clientAddress,sessionId,authProvider)); netconf_ssh_socket_thread.setDaemon(true); netconf_ssh_socket_thread.start(); } - private SocketThread(Socket socket, InetSocketAddress clientAddress, long sessionId) throws IOException { + private SocketThread(Socket socket, + InetSocketAddress clientAddress, + long sessionId, + AuthProvider authProvider) throws IOException { this.socket = socket; this.clientAddress = clientAddress; this.sessionId = sessionId; this.remoteAddressWithPort = socket.getRemoteSocketAddress().toString().replaceFirst("/",""); + this.authProvider = authProvider; } @Override public void run() { conn = new ServerConnection(socket); - RSAKey keyStore = new RSAKey(); - conn.setRsaHostKey(keyStore.getPrivateKey()); + try { + conn.setPEMHostKey(authProvider.getPEMAsCharArray(),"netconf"); + } catch (Exception e) { + logger.debug("Server authentication setup failed."); + } conn.setAuthenticationCallback(this); conn.setServerConnectionCallback(this); try { @@ -90,13 +108,14 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser netconf_ssh_output.start(); } catch (Throwable t){ - logger.error(t.getMessage(),t); + logger.error("SSH bridge couldn't create echo socket",t.getMessage(),t); try { if (netconf_ssh_input!=null){ netconf_ssh_input.join(); } } catch (InterruptedException e) { + Thread.currentThread().interrupt(); logger.error("netconf_ssh_input join error ",e); } @@ -105,6 +124,7 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser netconf_ssh_output.join(); } } catch (InterruptedException e) { + Thread.currentThread().interrupt(); logger.error("netconf_ssh_output join error ",e); } @@ -166,13 +186,16 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser public AuthenticationResult authenticateWithPassword(ServerConnection sc, String username, String password) { - if (USER.equals(username) && PASSWORD.equals(password)){ - currentUser = username; - logger.trace("user {}@{} authenticated",currentUser,remoteAddressWithPort); - return AuthenticationResult.SUCCESS; - } - + try { + if (authProvider.authenticated(username,password)){ + currentUser = username; + logger.trace("user {}@{} authenticated",currentUser,remoteAddressWithPort); + return AuthenticationResult.SUCCESS; + } + } catch (Exception e){ + logger.info("Authentication failed due to :" + e.getLocalizedMessage()); + } return AuthenticationResult.FAILURE; }