2 * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> and others
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
8 * SPDX-License-Identifier: BSD-3-Clause
10 package org.eclipse.jgit.internal.transport.sshd.agent;
13 import java.io.IOException;
14 import java.util.Collections;
15 import java.util.List;
17 import org.apache.sshd.agent.SshAgent;
18 import org.apache.sshd.agent.SshAgentFactory;
19 import org.apache.sshd.agent.SshAgentServer;
20 import org.apache.sshd.common.FactoryManager;
21 import org.apache.sshd.common.channel.ChannelFactory;
22 import org.apache.sshd.common.session.ConnectionService;
23 import org.eclipse.jgit.annotations.NonNull;
24 import org.eclipse.jgit.transport.sshd.agent.ConnectorFactory;
27 * A factory for creating {@link SshAgentClient}s.
29 public class JGitSshAgentFactory implements SshAgentFactory {
31 private final @NonNull ConnectorFactory factory;
33 private final File homeDir;
36 * Creates a new {@link JGitSshAgentFactory}.
39 * {@link JGitSshAgentFactory} to wrap
41 * for obtaining the current local user's home directory
43 public JGitSshAgentFactory(@NonNull ConnectorFactory factory,
45 this.factory = factory;
46 this.homeDir = homeDir;
50 public List<ChannelFactory> getChannelForwardingFactories(
51 FactoryManager manager) {
52 // No agent forwarding supported yet.
53 return Collections.emptyList();
57 public SshAgent createClient(FactoryManager manager) throws IOException {
58 // sshd 2.8.0 will pass us the session here. At that point, we can get
59 // the HostConfigEntry and extract and handle the IdentityAgent setting.
60 // For now, pass null to let the ConnectorFactory do its default
61 // behavior (Pageant on Windows, SSH_AUTH_SOCK on Unixes with the
62 // jgit-builtin factory).
63 return new SshAgentClient(factory.create(null, homeDir));
67 public SshAgentServer createServer(ConnectionService service)
69 // This should be called in a server only.