• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConfigRepository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: open

import com.jcraft.jsch.ConfigRepository; //导入依赖的package包/类
public void open() throws JSchException {
	JSch jsch = new JSch();
	String conf = (String)Configure.getConfigure().getString("SshConfPath");
	if (new File(conf).exists()) {
		try {
			ConfigRepository configRepository = OpenSSHConfig.parseFile(conf);
			jsch.setConfigRepository(configRepository);
		}catch(IOException ignore) {
			
		}
	}
	session = jsch.getSession(this.username, this.host, this.port);
	session.setConfig("StrictHostKeyChecking", "no");
	session.setPassword(this.password);
	session.setTimeout(timeout);
	session.connect();
	channelSftp = (ChannelSftp) session.openChannel("sftp");
	channelSftp.connect();
}
 
开发者ID:int32bit,项目名称:openstack-java-sdk,代码行数:20,代码来源:RemoteExecutor.java


示例2: SshConfiguration

import com.jcraft.jsch.ConfigRepository; //导入依赖的package包/类
public SshConfiguration(ConfigRepository configRepository) throws JSchException {
	JSchHelper.configureGlobalSettings();

	this.configRepository = configRepository;
	jsch.setConfigRepository(this.configRepository);

	Assert.isTrue(Files.isRegularFile(getLocalSshKnownHostsPath()), getLocalSshKnownHostsPath() + " does not exist");
	jsch.setKnownHosts(getLocalSshKnownHostsPath().toString());
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:10,代码来源:SshConfiguration.java


示例3: createTunnelJSch

import com.jcraft.jsch.ConfigRepository; //导入依赖的package包/类
private static void createTunnelJSch(String gatewayHost, String remoteHost,
                                     int remotePort, int localPort) throws Exception {
  JSch.setLogger(new MyJSchLogger());
  JSch jsch=new JSch();

  try {
    // NOTE: jsch does not support all ciphers.  User may be
    //       prompted to accept host key authenticy even if
    //       the key is in the known_hosts file.
    File knownHosts = new File(FileUtils.getHomeDir()+".ssh/known_hosts");
    if (knownHosts.exists() && knownHosts.canRead())
	    jsch.setKnownHosts(knownHosts.getAbsolutePath());
    ArrayList<File> privateKeys = new ArrayList<File>();
    if (!getSshKey().isEmpty()) {
      byte[] keyPass = null, key;
      if (!sshKeyPass.getValue().isEmpty())
        keyPass = sshKeyPass.getValue().getBytes();
      jsch.addIdentity("TigerVNC", getSshKey().getBytes(), null, keyPass);
    } else if (!getSshKeyFile().isEmpty()) {
      File f = new File(getSshKeyFile());
      if (!f.exists() || !f.canRead())
        throw new Exception("Cannot access SSH key file "+getSshKeyFile());
      privateKeys.add(f);
    }
    for (Iterator<File> i = privateKeys.iterator(); i.hasNext();) {
      File privateKey = (File)i.next();
      if (privateKey.exists() && privateKey.canRead())
        if (!sshKeyPass.getValue().isEmpty())
	        jsch.addIdentity(privateKey.getAbsolutePath(),
                           sshKeyPass.getValue());
        else
	        jsch.addIdentity(privateKey.getAbsolutePath());
    }

    String user = getSshUser();
    String label = new String("SSH Authentication");
    PasswdDialog dlg =
      new PasswdDialog(label, (user == null ? false : true), false);
    dlg.userEntry.setText(user != null ? user : "");
    File ssh_config = new File(sshConfig.getValue());
    if (ssh_config.exists() && ssh_config.canRead()) {
      ConfigRepository repo =
        OpenSSHConfig.parse(ssh_config.getAbsolutePath());
      jsch.setConfigRepository(repo);
    }
    Session session=jsch.getSession(user, gatewayHost, getSshPort());
    session.setUserInfo(dlg);
    // OpenSSHConfig doesn't recognize StrictHostKeyChecking
    if (session.getConfig("StrictHostKeyChecking") == null)
      session.setConfig("StrictHostKeyChecking", "ask");
    session.connect();
    session.setPortForwardingL(localPort, remoteHost, remotePort);
  } catch (java.lang.Exception e) {
    throw new Exception(e.getMessage()); 
  }
}
 
开发者ID:TigerVNC,项目名称:tigervnc,代码行数:57,代码来源:Tunnel.java


示例4: getSession

import com.jcraft.jsch.ConfigRepository; //导入依赖的package包/类
/**
 * get a new session using the default attributes if the given String is a full uri, use the
 * data from the uri instead
 *
 * @param pathOrUri
 *            might be just a path or a full ssh or sftp uri
 * @return matching Session
 * @throws IOException if something goes wrong
 */
protected Session getSession(String pathOrUri) throws IOException {
    URI uri = parseURI(pathOrUri);
    String host = getHost();
    int port = getPort();
    String user = getUser();
    String userPassword = getUserPassword();
    String sshConfig = getSshConfig();
    File keyFile = getKeyFile();
    if (uri != null && uri.getScheme() != null) {
        if (uri.getHost() != null) {
            host = uri.getHost();
        }
        if (uri.getPort() != -1) {
            port = uri.getPort();
        }
        if (uri.getUserInfo() != null) {
            String userInfo = uri.getUserInfo();
            if (!userInfo.contains(":")) {
                user = userInfo;
            } else {
                user = userInfo.substring(0, userInfo.indexOf(":"));
                userPassword = userInfo.substring(userInfo.indexOf(":") + 1);
            }
        }
    }

    if (sshConfig != null) {
        ConfigRepository configRepository = OpenSSHConfig.parseFile(sshConfig);
        Config config = configRepository.getConfig(host);
        host = config.getHostname();
        if (user == null) {
            user = config.getUser();
        }
        String keyFilePath = config.getValue("IdentityFile");
        if (keyFilePath != null && keyFile == null) {
            keyFile = new File(keyFilePath);
        }
    }

    if (host == null) {
        throw new IllegalArgumentException(
                "missing host information. host should be provided either "
                        + "directly on the repository or in the connection URI "
                        + ", or in the openssh config file specified by sshConfig");
    }
    if (user == null) {
        Credentials c = requestCredentials(host);
        if (c != null) {
            user = c.getUserName();
            userPassword = c.getPasswd();
        } else {
            Message.error("username is not set");
        }
    }
    return SshCache.getInstance().getSession(host, port, user, userPassword, keyFile,
        getKeyFilePassword(), getPassFile(), isAllowedAgentUse());
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:67,代码来源:AbstractSshBasedRepository.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XulTreeItem类代码示例发布时间:2022-05-22
下一篇:
Java ReturnStmt类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap