*/
public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
- private static final Logger logger = LoggerFactory.getLogger(RemoteNetconfCommand.class);
+ private static final Logger LOG = LoggerFactory.getLogger(RemoteNetconfCommand.class);
private final EventLoopGroup clientEventGroup;
private final LocalAddress localAddress;
@Override
public void start(final Environment env) throws IOException {
- logger.trace("Establishing internal connection to netconf server for client: {}", getClientAddress());
+ LOG.trace("Establishing internal connection to netconf server for client: {}", getClientAddress());
final Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.group(clientEventGroup).channel(LocalChannel.class);
if(future.isSuccess()) {
clientChannel = clientChannelFuture.channel();
} else {
- logger.warn("Unable to establish internal connection to netconf server for client: {}", getClientAddress());
+ LOG.warn("Unable to establish internal connection to netconf server for client: {}", getClientAddress());
Preconditions.checkNotNull(callback, "Exit callback must be set");
callback.onExit(1, "Unable to establish internal connection to netconf server for client: "+ getClientAddress());
}
@Override
public void destroy() {
- logger.trace("Releasing internal connection to netconf server for client: {} on channel: {}",
+ LOG.trace("Releasing internal connection to netconf server for client: {} on channel: {}",
getClientAddress(), clientChannel);
clientChannelFuture.cancel(true);
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (future.isSuccess() == false) {
- logger.warn("Unable to release internal connection to netconf server on channel: {}", clientChannel);
+ LOG.warn("Unable to release internal connection to netconf server on channel: {}", clientChannel);
}
}
});
*/
final class SshProxyClientHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(SshProxyClientHandler.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SshProxyClientHandler.class);
private final IoInputStream in;
private final IoOutputStream out;
}, new AsyncSshHandlerReader.ReadMsgHandler() {
@Override
public void onMessageRead(final ByteBuf msg) {
- if(logger.isTraceEnabled()) {
- logger.trace("Forwarding message for client: {} on channel: {}, message: {}",
+ if(LOG.isTraceEnabled()) {
+ LOG.trace("Forwarding message for client: {} on channel: {}, message: {}",
netconfHelloMessageAdditionalHeader.getAddress(), ctx.channel(), AsyncSshHandlerWriter.byteBufToString(msg));
}
// Just forward to delegate
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
- asyncSshHandlerWriter.write(ctx, msg, ctx.newPromise());
+ asyncSshHandlerWriter.write(ctx, msg, ctx.newPromise());
}
@Override
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
- logger.debug("Internal connection to netconf server was dropped for client: {} on channel: ",
+ LOG.debug("Internal connection to netconf server was dropped for client: {} on channel: ",
netconfHelloMessageAdditionalHeader.getAddress(), ctx.channel());
callback.onExit(1, "Internal connection to netconf server was dropped for client: " +
netconfHelloMessageAdditionalHeader.getAddress() + " on channel: " + ctx.channel());
private static Map<String, String> getProperties(final SshProxyServerConfiguration sshProxyServerConfiguration) {
return new HashMap<String, String>()
- {{
- put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
- // TODO make auth timeout configurable on its own
- put(ServerFactoryManager.AUTH_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
- }};
+ {
+ {
+ put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+ // TODO make auth timeout configurable on its own
+ put(ServerFactoryManager.AUTH_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+ }
+ };
}
@Override
import org.slf4j.LoggerFactory;
final class AuthProviderTracker implements ServiceTrackerCustomizer<AuthProvider, AuthProvider>, PasswordAuthenticator {
- private static final Logger logger = LoggerFactory.getLogger(AuthProviderTracker.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AuthProviderTracker.class);
private final BundleContext bundleContext;
@Override
public AuthProvider addingService(final ServiceReference<AuthProvider> reference) {
- logger.trace("Service {} added", reference);
+ LOG.trace("Service {} added", reference);
final AuthProvider authService = bundleContext.getService(reference);
final Integer newServicePreference = getPreference(reference);
if(isBetter(newServicePreference)) {
final AuthProvider authService = bundleContext.getService(reference);
final Integer newServicePreference = getPreference(reference);
if(isBetter(newServicePreference)) {
- logger.trace("Replacing modified service {} in netconf SSH.", reference);
+ LOG.trace("Replacing modified service {} in netconf SSH.", reference);
this.authProvider = authService;
}
}
@Override
public void removedService(final ServiceReference<AuthProvider> reference, final AuthProvider service) {
- logger.trace("Removing service {} from netconf SSH. " +
- "SSH won't authenticate users until AuthProvider service will be started.", reference);
+ LOG.trace("Removing service {} from netconf SSH. {}", reference,
+ " SSH won't authenticate users until AuthProvider service will be started.");
maxPreference = null;
this.authProvider = null;
}
import org.slf4j.LoggerFactory;
public class NetconfSSHActivator implements BundleActivator {
- private static final Logger logger = LoggerFactory.getLogger(NetconfSSHActivator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfSSHActivator.class);
private static final java.lang.String ALGORITHM = "RSA";
private static final int KEY_SIZE = 4096;
final Optional<InetSocketAddress> maybeSshSocketAddress = NetconfConfigUtil.extractNetconfServerAddress(bundleContext, InfixProp.ssh);
if (maybeSshSocketAddress.isPresent() == false) {
- logger.trace("SSH bridge not configured");
+ LOG.trace("SSH bridge not configured");
return null;
}
final InetSocketAddress sshSocketAddress = maybeSshSocketAddress.get();
- logger.trace("Starting netconf SSH bridge at {}", sshSocketAddress);
+ LOG.trace("Starting netconf SSH bridge at {}", sshSocketAddress);
final LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
* the server.
*/
public class EchoClient extends Thread {
- private static final Logger logger = LoggerFactory.getLogger(EchoClient.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
private final ChannelInitializer<LocalChannel> channelInitializer;
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} catch (Exception e) {
- logger.error("Error in client", e);
+ LOG.error("Error in client", e);
throw new RuntimeException("Error in client", e);
} finally {
// Shut down the event loop to terminate all threads.
- logger.info("Client is shutting down");
+ LOG.info("Client is shutting down");
group.shutdownGracefully();
}
}
* the server.
*/
public class EchoClientHandler extends ChannelInboundHandlerAdapter implements ChannelFutureListener {
- private static final Logger logger = LoggerFactory.getLogger(EchoClientHandler.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EchoClientHandler.class);
private ChannelHandlerContext ctx;
private final StringBuilder fromServer = new StringBuilder();
@Override
public synchronized void channelActive(ChannelHandlerContext ctx) {
checkState(this.ctx == null);
- logger.info("channelActive");
+ LOG.info("channelActive");
this.ctx = ctx;
state = State.CONNECTED;
}
ByteBuf bb = (ByteBuf) msg;
String string = bb.toString(Charsets.UTF_8);
fromServer.append(string);
- logger.info(">{}", string);
+ LOG.info(">{}", string);
bb.release();
}
@Override
public synchronized void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
- logger.warn("Unexpected exception from downstream.", cause);
+ LOG.warn("Unexpected exception from downstream.", cause);
checkState(this.ctx.equals(ctx));
ctx.close();
this.ctx = null;
public synchronized void operationComplete(ChannelFuture future) throws Exception {
checkState(state == State.CONNECTING);
if (future.isSuccess()) {
- logger.trace("Successfully connected, state will be switched in channelActive");
+ LOG.trace("Successfully connected, state will be switched in channelActive");
} else {
state = State.FAILED_TO_CONNECT;
}
* Echoes back any received data from a client.
*/
public class EchoServer implements Runnable {
- private static final Logger logger = LoggerFactory.getLogger(EchoServer.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EchoServer.class);
public void run() {
// Configure the server.
if (message == null || "exit".equalsIgnoreCase(message)) {
break;
}
- logger.debug("Got '{}'", message);
+ LOG.debug("Got '{}'", message);
clientHandler.write(message);
} while (true);
System.exit(0);
@Sharable
public class EchoServerHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(EchoServerHandler.class.getName());
+ private static final Logger LOG = LoggerFactory.getLogger(EchoServerHandler.class);
private String fromLastNewLine = "";
private final Splitter splitter = Splitter.onPattern("\r?\n");
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
- logger.debug("sleep start");
+ LOG.debug("sleep start");
Thread.sleep(1000);
- logger.debug("sleep done");
+ LOG.debug("sleep done");
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf byteBuf = (ByteBuf) msg;
String message = byteBuf.toString(Charsets.UTF_8);
- logger.info("writing back '{}'", message);
+ LOG.info("writing back '{}'", message);
ctx.write(msg);
fromLastNewLine += message;
for (String line : splitter.split(fromLastNewLine)) {
if ("quit".equals(line)) {
- logger.info("closing server ctx");
+ LOG.info("closing server ctx");
ctx.flush();
ctx.close();
break;
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
- logger.debug("flushing");
+ LOG.debug("flushing");
ctx.flush();
}
}
import org.slf4j.LoggerFactory;
public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(ProxyServerHandler.class.getName());
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyServerHandler.class);
private final Bootstrap clientBootstrap;
private final LocalAddress localAddress;
@Override
public void channelInactive(ChannelHandlerContext ctx) {
- logger.info("channelInactive - closing client connection");
+ LOG.info("channelInactive - closing client connection");
clientChannel.close();
}
@Override
public void channelRead(ChannelHandlerContext ctx, final Object msg) {
- logger.debug("Writing to client {}", msg);
+ LOG.debug("Writing to client {}", msg);
clientChannel.write(msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
- logger.debug("flushing");
+ LOG.debug("flushing");
clientChannel.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
- logger.warn("Unexpected exception from downstream.", cause);
+ LOG.warn("Unexpected exception from downstream.", cause);
ctx.close();
}
}
class ProxyClientHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(ProxyClientHandler.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
private final ChannelHandlerContext remoteCtx;
@Override
public void channelActive(ChannelHandlerContext ctx) {
- logger.info("client active");
+ LOG.info("client active");
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf bb = (ByteBuf) msg;
- logger.info(">{}", bb.toString(Charsets.UTF_8));
+ LOG.info(">{}", bb.toString(Charsets.UTF_8));
remoteCtx.write(msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
- logger.debug("Flushing server ctx");
+ LOG.debug("Flushing server ctx");
remoteCtx.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
- logger.warn("Unexpected exception from downstream", cause);
+ LOG.warn("Unexpected exception from downstream", cause);
ctx.close();
}
// called both when local or remote connection dies
@Override
public void channelInactive(ChannelHandlerContext ctx) {
- logger.debug("channelInactive() called, closing remote client ctx");
+ LOG.debug("channelInactive() called, closing remote client ctx");
remoteCtx.close();
}
}
import org.slf4j.LoggerFactory;
public class SSHTest {
- public static final Logger logger = LoggerFactory.getLogger(SSHTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SSHTest.class);
public static final String AHOJ = "ahoj\n";
private static EventLoopGroup nettyGroup;
Thread.sleep(500);
}
assertTrue(echoClientHandler.isConnected());
- logger.info("connected, writing to client");
+ LOG.info("connected, writing to client");
echoClientHandler.write(AHOJ);
// check that server sent back the same string
final String read = echoClientHandler.read();
assertTrue(read + " should end with " + AHOJ, read.endsWith(AHOJ));
} finally {
- logger.info("Closing socket");
+ LOG.info("Closing socket");
sshProxyServer.close();
}
}
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
-import java.net.InetSocketAddress;
import java.io.File;
+import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
private static final String PASSWORD = "netconf";
private static final String HOST = "127.0.0.1";
private static final int PORT = 1830;
- private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SSHServerTest.class);
private File sshKeyPair;
private SshProxyServer server;
doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString());
doReturn(new ServiceReference[0]).when(mockedContext).getServiceReferences(anyString(), anyString());
- logger.info("Creating SSH server");
+ LOG.info("Creating SSH server");
final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
return true;
}
}).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
- logger.info("SSH server started on " + PORT);
+ LOG.info("SSH server started on {}", PORT);
}
@Test