本文整理汇总了Java中org.eclipse.jgit.transport.SshSessionFactory.setInstance方法的典型用法代码示例。如果您正苦于以下问题:Java SshSessionFactory.setInstance方法的具体用法?Java SshSessionFactory.setInstance怎么用?Java SshSessionFactory.setInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.transport.SshSessionFactory
的用法示例。
在下文中一共展示了SshSessionFactory.setInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
});
}
示例2: 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();
}
示例3: 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();
}
});
*/
}
}
});
}
示例4: 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);
}
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
}
示例8: 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
示例9: 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);
}
示例10: 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;
}
示例11: initSSHAuthentication
import org.eclipse.jgit.transport.SshSessionFactory; //导入方法依赖的package包/类
/**
* Initializes SSH authentication
*/
private void initSSHAuthentication() {
SshSessionFactory.setInstance(new CustomJschConfigSessionFactory());
}
示例12: cleanup
import org.eclipse.jgit.transport.SshSessionFactory; //导入方法依赖的package包/类
@After
public void cleanup() {
SshSessionFactory.setInstance(null);
}
示例13: createMember
import org.eclipse.jgit.transport.SshSessionFactory; //导入方法依赖的package包/类
@Override
public void createMember(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
String gitUrl = state.getPropertyAsString("url");
String id = state.id();
String branch = state.getPropertyAsString("branch");
String user = state.getPropertyAsString("user");
String password = state.getPropertyAsString("pwd");
String passphrase = state.getPropertyAsString("passphrase");
if (!hasValue(gitUrl)) {
responder.invalidRequest(String.format(INVALID_REQUEST_MESSAGE, gitUrl));
return;
}
if (!hasValue(id)) {
int start = gitUrl.lastIndexOf('/');
int end = gitUrl.indexOf(".git", start);
id = gitUrl.substring(start + 1, end);
}
File installDir = new File(this.appsDir, id);
boolean cloneSucceeded = false;
try {
CloneCommand cloneCommand = Git.cloneRepository()
.setURI(gitUrl)
.setRemote("upstream")
.setDirectory(installDir);
if (hasValue(branch)) {
// Set branch to checkout
cloneCommand.setBranch(branch);
}
if (hasValue(user) && hasValue(password)) {
// Set credentials for cloning
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password));
}
if (hasValue(passphrase)) {
// Set SSH factory
SshSessionFactory.setInstance(new LiveOakSshSessionFactory(passphrase));
}
Git repo = cloneCommand.call();
repo.close();
cloneSucceeded = true;
} catch (InvalidRemoteException ire) {
responder.invalidRequest(String.format(INVALID_REQUEST_MESSAGE, gitUrl));
return;
} catch (TransportException te) {
responder.invalidRequest("Unable to connect to git repo due to: " + te.getMessage());
return;
} finally {
if (!cloneSucceeded && installDir.exists()) {
// Remove application directory
FileHelper.deleteNonEmpty(installDir);
}
}
InternalApplication app = this.registry.createApplication(id, (String) state.getProperty("name"), installDir, dir -> {
try {
Git gitRepo = GitHelper.initRepo(dir);
GitHelper.addAllAndCommit(gitRepo, ctx.securityContext().getUser(), "Import LiveOak application from git: " + gitUrl);
gitRepo.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
responder.resourceCreated(app.resource());
}
示例14: setAuthentication
import org.eclipse.jgit.transport.SshSessionFactory; //导入方法依赖的package包/类
/**
* Sets the authentication using user/pwd scheme
*
* @param username the username
* @param password the password
* @return the current object
*/
GitOperation setAuthentication(String username, String password) {
SshSessionFactory.setInstance(new GitConfigSessionFactory());
this.provider = new UsernamePasswordCredentialsProvider(username, password);
return this;
}