From f36b75d14923ba9cba3b0af9677d48b6682032e6 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Tue, 3 Dec 2013 09:24:44 +0100 Subject: [PATCH] - added hello message with client ip and user@host trace message - SSH bridge adds customHeader at the beginning of bridged communication Change-Id: I4bd1733901f3d37a5d62022bad0c39c33db8c5ed Signed-off-by: Martin Bobak --- .../controller/netconf/ssh/threads/IOThread.java | 14 ++++++++++++++ .../netconf/ssh/threads/SocketThread.java | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java index 33ed88edf8..b9c9c174dc 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java @@ -26,6 +26,7 @@ public class IOThread extends Thread { private String id; private ServerSession servSession; private ServerConnection servconnection; + private String customHeader; public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn){ @@ -36,11 +37,24 @@ public class IOThread extends Thread { super.setName(id); logger.trace("IOThread {} created", super.getName()); } + public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn,String header){ + this.inputStream = is; + this.outputStream = os; + this.servSession = ss; + this.servconnection = conn; + this.customHeader = header; + super.setName(id); + logger.trace("IOThread {} created", super.getName()); + } @Override public void run() { logger.trace("thread {} started", super.getName()); try { + if (this.customHeader!=null && !this.customHeader.equals("")){ + this.outputStream.write(this.customHeader.getBytes()); + logger.trace("adding {} header", this.customHeader); + } IOUtils.copy(this.inputStream, this.outputStream); } catch (Exception e) { logger.error("inputstream -> outputstream copy error ",e); 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 95fdd48bfe..15d99a44ee 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 @@ -28,6 +28,8 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser private static final Logger logger = LoggerFactory.getLogger(SocketThread.class); private ServerConnection conn = null; private long sessionId; + private String currentUser; + private final String remoteAddressWithPort; public static void start(Socket socket, InetSocketAddress clientAddress, long sessionId) throws IOException{ @@ -40,6 +42,7 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser this.socket = socket; this.clientAddress = clientAddress; this.sessionId = sessionId; + this.remoteAddressWithPort = socket.getRemoteSocketAddress().toString().replaceFirst("/",""); } @@ -81,7 +84,8 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser netconf_ssh_input.start(); logger.trace("starting netconf_ssh_output thread"); - netconf_ssh_output = new IOThread(ss.getStdout(),echoSocket.getOutputStream(),"output_thread_"+sessionId,ss,conn); + final String customHeader = "["+currentUser+";"+remoteAddressWithPort+";ssh;;;;;;]\n"; + netconf_ssh_output = new IOThread(ss.getStdout(),echoSocket.getOutputStream(),"output_thread_"+sessionId,ss,conn,customHeader); netconf_ssh_output.setDaemon(false); netconf_ssh_output.start(); @@ -146,7 +150,8 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser public String initAuthentication(ServerConnection sc) { - return ""; + logger.trace("Established connection with host {}",remoteAddressWithPort); + return "Established connection with host "+remoteAddressWithPort+"\r\n"; } public String[] getRemainingAuthMethods(ServerConnection sc) @@ -161,8 +166,12 @@ public class SocketThread implements Runnable, ServerAuthenticationCallback, Ser public AuthenticationResult authenticateWithPassword(ServerConnection sc, String username, String password) { - if (USER.equals(username) && PASSWORD.equals(password)) + if (USER.equals(username) && PASSWORD.equals(password)){ + currentUser = username; + logger.trace("user {}@{} authenticated",currentUser,remoteAddressWithPort); return AuthenticationResult.SUCCESS; + } + return AuthenticationResult.FAILURE; } -- 2.36.6