当前位置: 首页>>代码示例>>Java>>正文


Java Connection.authenticateWithPublicKey方法代码示例

本文整理汇总了Java中com.trilead.ssh2.Connection.authenticateWithPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.authenticateWithPublicKey方法的具体用法?Java Connection.authenticateWithPublicKey怎么用?Java Connection.authenticateWithPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.trilead.ssh2.Connection的用法示例。


在下文中一共展示了Connection.authenticateWithPublicKey方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticateSshSessionWithPublicKey

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
/**
 * This method will create and authenticate a session using a public key method. The
 * certificate that will be used is the Autonomiccs default certificated that is installed by
 * default in the Autonomiccs system VM template
 */
protected Session authenticateSshSessionWithPublicKey(Connection sshConnection) throws IOException {
    sshConnection.connect(null, CONNECT_TIMEOUT, CONNECT_TIMEOUT);
    if (!sshConnection.authenticateWithPublicKey("root", certificate, null)) {
        throw new CloudRuntimeException(String.format("Unable to authenticate to (%s)", sshConnection.getHostname()));
    }
    return sshConnection.openSession();
}
 
开发者ID:Autonomiccs,项目名称:autonomiccs-platform,代码行数:13,代码来源:SshUtils.java

示例2: authenticate

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static boolean authenticate( Connection connection, AuthenticationData auth ) throws IOException
{
	boolean isAuthenticated = false;
	if (auth.getMode().equals(AuthenticationData.Mode.KEY))
	{
		Logger.info("Authenticating with key file: '" + auth.getKeyFile() + "'", Level.COMM, Authenticator.class);
		File rsa = new File(auth.getKeyFile());
		if (rsa.exists() && rsa.canRead())
		{
			isAuthenticated = connection.authenticateWithPublicKey(auth.getUsername(), rsa , "");
		}
		else
		{
			Logger.warning("Cannot read RSA/DSA key: '" + auth.getKeyFile() + "'", Level.COMM, Authenticator.class);
		}
		if (!isAuthenticated && auth.getPassword()!=null)
		{
			Logger.warning("Falling back to password authentication", Level.COMM, Authenticator.class);
			isAuthenticated = connection.authenticateWithPassword( auth.getUsername(), auth.getPassword() );
		}
	}
	else
	{
		Logger.warning("Authenticating with password", Level.COMM, Authenticator.class);
		isAuthenticated = connection.authenticateWithPassword( auth.getUsername(), auth.getPassword() );
	}
	
	if (isAuthenticated == false) throw new IOException("Authentication failed.");
	return isAuthenticated;
}
 
开发者ID:Spacecraft-Code,项目名称:SPELL,代码行数:31,代码来源:Authenticator.java

示例3: bootstrap

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private int bootstrap(Connection bootstrapConn, EC2Computer computer, PrintStream logger) throws IOException, InterruptedException, AmazonClientException {
    logger.println("bootstrap()" );
    boolean closeBootstrap = true;
    try {
        int tries = 20;
        boolean isAuthenticated = false;
        logger.println("Getting keypair..." );
        KeyPair key = computer.getCloud().getKeyPair();
        logger.println("Using key: " + key.getKeyName() + "\n" + key.getKeyFingerprint() + "\n" + key.getKeyMaterial().substring(0, 160) );
        while (tries-- > 0) {
            logger.println("Authenticating as " + computer.getRemoteAdmin());
            isAuthenticated = bootstrapConn.authenticateWithPublicKey(computer.getRemoteAdmin(), key.getKeyMaterial().toCharArray(), "");
            if (isAuthenticated) {
                break;
            }
            logger.println("Authentication failed. Trying again...");
            Thread.sleep(10000);
        }
        if (!isAuthenticated) {
            logger.println("Authentication failed");
            return FAILED;
        }
        closeBootstrap = false;
        return SAMEUSER;
    } finally {
        if (closeBootstrap)
            bootstrapConn.close();
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:30,代码来源:EC2UnixLauncher.java

示例4: connect

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static Connection connect(HostAndPort host, StandardUsernameCredentials credentials) throws IOException {
    Connection connection = new Connection(host.getHostText(), host.getPortOrDefault(22));
    connection.setTCPNoDelay(true);
    connection.connect();

    try {
        if (credentials instanceof StandardUsernamePasswordCredentials) {
            StandardUsernamePasswordCredentials passwordCredentials = (StandardUsernamePasswordCredentials) credentials;
            connection.authenticateWithPassword(passwordCredentials.getUsername(), Secret.toString(passwordCredentials.getPassword()));
        } else if (credentials instanceof SSHUserPrivateKey) {
            SSHUserPrivateKey sshCredentials = (SSHUserPrivateKey) credentials;
            checkState(sshCredentials.getPrivateKeys().size() > 0, "no private keys defined");

            String username = credentials.getUsername();
            String password = Secret.toString(sshCredentials.getPassphrase());

            for (String privateKey : sshCredentials.getPrivateKeys()) {
                if (connection.authenticateWithPublicKey(username, privateKey.toCharArray(), password)) {
                    break;
                }
            }
        } else {
            connection.authenticateWithNone(credentials.getUsername());
        }

        checkState(connection.isAuthenticationComplete(), "Authentication failed");
    } catch (Throwable ex) {
        connection.close();
        throw Throwables.propagate(ex);
    }

    return connection;
}
 
开发者ID:dump247,项目名称:jenkins-docker-build-plugin,代码行数:34,代码来源:Ssh.java

示例5: bootstrap

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private int bootstrap(Connection bootstrapConn, Computer computer, PrintStream logger) throws IOException, InterruptedException {
    logger.println("bootstrap()" );
    boolean closeBootstrap = true;

    if (bootstrapConn.isAuthenticationComplete()) {
        return SAMEUSER;
    }

    try {
        int tries = 20;
        boolean isAuthenticated = false;

        while (tries-- > 0) {
            logger.println("Authenticating as " + computer.getRemoteAdmin());

            isAuthenticated = bootstrapConn.authenticateWithPublicKey(computer.getRemoteAdmin(), computer.getNode().getPrivateKey().toCharArray(), "");
            if (isAuthenticated) {
                break;
            }
            logger.println("Authentication failed. Trying again...");
            Thread.sleep(10000);
        }
        if (!isAuthenticated) {
            logger.println("Authentication failed");
            return FAILED;
        }
        closeBootstrap = false;
        return SAMEUSER;
    } catch (Exception e) {
        e.printStackTrace(logger);
        return FAILED;
    } finally {
        if (closeBootstrap)
            bootstrapConn.close();
    }
}
 
开发者ID:pulse00,项目名称:digitalocean-plugin,代码行数:37,代码来源:ComputerLauncher.java

示例6: SSHConnect

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(LogWriter log,String realservername, String realserverpassword, int realserverport,
		String realUsername, String realPassword,
		String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
		String realkeyFilename, String realkeyPass) throws Exception
{
	
	/* Create a connection instance */

	Connection conn = new Connection(realservername,realserverport);

	/* We want to connect through a HTTP proxy */
	if(useproxy)
	{
		conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
		{
			conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
		}
	}
	
	
	if(timeout>0)
	{
		// Use timeout
		conn.connect(null,0,timeout*1000);	
		
	}else
	{
		// Cache Host Key
		conn.connect();
	}
	
	// Authenticate

	boolean isAuthenticated = false;
	if(publicpublickey)
	{
		isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(keyFilename), realkeyPass);
	}else
	{
		isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
	}

	if(!isAuthenticated) throw new Exception("Can not connect to ");
	
	sshclient = new SFTPv3Client(conn);
	
	
	
	
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:55,代码来源:JobEntryFTPDelete.java

示例7: SSHConnect

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(String realservername, String realserverpassword, int realserverport,
		String realUsername, String realPassword,
		String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
		String realkeyFilename, String realkeyPass) throws Exception
{
	
	/* Create a connection instance */

	Connection conn = new Connection(realservername,realserverport);

	/* We want to connect through a HTTP proxy */
	if(useproxy)
	{
		conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
		{
			conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
		}
	}
	
	
	if(timeout>0)
	{
		// Use timeout
		conn.connect(null,0,timeout*1000);	
		
	}else
	{
		// Cache Host Key
		conn.connect();
	}
	
	// Authenticate

	boolean isAuthenticated = false;
	if(publicpublickey)
	{
		isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(keyFilename), realkeyPass);
	}else
	{
		isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
	}

	if(!isAuthenticated) throw new Exception("Can not connect to ");
	
	sshclient = new SFTPv3Client(conn);
	
	
	
	
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:55,代码来源:JobEntryFTPDelete.java

示例8: SSHConnect

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(String realservername, String realserverpassword, int realserverport,
		String realUsername, String realPassword,
		String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
		String realkeyFilename, String realkeyPass) throws Exception
{
	
	/* Create a connection instance */

	Connection conn = new Connection(realservername,realserverport);

	/* We want to connect through a HTTP proxy */
	if(useproxy)
	{
		conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
		{
			conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
		}
	}
	
	
	if(timeout>0)
	{
		// Use timeout
		conn.connect(null,0,timeout*1000);	
		
	}else
	{
		// Cache Host Key
		conn.connect();
	}
	
	// Authenticate

	boolean isAuthenticated = false;
	if(publicpublickey)
	{
		isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(realkeyFilename), realkeyPass);
	}else
	{
		isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
	}

	if(!isAuthenticated) throw new Exception("Can not connect to ");
	
	sshclient = new SFTPv3Client(conn);
	
	
	
	
}
 
开发者ID:bsspirit,项目名称:kettle-4.4.0-stable,代码行数:55,代码来源:JobEntryFTPDelete.java

示例9: SSHConnect

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect( String realservername, String realserverpassword, int realserverport,
  String realUsername, String realPassword, String realproxyhost, String realproxyusername,
  String realproxypassword, int realproxyport, String realkeyFilename, String realkeyPass ) throws Exception {

  /* Create a connection instance */

  Connection conn = new Connection( realservername, realserverport );

  /* We want to connect through a HTTP proxy */
  if ( useproxy ) {
    conn.setProxyData( new HTTPProxyData( realproxyhost, realproxyport ) );

    /* Now connect */
    // if the proxy requires basic authentication:
    if ( !Utils.isEmpty( realproxyusername ) || !Utils.isEmpty( realproxypassword ) ) {
      conn
        .setProxyData( new HTTPProxyData( realproxyhost, realproxyport, realproxyusername, realproxypassword ) );
    }
  }

  if ( timeout > 0 ) {
    // Use timeout
    conn.connect( null, 0, timeout * 1000 );

  } else {
    // Cache Host Key
    conn.connect();
  }

  // Authenticate

  boolean isAuthenticated = false;
  if ( publicpublickey ) {
    isAuthenticated = conn.authenticateWithPublicKey( realUsername, new File( realkeyFilename ), realkeyPass );
  } else {
    isAuthenticated = conn.authenticateWithPassword( realUsername, realserverpassword );
  }

  if ( !isAuthenticated ) {
    throw new Exception( "Can not connect to " );
  }

  sshclient = new SFTPv3Client( conn );

}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:46,代码来源:JobEntryFTPDelete.java

示例10: OpenConnection

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static Connection OpenConnection( String serveur, int port, String username, String password,
    boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost,
    int proxyport, String proxyusername, String proxypassword ) throws KettleException {
  Connection conn = null;
  char[] content = null;
  boolean isAuthenticated = false;
  try {
    // perform some checks
    if ( useKey ) {
      if ( Utils.isEmpty( keyFilename ) ) {
        throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) );
      }
      FileObject keyFileObject = KettleVFS.getFileObject( keyFilename );

      if ( !keyFileObject.exists() ) {
        throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) );
      }

      FileContent keyFileContent = keyFileObject.getContent();

      CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() );

      try ( InputStream in = keyFileContent.getInputStream() ) {
        IOUtils.copy( in, charArrayWriter );
      }

      content = charArrayWriter.toCharArray();
    }
    // Create a new connection
    conn = createConnection( serveur, port );

    /* We want to connect through a HTTP proxy */
    if ( !Utils.isEmpty( proxyhost ) ) {
      /* Now connect */
      // if the proxy requires basic authentication:
      if ( !Utils.isEmpty( proxyusername ) ) {
        conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) );
      } else {
        conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) );
      }
    }

    // and connect
    if ( timeOut == 0 ) {
      conn.connect();
    } else {
      conn.connect( null, 0, timeOut * 1000 );
    }
    // authenticate
    if ( useKey ) {
      isAuthenticated =
        conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) );
    } else {
      isAuthenticated = conn.authenticateWithPassword( username, password );
    }
    if ( isAuthenticated == false ) {
      throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) );
    }
  } catch ( Exception e ) {
    // Something wrong happened
    // do not forget to disconnect if connected
    if ( conn != null ) {
      conn.close();
    }
    throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e );
  }
  return conn;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:69,代码来源:SSHData.java

示例11: main

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static void main(String[] args)
{
	String hostname = "127.0.0.1";
	String username = "joe";

	File keyfile = new File("~/.ssh/id_rsa"); // or "~/.ssh/id_dsa"
	String keyfilePass = "joespass"; // will be ignored if not needed

	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect */

		conn.connect();

		/* Authenticate */

		boolean isAuthenticated = conn.authenticateWithPublicKey(username, keyfile, keyfilePass);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		InputStream stdout = new StreamGobbler(sess.getStdout());

		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		System.out.println("Here is some information about the remote host:");

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Close this session */

		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:61,代码来源:PublicKeyAuthentication.java


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