Java Code Examples for com.jcraft.jsch.JSch#setIdentityRepository()
The following examples show how to use
com.jcraft.jsch.JSch#setIdentityRepository() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSchExecutor.java From vividus with Apache License 2.0 | 11 votes |
private JSch createJSchInstance(ServerConfiguration server) throws AgentProxyException, JSchException { JSch jSch = new JSch(); if (server.isAgentForwarding()) { Connector connector = ConnectorFactory.getDefault().createConnector(); jSch.setIdentityRepository(new RemoteIdentityRepository(connector)); } else if (server.getPrivateKey() != null && server.getPublicKey() != null) { String passphrase = server.getPassphrase(); jSch.addIdentity("default", getBytes(server.getPrivateKey()), getBytes(server.getPublicKey()), passphrase != null ? getBytes(passphrase) : null); } return jSch; }
Example 2
Source File: SftpClient.java From netbeans with Apache License 2.0 | 6 votes |
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); if (irepo.getStatus() == IdentityRepository.RUNNING) { 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; }
Example 3
Source File: JGitSshSessionFactory.java From netbeans with Apache License 2.0 | 6 votes |
private boolean setupJSchIdentityRepository (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); if (irepo.getStatus() == IdentityRepository.RUNNING) { jsch.setIdentityRepository(irepo); agentUsed = true; } } } if (!agentUsed) { jsch.setIdentityRepository(null); // remove all identity files jsch.removeAllIdentity(); // and add the one specified by CredentialsProvider jsch.addIdentity(identityFile); } return agentUsed; }
Example 4
Source File: SshCache.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * 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; } }