当前位置: 首页>>代码示例>>Java>>正文


Java SshSessionFactory类代码示例

本文整理汇总了Java中org.eclipse.jgit.transport.SshSessionFactory的典型用法代码示例。如果您正苦于以下问题:Java SshSessionFactory类的具体用法?Java SshSessionFactory怎么用?Java SshSessionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SshSessionFactory类属于org.eclipse.jgit.transport包,在下文中一共展示了SshSessionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pushToRepository

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
 * Push all changes and tags to given remote.
 *
 * @param git
 *     instance.
 * @param remote
 *     to be used.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location.
 *
 * @return List of all results of given push.
 */
public Iterable<PushResult> pushToRepository(Git git, String remote, String passphrase, Path privateKey) {
    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return git.push()
            .setRemote(remote)
            .setPushAll()
            .setPushTags()
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:48,代码来源:GitOperations.java

示例2: getTransportConfigCallback

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
public static TransportConfigCallback getTransportConfigCallback() {
    final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            //session.setPassword(password);
        }
    };
    return new TransportConfigCallback() {

        public void configure(Transport transport) {
            if (transport instanceof TransportHttp)
                return;
            SshTransport sshTransport = (SshTransport) transport;
            sshTransport.setSshSessionFactory(sshSessionFactory);
        }
    };
}
 
开发者ID:warriorframework,项目名称:warrior-jenkins-plugin,代码行数:18,代码来源:WarriorPluginBuilder.java

示例3: pullFromRepository

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
 * Pull repository from current branch and remote branch with same name as current
 *
 * @param git
 *     instance.
 * @param remote
 *     to be used.
 * @param remoteBranch
 *     to use.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location.
 */
public PullResult pullFromRepository(final Git git, final String remote, String remoteBranch, final String passphrase,
    final Path privateKey) {
    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return git.pull()
            .setRemote(remote)
            .setRemoteBranchName(remoteBranch)
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:48,代码来源:GitOperations.java

示例4: cloneRepository

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
 * Clones a private remote git repository. Caller is responsible of closing git repository.
 *
 * @param remoteUrl
 *     to connect.
 * @param localPath
 *     where to clone the repo.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location. If null default (~.ssh/id_rsa) location is used.
 *
 * @return Git instance. Caller is responsible to close the connection.
 */
public Git cloneRepository(final String remoteUrl, final Path localPath, final String passphrase,
    final Path privateKey) {

    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return Git.cloneRepository()
            .setURI(remoteUrl)
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .setDirectory(localPath.toFile())
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:49,代码来源:GitOperations.java

示例5: initSsh

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
public static void initSsh(TestAccount a) {
  final Properties config = new Properties();
  config.put("StrictHostKeyChecking", "no");
  JSch.setConfig(config);

  // register a JschConfigSessionFactory that adds the private key as identity
  // to the JSch instance of JGit so that SSH communication via JGit can
  // succeed
  SshSessionFactory.setInstance(
      new JschConfigSessionFactory() {
        @Override
        protected void configure(Host hc, Session session) {
          try {
            final JSch jsch = getJSch(hc, FS.DETECTED);
            jsch.addIdentity("KeyPair", a.privateKey(), a.sshKey.getPublicKeyBlob(), null);
          } catch (JSchException e) {
            throw new RuntimeException(e);
          }
        }
      });
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:GitUtil.java

示例6: main

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
 * Starts a new {@link GitServer} instance on a specified port. You can specify a HTTP port by providing an argument
 * of the form <code>--httpPort=xxxx</code> where <code>xxxx</code> is a port number. If no such argument is
 * specified the HTTP port defaults to 8080.
 * 
 * @param args
 *        The arguments to influence the start-up phase of the {@link GitServer} instance.
 * @throws Exception
 *         In case the {@link GitServer} instance could not be started.
 */
public static void main(String[] args) throws Exception {
	SLF4JBridgeHandler.removeHandlersForRootLogger();
	SLF4JBridgeHandler.install();

	// TODO: Fix this...
	SshSessionFactory.setInstance(new JschConfigSessionFactory() {
		@Override
		protected void configure(Host hc, Session session) {
			session.setConfig("StrictHostKeyChecking", "no");
		}
	});

	Config config = new Config();
	config.reload();
	
	GitServer server = new GitServer(config);
	server.start();
	server.join();
}
 
开发者ID:devhub-tud,项目名称:git-server,代码行数:30,代码来源:GitServer.java

示例7: setKeyLocation

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
public void setKeyLocation(final String keyPath) {
    SshSessionFactory.setInstance(new JschConfigSessionFactory() {
        public void configure(Host hc, Session session) {
            session.setConfig("StrictHostKeyChecking", "no");
            try {
                getJSch(hc, FS.DETECTED).addIdentity(keyPath);
            } catch (Exception e) {
                /*
                   runOnUiThread(new Runnable() {
                   public void run() {
                   Toast.makeText(context, "Could not find SSH key", Toast.LENGTH_LONG).show();
                   }
                   });
                   */
            }
        }
    });
}
 
开发者ID:blinry,项目名称:roboboy,代码行数:19,代码来源:Wiki.java

示例8: JGitAPIImpl

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
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);
    }
}
 
开发者ID:jenkinsci,项目名称:git-client-plugin,代码行数:17,代码来源:JGitAPIImpl.java

示例9: getSshSessionFactory

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
   * Gets the an SshSessionFactory that is customised to allow for authentication for the specified
   * {@code repository}. This is used when connecting to a Git repository over an SSH tunnel.
   * 
   * @param repository the repository to get the session factory for. Must not be {@code null}
   * @return the session factory. Never {@code null}
   */
  private SshSessionFactory getSshSessionFactory(final GitRepository repository) {
  	assert repository != null : "repository must not be null";
  	
  	final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
  		@Override
  		protected void configure(final Host hc, final Session session) {
  		}
	@Override
	protected JSch createDefaultJSch(final FS fs) throws JSchException {
		JSch.setConfig("StrictHostKeyChecking", "no");
		
		final JSch jsch = new JSch();
		if (repository.getPrivateKeyPath() != null) {
			jsch.addIdentity(repository.getPrivateKeyPath().getPath());
		}
    	return jsch;
	}
};
return sshSessionFactory;
  }
 
开发者ID:astralbat,项目名称:gitcommitviewer,代码行数:28,代码来源:DefaultGitRepositoryService.java

示例10: getRepository

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
private synchronized JGitRepository getRepository () {
    if (gitRepository == null) {
        gitRepository = new JGitRepository(repositoryLocation);
        SshSessionFactory.setInstance(JGitSshSessionFactory.getDefault());
    }
    return gitRepository;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GitRepository.java

示例11: configure

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
@Override
protected void configure() {
  bind(DestinationFactory.class).in(Scopes.SINGLETON);
  bind(ReplicationQueue.class).in(Scopes.SINGLETON);

  DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(ReplicationQueue.class);
  DynamicSet.bind(binder(), NewProjectCreatedListener.class).to(ReplicationQueue.class);
  DynamicSet.bind(binder(), ProjectDeletedListener.class).to(ReplicationQueue.class);
  DynamicSet.bind(binder(), HeadUpdatedListener.class).to(ReplicationQueue.class);

  bind(OnStartStop.class).in(Scopes.SINGLETON);
  bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(OnStartStop.class);
  bind(LifecycleListener.class)
      .annotatedWith(UniqueAnnotations.create())
      .to(ReplicationLogFile.class);
  bind(CredentialsFactory.class)
      .to(AutoReloadSecureCredentialsFactoryDecorator.class)
      .in(Scopes.SINGLETON);
  bind(CapabilityDefinition.class)
      .annotatedWith(Exports.named(START_REPLICATION))
      .to(StartReplicationCapability.class);

  install(new FactoryModuleBuilder().build(PushAll.Factory.class));
  install(new FactoryModuleBuilder().build(RemoteSiteUser.Factory.class));

  bind(ReplicationConfig.class).to(AutoReloadConfigDecorator.class);
  bind(ReplicationStateListener.class).to(ReplicationStateLogger.class);

  EventTypes.register(RefReplicatedEvent.TYPE, RefReplicatedEvent.class);
  EventTypes.register(RefReplicationDoneEvent.TYPE, RefReplicationDoneEvent.class);
  EventTypes.register(ReplicationScheduledEvent.TYPE, ReplicationScheduledEvent.class);
  bind(SshSessionFactory.class).toProvider(ReplicationSshSessionFactoryProvider.class);
}
 
开发者ID:GerritCodeReview,项目名称:plugins_replication,代码行数:34,代码来源:ReplicationModule.java

示例12: configureCommand

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
 * Configures the transport of the command to deal with things like SSH
 */
public static <C extends GitCommand> void configureCommand(TransportCommand<C, ?> command, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey) {
    if (sshPrivateKey != null) {
        final CredentialsProvider provider = credentialsProvider;
        command.setTransportConfigCallback(new TransportConfigCallback() {
            @Override
            public void configure(Transport transport) {
                if (transport instanceof SshTransport) {
                    SshTransport sshTransport = (SshTransport) transport;
                    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
                        @Override
                        protected void configure(OpenSshConfig.Host host, Session session) {
                            session.setConfig("StrictHostKeyChecking", "no");
                            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
                            session.setUserInfo(userInfo);
                        }

                        @Override
                        protected JSch createDefaultJSch(FS fs) throws JSchException {
                            JSch jsch = super.createDefaultJSch(fs);
                            jsch.removeAllIdentity();
                            String absolutePath = sshPrivateKey.getAbsolutePath();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Adding identity privateKey: " + sshPrivateKey + " publicKey: " + sshPublicKey);
                            }
                            if (sshPublicKey != null) {
                                jsch.addIdentity(absolutePath, sshPublicKey.getAbsolutePath(), null);
                            } else {
                                jsch.addIdentity(absolutePath);
                            }
                            return jsch;
                        }
                    };
                    sshTransport.setSshSessionFactory(sshSessionFactory);
                }
            }
        });
    }
}
 
开发者ID:fabric8io,项目名称:fabric8-devops,代码行数:42,代码来源:GitHelpers.java

示例13: configure

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
@Override
protected void configure() {
    install(RepositoryScope.module());
    install(OperationScope.module());
    bind(UserInfo.class).to(GUIUserInfo.class);
    bind(ImageSession.class).toProvider(ImageSessionProvider.class).in(ContextSingleton.class);

    bind(Repository.class).toProvider(RepositoryProvider.class);
    bind(Ref.class).annotatedWith(named("branch")).toProvider(BranchRefProvider.class);
    bind(AndroidAuthAgent.class).toProvider(AndroidAuthAgentProvider.class);
    bind(GitAsyncTaskFactory.class).toProvider(newFactory(GitAsyncTaskFactory.class, GitAsyncTask.class));
    bind(ContextScopedViewInflatorFactory.class).toProvider(newFactory(ContextScopedViewInflatorFactory.class,
            ContextScopedViewInflator.class));

    bind(SyncCampaignFactory.class).toProvider(newFactory(SyncCampaignFactory.class, SyncCampaign.class));

    bind(TransportConfigCallback.class).to(AgitTransportConfig.class);
    bind(CredentialsProvider.class).to(GUICredentialsProvider.class);
    bind(SshSessionFactory.class).to(AndroidSshSessionFactory.class);
    bind(PromptUIRegistry.class);

    bind(HostKeyRepository.class).to(CuriousHostKeyRepository.class);
    bind(PromptUI.class).annotatedWith(named("status-bar")).to(StatusBarPromptUI.class);

    bind(RepoDomainType.class).annotatedWith(named("branch")).to(RDTBranch.class);
    bind(RepoDomainType.class).annotatedWith(named("remote")).to(RDTRemote.class);
    bind(RepoDomainType.class).annotatedWith(named("tag")).to(RDTTag.class);

    bind(CommitViewHolderFactory.class).toProvider(newFactory(CommitViewHolderFactory.class,
            CommitViewHolder.class));
    bind(BranchViewHolderFactory.class).toProvider(newFactory(BranchViewHolderFactory.class,
            BranchViewHolder.class));
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:34,代码来源:AgitModule.java

示例14: gitSync

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
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();
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:13,代码来源:DevicesGit.java

示例15: initialize

import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
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;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:13,代码来源:JGitEnvironmentRepository.java


注:本文中的org.eclipse.jgit.transport.SshSessionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。