本文整理汇总了Java中org.eclipse.jgit.transport.JschConfigSessionFactory类的典型用法代码示例。如果您正苦于以下问题:Java JschConfigSessionFactory类的具体用法?Java JschConfigSessionFactory怎么用?Java JschConfigSessionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JschConfigSessionFactory类属于org.eclipse.jgit.transport包,在下文中一共展示了JschConfigSessionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pushToRepository
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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);
}
}
示例2: initSessionFactory
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
private void initSessionFactory() {
JschConfigSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch jSch = super.createDefaultJSch(fs);
// apply customized private key
if (privateKeyPath != null) {
jSch.removeAllIdentity();
jSch.addIdentity(privateKeyPath.toString());
}
return jSch;
}
};
transportConfigCallback = transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
};
}
示例3: getTransportConfigCallback
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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);
}
};
}
示例4: getPublicKeys
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
private static List<String> getPublicKeys() throws Exception {
return new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
}
List<String> getPublicKeys() throws Exception {
JSch jSch = createDefaultJSch(FS.DETECTED);
List<String> keys = new ArrayList<>();
for (Object o : jSch.getIdentityRepository().getIdentities()) {
Identity i = (Identity) o;
KeyPair keyPair = KeyPair.load(jSch, i.getName(), null);
StringBuilder sb = new StringBuilder();
try (StringBuilderWriter sbw = new StringBuilderWriter(sb);
OutputStream os = new WriterOutputStream(sbw, "UTF-8")) {
keyPair.writePublicKey(os, keyPair.getPublicKeyComment());
} finally {
keyPair.dispose();
}
keys.add(sb.toString().trim());
}
return keys;
}
}.getPublicKeys();
}
示例5: pullFromRepository
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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);
}
}
示例6: cloneRepository
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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);
}
}
示例7: configureJsch
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
protected final void configureJsch() {
if (!disableSshAgent) {
if (serverId != null) {
final Server server = settings.getServer(serverId);
if (server != null) {
privateKey = privateKey == null ? server.getPrivateKey() : privateKey;
passphrase = passphrase == null ? server.getPassphrase() : passphrase;
} else {
getLog().warn(format("No server configuration in Maven settings found with id %s", serverId));
}
}
JschConfigSessionFactory
.setInstance(new SshAgentSessionFactory(getLog(), knownHosts, privateKey, passphrase));
}
}
示例8: initSsh
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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);
}
}
});
}
示例9: main
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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();
}
示例10: setKeyLocation
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的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();
}
});
*/
}
}
});
}
示例11: setup
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
@Before
public void setup() {
mojo.project = mock(MavenProject.class);
when(server.getPrivateKey()).thenReturn(SETTINGS_IDENTITY_FILE);
when(server.getPassphrase()).thenReturn(SETTINGS_PASSPHRASE);
when(settings.getServer(SERVER_ID)).thenReturn(server);
mojo.setSettings(settings);
mojo.setLog(log);
JschConfigSessionFactory.setInstance(null);
}
示例12: configureJsch_SshAgentDisabled
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
@Test
public void configureJsch_SshAgentDisabled() {
mojo.disableSshAgent();
mojo.configureJsch();
assertEquals("org.eclipse.jgit.transport.DefaultSshSessionFactory",
JschConfigSessionFactory.getInstance().getClass().getName());
}
示例13: configureJsch_CustomKnownHosts
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
@Test
public void configureJsch_CustomKnownHosts() {
mojo.setKnownHosts(KNOWN_HOSTS);
mojo.configureJsch();
final SshAgentSessionFactory factory = (SshAgentSessionFactory) JschConfigSessionFactory.getInstance();
assertEquals(KNOWN_HOSTS, factory.getKnownHostsOrNull());
}
示例14: configureJsch
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
protected final void configureJsch(final Log log) {
if (!disableSshAgent) {
if (serverId != null) {
final Server server = settings.getServer(serverId);
if (server != null) {
privateKey = privateKey == null ? server.getPrivateKey() : privateKey;
passphrase = passphrase == null ? server.getPassphrase() : passphrase;
} else {
log.warn(format("No server configuration in Maven settings found with id %s", serverId));
}
}
JschConfigSessionFactory.setInstance(new SshAgentSessionFactory(log, knownHosts, privateKey, passphrase));
}
}
示例15: setup
import org.eclipse.jgit.transport.JschConfigSessionFactory; //导入依赖的package包/类
@Before
public void setup() {
when(server.getPrivateKey()).thenReturn(SETTINGS_IDENTITY_FILE);
when(server.getPassphrase()).thenReturn(SETTINGS_PASSPHRASE);
when(settings.getServer(SERVER_ID)).thenReturn(server);
mojo.setSettings(settings);
JschConfigSessionFactory.setInstance(null);
}