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

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

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

JSch.setIdentityRepository介绍

[英]Sets the identityRepository, which will be referred in the public key authentication.
[中]设置将在公钥身份验证中引用的identityRepository

代码示例

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

/**
 * Sets the {@link IdentityRepository} for this factory. This will replace
 * any current IdentityRepository, so you should be sure to call this before
 * any of the <code>setIdentit(y|ies)Xxx</code> if you plan on using both.
 * 
 * @param identityRepository
 *            The identity repository
 * 
 * @see JSch#setIdentityRepository(IdentityRepository)
 */
public void setIdentityRepository( IdentityRepository identityRepository ) {
  jsch.setIdentityRepository( identityRepository );
}

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

/**
 * Sets the {@link IdentityRepository} for this factory. This will replace
 * any current IdentityRepository, so you should be sure to call this before
 * any of the <code>setIdentit(y|ies)Xxx</code> if you plan on using both.
 * 
 * @param identityRepository
 *            The identity repository
 * 
 * @see JSch#setIdentityRepository(IdentityRepository)
 */
public void setIdentityRepository( IdentityRepository identityRepository ) {
  jsch.setIdentityRepository( identityRepository );
}

代码示例来源: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: org.eclipse.platform/org.eclipse.jsch.core

public synchronized void setIdentityRepository(){
 IdentityRepository[] repositories = getPluggedInIdentityRepositries();
 String[] selected = Utils.getSelectedSSHAgent().split(","); //$NON-NLS-1$
 IdentityRepository irepo = null;
 for(int i=0; i<selected.length; i++){
  for(int j=0; j<repositories.length; j++){
   IdentityRepository _irepo = repositories[j];
   if(selected[i].equals(_irepo.getName()) &&
     _irepo.getStatus()==IdentityRepository.RUNNING){
    irepo = _irepo;
    break;
   }
  }
  if(irepo!=null)
   break;
 }
 if(irepo!=null){
  jsch.setIdentityRepository(irepo);
 }
 else{
  // set the internal default IdentityRepository
  jsch.setIdentityRepository(null);
 }
}

代码示例来源:origin: com.dell.cpsd.component/component-common-core

private boolean doAgentAuth(Session session) throws AgentProxyException, JSchException
{
  ConnectorFactory cf = ConnectorFactory.getDefault();
  Connector connector = cf.createConnector();
  if (connector != null)
  {
    session.setConfig("PreferredAuthentications", "publickey");
    IdentityRepository repo = new RemoteIdentityRepository(connector);
    jsch.setIdentityRepository(repo);
    session.connect(timeout);
    return session.isConnected();
  }
  return false;
}

代码示例来源:origin: org.apache.ivy/ivy

/**
 * 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;
  }
}

代码示例来源:origin: com.amysta.jclouds.driver/jclouds-jsch

@Override
public Session create() throws Exception {
 JSch jsch = new JSch();
 session = jsch
    .getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
 if (sessionTimeout != 0)
   session.setTimeout(sessionTimeout);
 if (loginCredentials.hasUnencryptedPrivateKey()) {
   byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes();
   jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
 } else if (loginCredentials.getOptionalPassword().isPresent()) {
   session.setPassword(loginCredentials.getOptionalPassword().orNull());
 } else if (agentConnector.isPresent()) {
   JSch.setConfig("PreferredAuthentications", "publickey");
   jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));
 }
 java.util.Properties config = new java.util.Properties();
 config.put("StrictHostKeyChecking", "no");
 session.setConfig(config);
 if (proxy.isPresent())
   session.setProxy(proxy.get());
 session.connect(connectTimeout);
 return session;
}

代码示例来源: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;
}

代码示例来源:origin: apache/jclouds

@Override
public Session create() throws Exception {
 JSch jsch = new JSch();
 session = jsch
    .getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
 if (sessionTimeout != 0)
   session.setTimeout(sessionTimeout);
 if (loginCredentials.hasUnencryptedPrivateKey()) {
   byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes();
   jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
 } else if (loginCredentials.getOptionalPassword().isPresent()) {
   session.setPassword(loginCredentials.getOptionalPassword().orNull());
 } else if (agentConnector.isPresent()) {
   JSch.setConfig("PreferredAuthentications", "publickey");
   jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));
 }
 java.util.Properties config = new java.util.Properties();
 config.put("StrictHostKeyChecking", "no");
 session.setConfig(config);
 if (proxy.isPresent())
   session.setProxy(proxy.get());
 session.connect(connectTimeout);
 return session;
}

代码示例来源:origin: danielflower/multi-module-maven-release-plugin

jsch.setIdentityRepository(identityRepository);

代码示例来源:origin: br.com.objectos/way-secshell

@Override
public WaySSH connect() {
 try {
  JSch sch = new JSch();
  ConnectorFactory cf = ConnectorFactory.getDefault();
  Connector con = cf.createConnector();
  IdentityRepository irepo = new RemoteIdentityRepository(con);
  sch.setIdentityRepository(irepo);
  String knownHosts = knownHosts();
  sch.setKnownHosts(knownHosts);
  Session session = sch.getSession(user, host, port);
  session.connect();
  return WaySSH.success(session);
 } catch (JSchException e) {
  return WaySSH.failed(e);
 } catch (AgentProxyException e) {
  return WaySSH.failed(e);
 }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

@Override
  protected JSch createDefaultJSch(FS fs) throws JSchException {
    Connector connector = null;
    try {
      if (SSHAgentConnector.isConnectorAvailable()) {
        USocketFactory usf = new JNAUSocketFactory();
        connector = new SSHAgentConnector(usf);
      }
      log.info("Successfully connected to an agent");
    }
    catch (AgentProxyException e) {
      log.error(
          "Exception occurred while trying to connect to agent. Will create"
              + "the default JSch connection",
          e);
      return super.createDefaultJSch(fs);
    }
    final JSch jsch = super.createDefaultJSch(fs);
    if (connector != null) {
      JSch.setConfig("PreferredAuthentications", "publickey,password");
      IdentityRepository identityRepository = new RemoteIdentityRepository(
          connector);
      jsch.setIdentityRepository(identityRepository);
    }
    return jsch;
  }
};

代码示例来源:origin: com.atlassian.maven.plugins/maven-jgitflow-plugin

jsch.setConfig("PreferredAuthentications", "publickey");
IdentityRepository irepo = new RemoteIdentityRepository(con);
jsch.setIdentityRepository(irepo);

代码示例来源:origin: org.xbib/jsch-core

synchronized (this) {
  if (!(identityRepository instanceof IdentityRepository.Wrapper)) {
    setIdentityRepository(new IdentityRepository.Wrapper(identityRepository));

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jsch

synchronized(this){
 if(!(identityRepository instanceof IdentityRepository.Wrapper)){
  setIdentityRepository(new IdentityRepository.Wrapper(identityRepository));

代码示例来源:origin: org.mule.jsch/jsch

synchronized(this){
 if(!(identityRepository instanceof IdentityRepository.Wrapper)){
  setIdentityRepository(new IdentityRepository.Wrapper(identityRepository));

代码示例来源:origin: ePaul/jsch-documentation

synchronized(this){
 if(!(identityRepository instanceof IdentityRepository.Wrapper)){
  setIdentityRepository(new IdentityRepository.Wrapper(identityRepository));

代码示例来源:origin: omegat-org/omegat

@Override
  protected JSch createDefaultJSch(FS fs) throws JSchException {
    Connector con = null;
    try {
      if (SSHAgentConnector.isConnectorAvailable()) {
        USocketFactory usf = new JNAUSocketFactory();
        con = new SSHAgentConnector(usf);
      } else {
        ConnectorFactory cf = ConnectorFactory.getDefault();
        con = cf.createConnector();
      }
    } catch (AgentProxyException e) {
      Log.log(e);
    }
    JSch jsch = super.createDefaultJSch(fs);
    if (con != null) {
      JSch.setConfig("PreferredAuthentications", "publickey");
      IdentityRepository irepo = new RemoteIdentityRepository(con);
      jsch.setIdentityRepository(irepo);
    }
    return jsch;
  }
};

代码示例来源:origin: com.github.robtimus/sftp-fs

void initialize(JSch jsch) throws IOException {
  if (containsKey(IDENTITY_REPOSITORY)) {
    IdentityRepository identityRepository = FileSystemProviderSupport.getValue(this, IDENTITY_REPOSITORY, IdentityRepository.class, null);
    jsch.setIdentityRepository(identityRepository);

相关文章