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


Java Connection.authenticateWithPassword方法代码示例

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


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

示例1: testRecRemoteOperatorAuthInfoString

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
@Test
public final void testRecRemoteOperatorAuthInfoString() throws IOException, RemoteException {
	String midwarePath = "/root/nginx/";
	AuthInfo authInfo= new RecAuthInfo();
	authInfo.setHost("10.1.50.4");
	authInfo.setUsername("root");
	authInfo.setPassword("cs2csolutions");


	Connection conn = new Connection("10.1.50.4");
	/* Now connect */
	conn.connect();
	boolean isAuthenticated = conn.authenticateWithPassword(
			"root", "cs2csolutions");
	if (isAuthenticated == false)
		throw new RemoteException("Authentication failed.");
	
	RecRemoteOperator rro1 = new RecRemoteOperator(authInfo,midwarePath,conn);

	assertTrue(null != rro1);
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:22,代码来源:RecRemoteOperatorTest.java

示例2: setUpBeforeClass

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	/* Create a connection instance */
	conn = new Connection("10.1.50.4", 22);
	
	/* Connect */
	conn.connect();

	/* Authenticate. */
	boolean isAuthenticated = 
	conn.authenticateWithPassword("root", "cs2csolutions");
	if (isAuthenticated == false)
		throw new IOException("Authentication failed.");
	logger=new RecLogger(conn, "/usr/local/nginx");
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:19,代码来源:LoggerTest.java

示例3: authenticate

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public void authenticate(final Connection connection) throws AuthenticationException, SolveableAuthenticationException {
  final String password = myPasswordProvider.getPasswordForCvsRoot(myCvsRootAsString);
  if (password == null) {
    throw new SolveableAuthenticationException("Authentication rejected.");
  }
  try {
    final String[] methodsArr = connection.getRemainingAuthMethods(myLogin);
    if ((methodsArr == null) || (methodsArr.length == 0)) return;
    final List<String> methods = Arrays.asList(methodsArr);

    if (methods.contains(PASSWORD_METHOD)) {
      if (connection.authenticateWithPassword(myLogin, password)) return;
    }

    if (methods.contains(KEYBOARD_METHOD)) {
      final boolean wasAuthenticated = connection.authenticateWithKeyboardInteractive(myLogin, new InteractiveCallback() {
        public String[] replyToChallenge(String s, String instruction, int numPrompts, String[] strings, boolean[] booleans) throws Exception {
          final String[] result = new String[numPrompts];
          if (numPrompts > 0) {
            Arrays.fill(result, password);
          }
          return result;
        }
      });
      if (wasAuthenticated) return;       
    }

    throw new SolveableAuthenticationException("Authentication rejected.");
  }
  catch (IOException e) {
    throw new SolveableAuthenticationException(e.getMessage(), e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:SshPasswordAuthentication.java

示例4: getConnection

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public Connection getConnection() throws IOException {
	Connection conn = new Connection(this.getIp(), this.getPort());
	conn.connect();
	boolean isAuthenticated = conn.authenticateWithPassword(
			this.getUsername(), this.getPassword());
	if (!isAuthenticated) {
		throw new IOException("Authentication failed.");
	}
	LOG.info("create ssh session success with ip=[" + getIp()
			 + "],port=[" + getPort() + "],username=[" + getUsername()
			 + "],password=[*******]");
	return conn;
}
 
开发者ID:jenkinsci,项目名称:ssh2easy-plugin,代码行数:14,代码来源:JenkinsSshClient.java

示例5: 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

示例6: 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

示例7: creatConnection

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public void creatConnection() throws RemoteException {
	/* Create a connection instance */
	conn = new Connection(authInfo.getHostname());
	/* Now connect */
	try {
		conn.connect();
	    conn.authenticateWithPassword(
				authInfo.getUsername(), authInfo.getPassword());
	} catch (IOException e) {
		// TODO Auto-generated catch block
		
		throw new RemoteException(e);
	}
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:15,代码来源:RecMiddlewareFactory.java

示例8: establishConnection

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static void establishConnection() throws IOException {
	/* Create a connection instance */
	conn = new Connection(hostname, port);
	
	/* Connect */
	conn.connect();

	/* Authenticate. */
	boolean isAuthenticated = 
	conn.authenticateWithPassword(username, password);
	if (isAuthenticated == false)
		throw new IOException("Authentication failed.");
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:14,代码来源:MonitorTest.java

示例9: main

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

	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect */

		conn.connect();

		/* Authenticate.
		 * If you get an IOException saying something like
		 * "Authentication method password not supported by the server at this stage."
		 * then please check the FAQ.
		 */

		boolean isAuthenticated = conn.authenticateWithPassword(username, password);

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

		/* Create a session */

		Session sess = conn.openSession();

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

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

		/* 
		 * This basic example does not handle stderr, which is sometimes dangerous
		 * (please read the FAQ).
		 */

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

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

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

		/* Show exit status, if available (otherwise "null") */

		System.out.println("ExitCode: " + sess.getExitStatus());

		/* 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,代码行数:72,代码来源:Basic.java

示例10: main

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

	String proxyHost = "192.168.1.1";
	int proxyPort = 3128; // default port used by squid
	
	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* We want to connect through a HTTP proxy */
		
		conn.setProxyData(new HTTPProxyData(proxyHost, proxyPort));
		
		// if the proxy requires basic authentication:
		// conn.setProxyData(new HTTPProxyData(proxyHost, proxyPort, "username", "secret"));
		
		/* Now connect (through the proxy) */

		conn.connect();

		/* Authenticate.
		 * If you get an IOException saying something like
		 * "Authentication method password not supported by the server at this stage."
		 * then please check the FAQ.
		 */

		boolean isAuthenticated = conn.authenticateWithPassword(username, password);

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

		/* Create a session */

		Session sess = conn.openSession();

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

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

		/* 
		 * This basic example does not handle stderr, which is sometimes dangerous
		 * (please read the FAQ).
		 */

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

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

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

		/* Show exit status, if available (otherwise "null") */

		System.out.println("ExitCode: " + sess.getExitStatus());

		/* 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,代码行数:82,代码来源:BasicWithHTTPProxy.java

示例11: 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

示例12: 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

示例13: 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

示例14: main

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

        // Parameters
        List<String> argsList = Arrays.asList(args);
        Iterator<String> iter = argsList.iterator();
        while (iter.hasNext()) {
            String arg = iter.next();
            if (arg.equals("-h")) {
                host = iter.next();
            }
            if (arg.equals("-p")) {
                password = iter.next();
            }

            if (arg.equals("-u")) {
                url = iter.next();
            }
        }

        if (host == null || host.equals("")) {
            s_logger.info("Did not receive a host back from test, ignoring ssh test");
            System.exit(2);
        }

        if (password == null) {
            s_logger.info("Did not receive a password back from test, ignoring ssh test");
            System.exit(2);
        }

        try {
            s_logger.info("Attempting to SSH into host " + host);
            Connection conn = new Connection(host);
            conn.connect(null, 60000, 60000);

            s_logger.info("User + ssHed successfully into host " + host);

            boolean isAuthenticated = conn.authenticateWithPassword("root", password);

            if (isAuthenticated == false) {
                s_logger.info("Authentication failed for root with password" + password);
                System.exit(2);
            }

            String linuxCommand = "wget " + url;
            Session sess = conn.openSession();
            sess.execCommand(linuxCommand);
            sess.close();
            conn.close();

        } catch (Exception e) {
            s_logger.error("SSH test fail with error", e);
            System.exit(2);
        }
    }
 
开发者ID:apache,项目名称:cloudstack,代码行数:55,代码来源:SshTest.java

示例15: run

import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
@Override
public void run() {
    NDC.push("Following thread has started" + Thread.currentThread().getName());
    int retry = 0;

    //Start copying files between machines in the network
    s_logger.info("The size of the array is " + this.virtualMachines.size());
    while (true) {
        try {
            if (retry > 0) {
                s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
                Thread.sleep(120000);
            }
            for (VirtualMachine vm : this.virtualMachines) {

                s_logger.info("Attempting to SSH into linux host " + this.publicIp + " with retry attempt: " + retry);
                Connection conn = new Connection(this.publicIp);
                conn.connect(null, 600000, 600000);

                s_logger.info("SSHed successfully into linux host " + this.publicIp);

                boolean isAuthenticated = conn.authenticateWithPassword("root", "password");

                if (isAuthenticated == false) {
                    s_logger.info("Authentication failed");
                }
                //execute copy command
                Session sess = conn.openSession();
                String fileName;
                Random ran = new Random();
                fileName = Math.abs(ran.nextInt()) + "-file";
                String copyCommand = new String("./scpScript " + vm.getPrivateIp() + " " + fileName);
                s_logger.info("Executing " + copyCommand);
                sess.execCommand(copyCommand);
                Thread.sleep(120000);
                sess.close();

                //execute wget command
                sess = conn.openSession();
                String downloadCommand =
                    new String("wget http://172.16.0.220/scripts/checkDiskSpace.sh; chmod +x *sh; ./checkDiskSpace.sh; rm -rf checkDiskSpace.sh");
                s_logger.info("Executing " + downloadCommand);
                sess.execCommand(downloadCommand);
                Thread.sleep(120000);
                sess.close();

                //close the connection
                conn.close();
            }
        } catch (Exception ex) {
            s_logger.error(ex);
            retry++;
            if (retry == retryNum) {
                s_logger.info("Performance Guest Network test failed with error " + ex.getMessage());
            }
        }
    }

}
 
开发者ID:apache,项目名称:cloudstack,代码行数:60,代码来源:GuestNetwork.java


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