Search in sources :

Example 1 with AgentServerProxy

use of org.apache.sshd.agent.local.AgentServerProxy in project karaf by apache.

the class KarafAgentFactory method createClient.

public SshAgent createClient(FactoryManager manager) throws IOException {
    String proxyId = (String) manager.getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
    if (proxyId == null) {
        throw new IllegalStateException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + " environment variable set");
    }
    AgentServerProxy proxy = proxies.get(proxyId);
    if (proxy != null) {
        return proxy.createClient();
    }
    SshAgent agent = locals.get(proxyId);
    if (agent != null) {
        return new AgentDelegate(agent);
    }
    throw new IllegalStateException("No ssh agent found");
}
Also used : AgentDelegate(org.apache.sshd.agent.common.AgentDelegate) SshAgent(org.apache.sshd.agent.SshAgent) AgentServerProxy(org.apache.sshd.agent.local.AgentServerProxy)

Example 2 with AgentServerProxy

use of org.apache.sshd.agent.local.AgentServerProxy in project karaf by apache.

the class KarafAgentFactory method createServer.

public SshAgentServer createServer(ConnectionService service) throws IOException {
    Session session = service.getSession();
    if (!(session instanceof ServerSession)) {
        throw new IllegalStateException("The session used to create an agent server proxy must be a server session");
    }
    final AgentServerProxy proxy = new AgentServerProxy(service);
    proxies.put(proxy.getId(), proxy);
    return new SshAgentServer() {

        public String getId() {
            return proxy.getId();
        }

        @Override
        public boolean isOpen() {
            return proxy.isOpen();
        }

        public void close() throws IOException {
            proxies.remove(proxy.getId());
            proxy.close();
        }
    };
}
Also used : ServerSession(org.apache.sshd.server.session.ServerSession) SshAgentServer(org.apache.sshd.agent.SshAgentServer) AgentServerProxy(org.apache.sshd.agent.local.AgentServerProxy) ServerSession(org.apache.sshd.server.session.ServerSession) Session(org.apache.sshd.common.session.Session)

Aggregations

AgentServerProxy (org.apache.sshd.agent.local.AgentServerProxy)2 SshAgent (org.apache.sshd.agent.SshAgent)1 SshAgentServer (org.apache.sshd.agent.SshAgentServer)1 AgentDelegate (org.apache.sshd.agent.common.AgentDelegate)1 Session (org.apache.sshd.common.session.Session)1 ServerSession (org.apache.sshd.server.session.ServerSession)1