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


Java SshClient.authenticate方法代码示例

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


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

示例1: connectSsh

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * connect to host
 * 
 * @return
 * @throws Exception
 */
private static SshClient connectSsh() throws Exception {
	SshClient ssh = new SshClient();

	HostKeyVerification host = new IgnoreHostKeyVerification();
	String hostStr = getBundle().getString("ssh.host");
	ssh.connect(hostStr, host);
	PasswordAuthenticationClient auth = new PasswordAuthenticationClient();
	auth.setUsername(getBundle().getString("ssh.user"));
	auth.setPassword(getBundle().getString("ssh.pwd"));
	int result = ssh.authenticate(auth);

	System.out.println("Status " + result);
	if ((result == AuthenticationProtocolState.CANCELLED) || (result == AuthenticationProtocolState.FAILED)) {
		throw new Exception("Authentication Error.");
	}
	return ssh;
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:24,代码来源:SshUtil.java

示例2: connectToLinux

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
public boolean connectToLinux(String ipAddress) {
	boolean isConnect = false;
	try {
		SshClient client = new SshClient();
		client.connect(ipAddress, 22);// IP�Ͷ˿�
		// �����û���������
		PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
		pwd.setUsername("root");
		pwd.setPassword("chenzhao");
		int result = client.authenticate(pwd);
		if (result == AuthenticationProtocolState.COMPLETE) {// ����������
			isConnect = true;
		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();

	}
	return isConnect;
}
 
开发者ID:yifzhang,项目名称:storm-miclog,代码行数:21,代码来源:PingServerTest.java

示例3: makeConnection

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/***********************************************************************/
public synchronized Connection makeConnection(String database, DatabaseConfiguration originalConfiguration)
{
  int port = counter++;
  DatabaseConfiguration config = new DatabaseConfiguration(originalConfiguration.getDataSourceName(), originalConfiguration.getDriver(), originalConfiguration.getProtocol(), "localhost", "" + port, database, originalConfiguration.getUserName(), originalConfiguration.getPassword(), originalConfiguration.getType());
  try
  {
      LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
      SshClient ssh = new SshClient();
      ssh.setSocketTimeout(60000);
      ssh.connect(originalConfiguration.getServer(), new IgnoreHostKeyVerification());
      PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
      pwd.setUsername(originalConfiguration.getUserName());
      pwd.setPassword(originalConfiguration.getPassword());
      ssh.authenticate(pwd);
      ForwardingClient client = ssh.getForwardingClient();
      client.addLocalForwarding(config.getProtocol(), "0.0.0.0", config.getPort(), "localhost", originalConfiguration.getPort());
      client.startLocalForwarding(config.getProtocol());
      return new SshConnection(ssh, config.makeConnection());
  }
  catch (IOException ie)
  {
    throw ObjectUtils.throwAsError(ie);
  }
}
 
开发者ID:approvals,项目名称:ApprovalTests.Java,代码行数:26,代码来源:SshDatabaseWrapper.java

示例4: connect

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
public void connect() throws IOException {
    lia.gsi.ssh.GSIAuthenticationClient gsiAuth = null;
    try {
        gsiAuth = new lia.gsi.ssh.GSIAuthenticationClient();
        gsiAuth.setUsername(username);
    } catch (GSSException e) {
        throw new IOException("Cannot load grid credentials.");
    }
    conn = new SshClient();
    SshToolsConnectionProfile properties = new SshToolsConnectionProfile();
    // TODO: add new "port" parameter
    properties.setPort(port);
    properties.setForwardingAutoStartMode(false);
    properties.setHost(hostname);
    properties.setUsername(username);
    conn.setUseDefaultForwarding(false);
    conn.connect(properties);
    try {
        // Authenticate the user
        int result = conn.authenticate(gsiAuth, hostname);
        if (result != AuthenticationProtocolState.COMPLETE) {
            throw new IOException("GSI authentication failed");
        }
        // Open a session channel
        sess = conn.openSessionChannel();
        sess.requestPseudoTerminal("javash", 0, 0, 0, 0, "");
    } catch (Throwable t) {
        throw new IOException(t.getMessage());
    }
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:31,代码来源:GSISSHControlStream.java

示例5: connect

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * Connect. This action simulates all the actions required for a SSH connection
 *
 * @param host  the hostname of the host you want to connect to
 * @param port the port of the host you want to connect to
 * @param username the username required for authentication
 * @param password the password required for authentication
 * @return the ssh client you connected to
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static SshClient connect(String host, int port,String username,String password) throws IOException {
	SSH_LOG.info("Connecting to " + host);
	SshClient ssh = new SshClient();
	ssh.connect(host, port, new IgnoreHostKeyVerification());
	PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
	passwordAuthenticationClient.setUsername(username);
	passwordAuthenticationClient.setPassword(password);
	int result = ssh.authenticate(passwordAuthenticationClient);
	if (result != AuthenticationProtocolState.COMPLETE) {
		throw new IOException("Login to " + host + ":" + port + " "+ username + "/" + password + " failed");
	}
	SSH_LOG.info("Connected " + host);
	return ssh;
}
 
开发者ID:persado,项目名称:stevia,代码行数:25,代码来源:SSHUtils.java

示例6: sshLogin

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/************************************************************************/
private static SftpClient sshLogin(FTPConfig config, SshClient ssh) throws IOException
{
  ssh.setSocketTimeout(60000);
  ssh.connect(config.host, new IgnoreHostKeyVerification());
  PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
  pwd.setUsername(config.userName);
  pwd.setPassword(config.password);
  ssh.authenticate(pwd);
  SftpClient sftp = ssh.openSftpClient();
  return sftp;
}
 
开发者ID:approvals,项目名称:ApprovalTests.Java,代码行数:13,代码来源:NetUtils.java

示例7: main

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * The main program for the PasswordConnect class
 *
 * @param args The command line arguments
 */
public static void main(String args[]) {
  try {
    // Setup a logfile
    /*Handler fh = new FileHandler("example.log");
    fh.setFormatter(new SimpleFormatter());
    Logger.getLogger("com.sshtools").setUseParentHandlers(false);
    Logger.getLogger("com.sshtools").addHandler(fh);
    Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
    // Configure J2SSH (This will attempt to install the bouncycastle provider
    // under jdk 1.3.1)
    ConfigurationLoader.initialize(false);
    System.out.print("Connect to host? ");
    System.out.print("Connect to host? ");
    String hostname = reader.readLine();
    // Make a client connection
    SshClient ssh = new SshClient();
    SshConnectionProperties properties = new SshConnectionProperties();
    properties.setHost(hostname);
    // Connect to the host
    ssh.connect(properties);
    // Create a password authentication instance
    KBIAuthenticationClient kbi = new KBIAuthenticationClient();
    // Get the users name
    System.out.print("Username? ");
    // Read the password
    String username = reader.readLine();
    kbi.setUsername(username);
    kbi.setKBIRequestHandler(new KBIRequestHandler() {
      public void showPrompts(String name, String instructions,
                              KBIPrompt[] prompts) {
        System.out.println(name);
        System.out.println(instructions);
        String response;
        if (prompts != null) {
          for (int i = 0; i < prompts.length; i++) {
            System.out.print(prompts[i].getPrompt() + ": ");
            try {
              response = reader.readLine();
              prompts[i].setResponse(response);
            }
            catch (IOException ex) {
              prompts[i].setResponse("");
              ex.printStackTrace();
            }
          }
        }
      }
    });
    // Try the authentication
    int result = ssh.authenticate(kbi);
    // Evaluate the result
    if (result == AuthenticationProtocolState.COMPLETE) {
      // The connection is authenticated we can now do some real work!
      SessionChannelClient session = ssh.openSessionChannel();
      if(!session.requestPseudoTerminal("vt100", 80, 24, 0, 0, ""))
        System.out.println("Failed to allocate a pseudo terminal");
      if(session.startShell()) {
        IOStreamConnector input =
            new IOStreamConnector(System.in, session.getOutputStream());
        IOStreamConnector output =
            new IOStreamConnector(session.getInputStream(), System.out);
        output.getState().waitForState(IOStreamConnectorState.CLOSED);
      }else
        System.out.println("Failed to start the users shell");
      ssh.disconnect();
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:77,代码来源:KBIConnect.java

示例8: main

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * The main program for the PasswordConnect class
 *
 * @param args The command line arguments
 */
public static void main(String args[]) {
  try {
    // JDK > 1.4 ONLY
    /*Handler fh = new FileHandler("example.log");
    fh.setFormatter(new SimpleFormatter());
    Logger.getLogger("com.sshtools").setUseParentHandlers(false);
    Logger.getLogger("com.sshtools").addHandler(fh);
    Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
    // Configure J2SSH (This will attempt to install the bouncycastle provider
    // under jdk 1.3.1)
    ConfigurationLoader.initialize(false);
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Connect to host? ");
    String hostname = reader.readLine();
    // Make a client connection
    SshClient ssh = new SshClient();
    ssh.setSocketTimeout(30000);
    SshConnectionProperties properties = new SshConnectionProperties();
    properties.setHost(hostname);
    properties.setPrefPublicKey("ssh-dss");
    // Connect to the host
    ssh.connect(properties);
    // Create a password authentication instance
    PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
    // Get the users name
    System.out.print("Username? ");
    // Read the password
    String username = reader.readLine();
    pwd.setUsername(username);
    // Get the password
    System.out.print("Password? ");
    String password = reader.readLine();
    pwd.setPassword(password);
    // Try the authentication
    int result = ssh.authenticate(pwd);
    // Evaluate the result
    if (result == AuthenticationProtocolState.COMPLETE) {
      // The connection is authenticated we can now do some real work!
      SessionChannelClient session = ssh.openSessionChannel();
      if(!session.requestPseudoTerminal("vt100", 80, 24, 0, 0, ""))
        System.out.println("Failed to allocate a pseudo terminal");
      if (session.startShell()) {
        IOStreamConnector input =
            new IOStreamConnector();
        IOStreamConnector output =
            new IOStreamConnector();
        IOStreamConnector error =
            new IOStreamConnector();
        output.setCloseOutput(false);
        input.setCloseInput(false);
        error.setCloseOutput(false);
        input.connect(System.in, session.getOutputStream());
        output.connect(session.getInputStream(), System.out);
        error.connect(session.getStderrInputStream(), System.out);
        session.getState().waitForState(ChannelState.CHANNEL_CLOSED);
      }else
        System.out.println("Failed to start the users shell");
      ssh.disconnect();
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:71,代码来源:PasswordConnect.java

示例9: main

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * The main program for the PasswordConnect class
 *
 * @param args The command line arguments
 */
public static void main(String args[]) {
  try {
    // Setup a logfile
    /*Handler fh = new FileHandler("example.log");
    fh.setFormatter(new SimpleFormatter());
    Logger.getLogger("com.sshtools").setUseParentHandlers(false);
    Logger.getLogger("com.sshtools").addHandler(fh);
    Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
    // Configure J2SSH (This will attempt to install the bouncycastle provider
    // under jdk 1.3.1)
    ConfigurationLoader.initialize(false);
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Connect to host? ");
    String hostname = reader.readLine();
    // Make a client connection
    SshClient ssh = new SshClient();
    // Connect to the host
    ssh.connect(hostname);
    // Create a password authentication instance
    PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
    // Get the users name
    System.out.print("Username? ");
    String username = reader.readLine();
    pwd.setUsername(username);
    // Get the password
    System.out.print("Password? ");
    String password = reader.readLine();
    pwd.setPassword(password);
    // Try the authentication
    int result = ssh.authenticate(pwd);
    // Evaluate the result
    if (result == AuthenticationProtocolState.COMPLETE) {
      // The connection is authenticated we can now do some real work!
      SftpClient sftp = ssh.openSftpClient();
      // Make a directory
      try {
        sftp.mkdir("j2ssh");
      }
      catch (IOException ex) {
      }
      // Change directory
      sftp.cd("j2ssh");
      System.out.println(sftp.pwd());
      // Change the mode
      sftp.chmod(0777, "j2ssh");
      sftp.lcd("c:/");
      // Upload a file
      sftp.put("system.gif");
      // Change the local directory
      sftp.lcd("localdir");
      // Download a file
      sftp.get("somefile.txt", "anotherfile.txt");
      // Remove a directory or file
      sftp.rm("j2ssh");
      // Quit
      sftp.quit();
      ssh.disconnect();
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  finally {
    System.exit(0);
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:73,代码来源:SftpConnect.java

示例10: main

import com.sshtools.j2ssh.SshClient; //导入方法依赖的package包/类
/**
 * The main program for the PortForwarding class
 *
 * @param args The command line arguments
 */
public static void main(String args[]) {
  try {
    // Setup a logfile
    /*Handler fh = new FileHandler("example.log");
    fh.setFormatter(new SimpleFormatter());
    Logger.getLogger("com.sshtools").setUseParentHandlers(false);
    Logger.getLogger("com.sshtools").addHandler(fh);
    Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
    // Configure J2SSH (This will attempt to install the bouncycastle provider
    // under jdk 1.3.1)
    ConfigurationLoader.initialize(false);
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Connect to host? ");
    String hostname = reader.readLine();
    // Make a client connection
    SshClient ssh = new SshClient();
    // Connect to the hos
    ssh.connect(hostname);
    // Create a password authentication instance
    PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
    // Get the users name
    System.out.print("Username? ");
    String username = reader.readLine();
    pwd.setUsername(username);
    // Get the password
    System.out.print("Password? ");
    String password = reader.readLine();
    pwd.setPassword(password);
    // Try the authentication
    int result = ssh.authenticate(pwd);
    // Evaluate the result
    if (result == AuthenticationProtocolState.COMPLETE) {
      ForwardingClient forwarding = ssh.getForwardingClient();
      forwarding.addLocalForwarding("Test Local", "0.0.0.0", 8081,
                                    "127.0.0.1", 80);
      forwarding.startLocalForwarding("Test Local");
      forwarding.addRemoteForwarding("Test Remote", "0.0.0.0", 8081,
                                     "127.0.0.1", 8080);
      forwarding.startRemoteForwarding("Test Remote");
    }
    ssh.getConnectionState().waitForState(TransportProtocolState.DISCONNECTED);
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:53,代码来源:PortForwarding.java


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