org.apache.sshd.server.forward.AcceptAllForwardingFilter Java Examples
The following examples show how to use
org.apache.sshd.server.forward.AcceptAllForwardingFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SshProxyTest.java From ssh-proxy with Apache License 2.0 | 6 votes |
private SshServer setUpSshServer(String algorithm) throws IOException { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(0); AbstractGeneratorHostKeyProvider hostKeyProvider = SecurityUtils.createGeneratorHostKeyProvider(getServerKeyFile(algorithm)); hostKeyProvider.setAlgorithm(algorithm); if (algorithm.equals(KeyUtils.EC_ALGORITHM)) { hostKeyProvider.setKeySize(256); } sshServer.setKeyPairProvider(hostKeyProvider); sshServer.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshServer.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE); writeFingerprintToKnownHosts(algorithm); sshServer.start(); int sshServerPort = sshServer.getPort(); assertTrue(sshServerPort > 0); return sshServer; }
Example #2
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession(); session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(11L, TimeUnit.SECONDS); return session; }
Example #3
Source File: TestSshTunnel.java From datacollector with Apache License 2.0 | 5 votes |
private SshServer createSshd(PublickeyAuthenticator publickeyAuthenticator, java.security.KeyPair sshdKeyPair) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setHost("localhost"); sshd.setPort(randomPort()); KeyPairProvider keyPairProvider = KeyPairProvider.wrap(sshdKeyPair); sshd.setKeyPairProvider(keyPairProvider); sshd.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.setPublickeyAuthenticator(publickeyAuthenticator); return sshd; }
Example #4
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 5 votes |
protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshPort).verify(7L, TimeUnit.SECONDS).getSession(); session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(11L, TimeUnit.SECONDS); return session; }
Example #5
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); if (!requestsQ.isEmpty()) { requestsQ.clear(); } final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory"); sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() { private final Class<?>[] interfaces = {TcpipForwarder.class}; private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; // we're not serializing it... { put("localPortForwardingRequested", TcpipForwardHandler.REQUEST); put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST); } }; @Override public TcpipForwarder create(ConnectionService service) { Thread thread = Thread.currentThread(); ClassLoader cl = thread.getContextClassLoader(); final TcpipForwarder forwarder = factory.create(service); return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() { @SuppressWarnings("synthetic-access") @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(forwarder, args); String name = method.getName(); String request = method2req.get(name); if (GenericUtils.length(request) > 0) { if (requestsQ.offer(request)) { log.info("Signal " + request); } else { log.error("Failed to offer request=" + request); } } return result; } }); } }); sshPort = sshd.getPort(); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setHandler(new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { IoBuffer recv = (IoBuffer) message; IoBuffer sent = IoBuffer.allocate(recv.remaining()); sent.put(recv); sent.flip(); session.write(sent); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(0)); echoPort = acceptor.getLocalAddress().getPort(); this.acceptor = acceptor; }
Example #6
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); if (!requestsQ.isEmpty()) { requestsQ.clear(); } final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory"); sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() { private final Class<?>[] interfaces = {TcpipForwarder.class}; private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; // we're not serializing it... { put("localPortForwardingRequested", TcpipForwardHandler.REQUEST); put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST); } }; @Override public TcpipForwarder create(ConnectionService service) { Thread thread = Thread.currentThread(); ClassLoader cl = thread.getContextClassLoader(); final TcpipForwarder forwarder = factory.create(service); return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() { @SuppressWarnings("synthetic-access") @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(forwarder, args); String name = method.getName(); String request = method2req.get(name); if (GenericUtils.length(request) > 0) { if (requestsQ.offer(request)) { log.info("Signal " + request); } else { log.error("Failed to offer request=" + request); } } return result; } }); } }); sshPort = sshd.getPort(); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setHandler(new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { IoBuffer recv = (IoBuffer) message; IoBuffer sent = IoBuffer.allocate(recv.remaining()); sent.put(recv); sent.flip(); session.write(sent); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(0)); echoPort = acceptor.getLocalAddress().getPort(); this.acceptor = acceptor; }