Java Code Examples for org.eclipse.jgit.transport.SshSessionFactory#setInstance()

The following examples show how to use org.eclipse.jgit.transport.SshSessionFactory#setInstance() . 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: JGitAPIImpl.java    From git-client-plugin with MIT License 6 votes vote down vote up
JGitAPIImpl(File workspace, TaskListener listener, final PreemptiveAuthHttpClientConnectionFactory httpConnectionFactory) {
    /* If workspace is null, then default to current directory to match 
     * CliGitAPIImpl behavior */
    super(workspace == null ? new File(".") : workspace);
    this.listener = listener;

    // to avoid rogue plugins from clobbering what we use, always
    // make a point of overwriting it with ours.
    SshSessionFactory.setInstance(new TrileadSessionFactory());

    if (httpConnectionFactory != null) {
        httpConnectionFactory.setCredentialsProvider(asSmartCredentialsProvider());
        // allow override of HttpConnectionFactory to avoid JENKINS-37934
        HttpTransport.setConnectionFactory(httpConnectionFactory);
    }
}
 
Example 2
Source File: GitRepository.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized JGitRepository getRepository () {
    if (gitRepository == null) {
        gitRepository = new JGitRepository(repositoryLocation);
        SshSessionFactory.setInstance(JGitSshSessionFactory.getDefault());
    }
    return gitRepository;
}
 
Example 3
Source File: DevicesGit.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public static void gitSync() throws IOException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException, GitAPIException {
	SshSessionFactory.setInstance(new JschConfigSessionFactory() {
		  public void configure(Host hc, Session session) {
		    session.setConfig("StrictHostKeyChecking", "no");
		  };
		}
	);
	if (openRepository()) {
		pullRepository();
	}
	else cloneRepository();
}
 
Example 4
Source File: JGitEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
private void initialize() {
	if (!this.initialized) {
		SshSessionFactory.setInstance(new JschConfigSessionFactory() {
			@Override
			protected void configure(Host hc, Session session) {
				session.setConfig("StrictHostKeyChecking",
						isStrictHostKeyChecking() ? "yes" : "no");
			}
		});
		this.initialized = true;
	}
}
 
Example 5
Source File: FileBasedSshTransportConfigCallback.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Transport transport) {
	SshSessionFactory.setInstance(new JschConfigSessionFactory() {
		@Override
		protected void configure(OpenSshConfig.Host hc, Session session) {
			session.setConfig("StrictHostKeyChecking",
					FileBasedSshTransportConfigCallback.this.sshUriProperties
							.isStrictHostKeyChecking() ? "yes" : "no");
		}
	});
}
 
Example 6
Source File: TransportConfigurationIntegrationTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void strictHostKeyCheckShouldCheck() throws Exception {
	String uri = "git+ssh://git@somegitserver/somegitrepo";
	SshSessionFactory.setInstance(null);
	this.jGitEnvironmentRepository.setUri(uri);
	this.jGitEnvironmentRepository.setBasedir(new File("./mybasedir"));
	assertThat(this.jGitEnvironmentRepository.isStrictHostKeyChecking())
			.isTrue();
	this.jGitEnvironmentRepository.setCloneOnStart(true);
	try {
		// this will throw but we don't care about connecting.
		this.jGitEnvironmentRepository.afterPropertiesSet();
	}
	catch (Exception e) {
		final OpenSshConfig.Host hc = OpenSshConfig.get(FS.detect())
				.lookup("github.com");
		JschConfigSessionFactory factory = (JschConfigSessionFactory) SshSessionFactory
				.getInstance();
		// There's no public method that can be used to inspect the ssh
		// configuration, so we'll reflect
		// the configure method to allow us to check that the config
		// property is set as expected.
		Method configure = factory.getClass().getDeclaredMethod("configure",
				OpenSshConfig.Host.class, Session.class);
		configure.setAccessible(true);
		Session session = mock(Session.class);
		ArgumentCaptor<String> keyCaptor = ArgumentCaptor
				.forClass(String.class);
		ArgumentCaptor<String> valueCaptor = ArgumentCaptor
				.forClass(String.class);
		configure.invoke(factory, hc, session);
		verify(session).setConfig(keyCaptor.capture(), valueCaptor.capture());
		configure.setAccessible(false);
		assertThat("yes".equals(valueCaptor.getValue())).isTrue();
	}
}
 
Example 7
Source File: TransportConfigurationIntegrationTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void strictHostKeyCheckShouldCheck() throws Exception {
	String uri = "git+ssh://git@somegitserver/somegitrepo";
	SshSessionFactory.setInstance(null);
	this.jGitEnvironmentRepository.setUri(uri);
	this.jGitEnvironmentRepository.setBasedir(new File("./mybasedir"));
	assertThat(this.jGitEnvironmentRepository.isStrictHostKeyChecking())
			.isTrue();
	this.jGitEnvironmentRepository.setCloneOnStart(true);
	try {
		// this will throw but we don't care about connecting.
		this.jGitEnvironmentRepository.afterPropertiesSet();
	}
	catch (Exception e) {
		final OpenSshConfig.Host hc = OpenSshConfig.get(FS.detect())
				.lookup("github.com");
		JschConfigSessionFactory factory = (JschConfigSessionFactory) SshSessionFactory
				.getInstance();
		// There's no public method that can be used to inspect the ssh
		// configuration, so we'll reflect
		// the configure method to allow us to check that the config
		// property is set as expected.
		Method configure = factory.getClass().getDeclaredMethod("configure",
				OpenSshConfig.Host.class, Session.class);
		configure.setAccessible(true);
		Session session = mock(Session.class);
		ArgumentCaptor<String> keyCaptor = ArgumentCaptor
				.forClass(String.class);
		ArgumentCaptor<String> valueCaptor = ArgumentCaptor
				.forClass(String.class);
		configure.invoke(factory, hc, session);
		verify(session).setConfig(keyCaptor.capture(), valueCaptor.capture());
		configure.setAccessible(false);
		assertThat("yes".equals(valueCaptor.getValue())).isTrue();
	}
}
 
Example 8
Source File: JGitWrapper.java    From mOrgAnd with GNU General Public License v2.0 5 votes vote down vote up
private void setupJGitAuthentication(SharedPreferences preferences) {
    String username = preferences.getString("git_username", "");
    String password = preferences.getString("git_password", "");
    String keyLocation = preferences.getString("git_key_path", "");

    JGitConfigSessionFactory session = new JGitConfigSessionFactory(username, password, keyLocation);
    SshSessionFactory.setInstance(session);

    credentialsProvider = new JGitCredentialsProvider(username, password);
}
 
Example 9
Source File: GitActivator.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void start(BundleContext context) throws Exception {
	context.registerService(IWebResourceDecorator.class, new GitFileDecorator(), null);
	SshSessionFactory.setInstance(new GitSshSessionFactory());
}
 
Example 10
Source File: DifferentFilesSshFetchTest.java    From gitflow-incremental-builder with MIT License 4 votes vote down vote up
@AfterEach
void resetSshSessionFactory() throws Exception {
    SshSessionFactory.setInstance(null);    // force reload of known_host etc. (see also org.eclipse.jgit.transport.ssh.SshTestHarness)
}
 
Example 11
Source File: SshUriPropertyProcessorTest.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() {
	SshSessionFactory.setInstance(null);
}
 
Example 12
Source File: GitBasedArtifactRepository.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes SSH authentication
 */
private void initSSHAuthentication() {

    SshSessionFactory.setInstance(new CustomJschConfigSessionFactory());
}