1 package cn.home1.cloud.config.server.ssh;
2
3 import com.jcraft.jsch.JSch;
4 import com.jcraft.jsch.JSchException;
5 import com.jcraft.jsch.Session;
6
7 import org.eclipse.jgit.transport.JschConfigSessionFactory;
8 import org.eclipse.jgit.transport.OpenSshConfig;
9 import org.eclipse.jgit.util.FS;
10
11
12
13
14
15
16 @Deprecated
17 public class CustomJschConfigSessionFactory extends JschConfigSessionFactory {
18
19 private String[] identityKeyPaths;
20
21 public CustomJschConfigSessionFactory(final String... identityKeyPaths) {
22 this.identityKeyPaths = identityKeyPaths;
23 }
24
25 @Override
26 protected void configure(final OpenSshConfig.Host hc, final Session session) {
27
28 session.setConfig("StrictHostKeyChecking", "no");
29 }
30
31 @Override
32 protected JSch getJSch(final OpenSshConfig.Host hc, final FS fs) throws JSchException {
33 final JSch jsch = super.getJSch(hc, fs);
34
35 jsch.removeAllIdentity();
36 for (final String identKeyPath : this.identityKeyPaths) {
37 jsch.addIdentity(identKeyPath);
38 }
39 return jsch;
40 }
41 }