Java Code Examples for org.apache.sshd.common.util.ValidateUtils#checkNotNull()
The following examples show how to use
org.apache.sshd.common.util.ValidateUtils#checkNotNull() .
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: Utils.java From termd with Apache License 2.0 | 6 votes |
public static KeyPairProvider createTestHostKeyProvider(Class<?> anchor) { KeyPairProvider provider = KEYPAIR_PROVIDER_HOLDER.get(); if (provider != null) { return provider; } File targetFolder = ValidateUtils.checkNotNull(detectTargetFolder(anchor), "Failed to detect target folder"); File file = new File(targetFolder, "hostkey." + DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM.toLowerCase()); provider = createTestHostKeyProvider(file); KeyPairProvider prev = KEYPAIR_PROVIDER_HOLDER.getAndSet(provider); if (prev != null) { // check if somebody else beat us to it return prev; } else { return provider; } }
Example 2
Source File: Utils.java From termd with Apache License 2.0 | 6 votes |
public static KeyPairProvider createTestHostKeyProvider(Class<?> anchor) { KeyPairProvider provider = KEYPAIR_PROVIDER_HOLDER.get(); if (provider != null) { return provider; } File targetFolder = ValidateUtils.checkNotNull(detectTargetFolder(anchor), "Failed to detect target folder"); File file = new File(targetFolder, "hostkey." + DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM.toLowerCase()); provider = createTestHostKeyProvider(file); KeyPairProvider prev = KEYPAIR_PROVIDER_HOLDER.getAndSet(provider); if (prev != null) { // check if somebody else beat us to it return prev; } else { return provider; } }
Example 3
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
public static KeyPair getFirstKeyPair(KeyIdentityProvider provider) { ValidateUtils.checkNotNull(provider, "No key pair provider"); Iterable<? extends KeyPair> pairs = ValidateUtils.checkNotNull(provider.loadKeys(), "No loaded keys"); Iterator<? extends KeyPair> iter = ValidateUtils.checkNotNull(pairs.iterator(), "No keys iterator"); ValidateUtils.checkTrue(iter.hasNext(), "Empty loaded kyes iterator"); return ValidateUtils.checkNotNull(iter.next(), "No key pair in iterator"); }
Example 4
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
private static <P extends KeyIdentityProvider> P validateKeyPairProvider(P provider) { ValidateUtils.checkNotNull(provider, "No provider"); // get the I/O out of the way Iterable<KeyPair> keys = ValidateUtils.checkNotNull(provider.loadKeys(), "No keys loaded"); if (keys instanceof Collection<?>) { ValidateUtils.checkNotNullAndNotEmpty((Collection<?>) keys, "Empty keys loaded"); } return provider; }
Example 5
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
public static KeyPair getFirstKeyPair(KeyIdentityProvider provider) { ValidateUtils.checkNotNull(provider, "No key pair provider"); Iterable<? extends KeyPair> pairs = ValidateUtils.checkNotNull(provider.loadKeys(), "No loaded keys"); Iterator<? extends KeyPair> iter = ValidateUtils.checkNotNull(pairs.iterator(), "No keys iterator"); ValidateUtils.checkTrue(iter.hasNext(), "Empty loaded kyes iterator"); return ValidateUtils.checkNotNull(iter.next(), "No key pair in iterator"); }
Example 6
Source File: Utils.java From termd with Apache License 2.0 | 5 votes |
private static <P extends KeyIdentityProvider> P validateKeyPairProvider(P provider) { ValidateUtils.checkNotNull(provider, "No provider"); // get the I/O out of the way Iterable<KeyPair> keys = ValidateUtils.checkNotNull(provider.loadKeys(), "No keys loaded"); if (keys instanceof Collection<?>) { ValidateUtils.checkNotNullAndNotEmpty((Collection<?>) keys, "Empty keys loaded"); } return provider; }
Example 7
Source File: AbstractUserAuth.java From termd with Apache License 2.0 | 4 votes |
protected AbstractUserAuth(ClientSession session, String service) { this.session = ValidateUtils.checkNotNull(session, "No client session"); this.service = service; }
Example 8
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 9
Source File: AbstractUserAuth.java From termd with Apache License 2.0 | 4 votes |
protected AbstractUserAuth(ClientSession session, String service) { this.session = ValidateUtils.checkNotNull(session, "No client session"); this.service = service; }
Example 10
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; }