com.jcraft.jsch.JSch.removeAllIdentity()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.jcraft.jsch.JSch.removeAllIdentity()方法的一些代码示例,展示了JSch.removeAllIdentity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSch.removeAllIdentity()方法的具体详情如下:
包路径:com.jcraft.jsch.JSch
类名称:JSch
方法名:removeAllIdentity

JSch.removeAllIdentity介绍

[英]Removes all identities. Public key authentication will not work anymore until another identity is added.
[中]删除所有标识。在添加另一个标识之前,公钥身份验证将不再有效。

代码示例

代码示例来源:origin: FlowCI/flow-platform

@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;
  }
};

代码示例来源:origin: stackoverflow.com

class CustomConfigSessionFactory extends JschConfigSessionFactory
{
  @Override
  protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
    JSch jsch = super.getJSch(hc, fs);
    jsch.removeAllIdentity();
    jsch.addIdentity( "/path/to/private/key" );
    return jsch;
  }
}

代码示例来源:origin: com.pastdev/jsch-extension

private void clearIdentityRepository() throws JSchException {
  jsch.setIdentityRepository( null ); // revert to default identity repo
  jsch.removeAllIdentity();
}

代码示例来源:origin: lucastheisen/jsch-extension

private void clearIdentityRepository() throws JSchException {
  jsch.setIdentityRepository( null ); // revert to default identity repo
  jsch.removeAllIdentity();
}

代码示例来源:origin: stackoverflow.com

SshSessionFactory factory = new JschConfigSessionFactory() {
   public void configure(Host hc, Session session) {
     session.setConfig("StrictHostKeyChecking", "no");
   }
   @Override
   protected JSch
           getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
     JSch jsch = super.getJSch(hc, fs);
     jsch.removeAllIdentity();
     //Where getSshKey returns content of the private key file
     if (StringUtils.isNotEmpty(data.getSshKey())) {
       jsch.addIdentity("identityName", data.getSshKey()
         .getBytes(), null, data.getSshPassphrase()
         .getBytes());
     }
     return jsch;
   }
 };

代码示例来源:origin: stackoverflow.com

jsch.removeAllIdentity();
session = jsch.getSession(user, host, port);
session.setPassword(password);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private boolean setAgent(JSch jsch, String identityFile, boolean preferAgent) throws JSchException {
  boolean agentUsed = false;
  if (preferAgent) {
    Connector con = ConnectorFactory.getInstance().createConnector(ConnectorFactory.ConnectorKind.ANY);
    if (con != null) {
      IdentityRepository irepo = new IdentityRepositoryImpl(con);
      jsch.setIdentityRepository(irepo);
      agentUsed = true;
    }
  }
  if (!agentUsed) {
    jsch.setIdentityRepository(null);
    // remove all identity files
    jsch.removeAllIdentity();
    // and add the one specified by CredentialsProvider
    if (StringUtils.hasText(identityFile)) {
      jsch.addIdentity(identityFile);
    }
  }
  return agentUsed;
}

相关文章