本文整理汇总了Java中com.jcraft.jsch.agentproxy.RemoteIdentityRepository类的典型用法代码示例。如果您正苦于以下问题:Java RemoteIdentityRepository类的具体用法?Java RemoteIdentityRepository怎么用?Java RemoteIdentityRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RemoteIdentityRepository类属于com.jcraft.jsch.agentproxy包,在下文中一共展示了RemoteIdentityRepository类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSessionSshAgent
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; //导入依赖的package包/类
private Session initSessionSshAgent(String username, String socketPath, JSch jsch) throws JSchException {
final Session session = jsch.getSession(username, myHost, myPort);
session.setConfig("PreferredAuthentications", "publickey");
try {
ConnectorFactory cf = ConnectorFactory.getDefault();
cf.setUSocketPath(socketPath);
Connector con = cf.createConnector();
IdentityRepository irepo = new RemoteIdentityRepository(con);
jsch.setIdentityRepository(irepo);
return session;
} catch (AgentProxyException e) {
throw new JSchException("Failed to connect to ssh agent.", e);
}
}
示例2: newSession
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; //导入依赖的package包/类
private Session newSession() throws JSchException {
JSch jSch = new JSch();
try {
jSch.setConfig("PreferredAuthentications", "publickey");
if (hostInfo.isDoHostKeyChecks()) {
jSch.setKnownHosts(userInfo.sshFolderLocation() + File.separator + "known_hosts");
} else {
jSch.setHostKeyRepository(new FakeHostKeyRepository());
}
if (userInfo.isUseAgentIdentities()) {
Connector connector = ConnectorFactory.getDefault().createConnector();
if (connector != null) {
IdentityRepository identityRepository = new RemoteIdentityRepository(connector);
jSch.setIdentityRepository(identityRepository);
}
}
// add private key to the IdentityRepository. If using agent identities, this will add the private
// key to the agent, if it is not already present.
jSch.addIdentity(userInfo.privateKeyLocation().getAbsolutePath());
session = jSch.getSession(userInfo.getUserName(), hostInfo.getHostname(), hostInfo.getPort());
Long timeout = TimeUnit.SECONDS.toMillis(hostInfo.getTimeoutSeconds());
session.setTimeout(timeout.intValue());
session.setUserInfo(new PasswordlessEnabledUser(userInfo.getPassphrase()));
return session;
} catch (JSchException | AgentProxyException e) {
String msg = ExecutionFailedException.userFriendlyCause(e.getMessage(), hostInfo.getHostname(), userInfo);
throw new ExecutionFailedException(msg, e);
}
}
示例3: RemoteClient
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; //导入依赖的package包/类
public RemoteClient(Environment environment, DeploymentContext context, Logger logger) throws RemoteClientException {
RemoteClient instance = this;
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
instance.tryDisconnect();
}
});
this.logger = logger;
try {
JSch shellClient = new JSch();
shellClient.setKnownHosts(new FileInputStream(new File(System.getenv("HOME") + "/.ssh/known_hosts")));
ConnectorFactory connectorFactory = ConnectorFactory.getDefault();
Connector connector = connectorFactory.createConnector();
Properties config = new java.util.Properties();
config.put("PreferredAuthentications", "publickey");
if (context.project().options().containsKey("check_host_keys")) {
String option = (boolean) context.project().options().get("check_host_keys") ? "yes" : "no";
JSch.setConfig("StrictHostKeyChecking", option);
if (option.equals("no")) {
logger.warn("WARNING: host key check is disabled!");
}
}
if (connector != null) {
IdentityRepository remoteIdentityRepository = new RemoteIdentityRepository(connector);
shellClient.setIdentityRepository(remoteIdentityRepository);
}
for (Target target : environment.targets()) {
sessions.add(new RemoteTarget(connect(shellClient, target, context, config), target, context, environment));
}
} catch (AgentProxyException | FileNotFoundException | JSchException e) {
throw new RemoteClientException(e.getMessage());
}
}
示例4: attemptAgentUse
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; //导入依赖的package包/类
/**
* Attempts to connect to a local SSH agent (using either UNIX sockets or PuTTY's Pageant)
*
* @param jsch
* Connection to be attached to an available local agent
* @return true if connected to agent, false otherwise
*/
private boolean attemptAgentUse(JSch jsch) {
try {
Connector con = ConnectorFactory.getDefault().createConnector();
jsch.setIdentityRepository(new RemoteIdentityRepository(con));
return true;
} catch (Exception e) {
Message.verbose(":: SSH :: Failure connecting to agent :: " + e.toString());
return false;
}
}
示例5: create
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository; //导入依赖的package包/类
@Override
public Session create() throws Exception
{
if (connected_.compareAndSet(false, true))
{
JSch jsch = new JSch();
session_ = jsch.getSession(loginCredentials_.getUser(), hostAndPort_.getHost(), hostAndPort_.getPortOrDefault(22));
if (sessionTimeout_ != 0)
{
session_.setTimeout(sessionTimeout_);
}
if (loginCredentials_.getPrivateKey() == null)
{
session_.setPassword(loginCredentials_.getPassword());
}
else if (loginCredentials_.hasUnencryptedPrivateKey())
{
jsch.addIdentity(loginCredentials_.getPrivateKey());
// jsch.addIdentity(loginCredentials_.getUser(), loginCredentials_.getPrivateKey().getBytes(), null, new byte[0]);
}
else if (agentConnector_.isPresent())
{
JSch.setConfig("PreferredAuthentications", "publickey");
jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector_.get()));
}
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session_.setConfig(config);
if (proxy_.isPresent())
{
session_.setProxy(proxy_.get());
}
session_.connect(connectTimeout_);
LOGGER.info("ssh session started on {}", hostAndPort_);
}
return session_;
}