本文整理汇总了Java中org.eclipse.jgit.transport.SshSessionFactory类的典型用法代码示例。如果您正苦于以下问题:Java SshSessionFactory类的具体用法?Java SshSessionFactory怎么用?Java SshSessionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SshSessionFactory类属于org.eclipse.jgit.transport包,在下文中一共展示了SshSessionFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: strictHostKeyCheckShouldCheck
import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
@Test
public void strictHostKeyCheckShouldCheck() throws Exception {
String uri = "git+ssh://[email protected]/somegitrepo";
SshSessionFactory.setInstance(null);
jGitEnvironmentRepository.setUri(uri);
jGitEnvironmentRepository.setBasedir(new File("./mybasedir"));
assertTrue(jGitEnvironmentRepository.isStrictHostKeyChecking());
jGitEnvironmentRepository.setCloneOnStart(true);
try {
// this will throw but we don't care about connecting.
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);
assertTrue("yes".equals(valueCaptor.getValue()));
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:31,代码来源:TransportConfigurationIntegrationTests.java
示例17: configure
import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
/**
* Configures the transport to work with ssh-agent if an SSH transport is
* being used. {@inheritDoc}
*/
@Override
public void configure(final Transport transport) {
if (transport instanceof SshTransport) {
final SshTransport sshTransport = (SshTransport) transport;
final SshSessionFactory sshSessionFactory = new AgentJschConfigSessionFactory(authenticationInfo);
sshTransport.setSshSessionFactory(sshSessionFactory);
}
}
开发者ID:trajano,项目名称:wagon-git,代码行数:14,代码来源:JSchAgentCapableTransportConfigCallback.java
示例18: setupJGitAuthentication
import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
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);
}
开发者ID:hdweiss,项目名称:mOrgAnd,代码行数:11,代码来源:JGitWrapper.java
示例19: getDefault
import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
public static synchronized SshSessionFactory getDefault () {
if (INSTANCE == null) {
INSTANCE = new JGitSshSessionFactory();
}
return INSTANCE;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:JGitSshSessionFactory.java
示例20: cloneRepository
import org.eclipse.jgit.transport.SshSessionFactory; //导入依赖的package包/类
public static File cloneRepository(String cloneUrl, String repoPw) throws GitAPIException, JSONException, IOException {
config = ConfigParser.getConfig();
File tmpDir = new File("temp_repo");
String key = null;
String keyPassPhrase = null;
if (config.has("privateKey")) {
key = config.getString("privateKey");
keyPassPhrase = config.getString("privateKeyPassPhrase");
}
// git clone will fail if the directory already exists, even if empty
if (tmpDir.exists()) {
FileUtils.deleteDirectory(tmpDir);
}
String pw = null;
if (repoPw != null) {
pw = repoPw;
}
else if (config.has("gitClonePassword")) {
pw = config.getString("gitClonePassword");
}
final String finalKeyPassPhrase = keyPassPhrase;
final String finalKey = key;
SshSessionFactory sessionFactory = new CustomJschConfigSessionFactory();
// use a private key if provided
if (finalKey != null) {
SshSessionFactory.setInstance(sessionFactory);
}
// use a password if provided
if (pw != null) {
final String finalPw = pw;
SshSessionFactory.setInstance(new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setPassword(finalPw);
}
});
}
SshSessionFactory.setInstance(sessionFactory);
Git.cloneRepository()
.setURI(cloneUrl)
.setDirectory(tmpDir)
.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sessionFactory);
}
})
.call();
return tmpDir;
}
开发者ID:alianza-dev,项目名称:jenkins-test-job-generator,代码行数:56,代码来源:GitHelper.java
注:本文中的org.eclipse.jgit.transport.SshSessionFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论