當前位置: 首頁>>代碼示例>>Java>>正文


Java UserInfo類代碼示例

本文整理匯總了Java中com.jcraft.jsch.UserInfo的典型用法代碼示例。如果您正苦於以下問題:Java UserInfo類的具體用法?Java UserInfo怎麽用?Java UserInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UserInfo類屬於com.jcraft.jsch包,在下文中一共展示了UserInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
ChannelSftp init(String filename) throws JSchException, UnsupportedEncodingException {
	jsch = new JSch();
	ConnectionInfo ci = splitStringToConnectionInfo(filename);

	Session session = jsch.getSession(ci.username, ci.host, ci.port);
	UserInfo ui = new SftpUserInfo(ci.password);
	session.setUserInfo(ui);

	session.connect();

	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp c = (ChannelSftp) channel;

	logDebug("success: init Sftp");
	return c;

}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:19,代碼來源:SftpStorage.java

示例2: SshXpraConnector

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
public SshXpraConnector(XpraClient client, String host, String username, int port, UserInfo userInfo) {
	super(client);
	this.host = host;
	this.username = username;
	this.port = port;
	this.userInfo = userInfo;
	JSch.setConfig("compression_level", "0");
}
 
開發者ID:jksiezni,項目名稱:xpra-client,代碼行數:9,代碼來源:SshXpraConnector.java

示例3: scpFileFromRemoteServer

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * 
 * Scp file from remote server
 * 
 * @param host
 * @param user
 * @param password
 * @param remoteFile
 * @param localFile
 * @throws JSchException 
 * @throws IOException 
 */
public void scpFileFromRemoteServer(String host, String user, String password, String remoteFile, String localFile) throws JSchException, IOException {
	
	String prefix = null;
	if (new File(localFile).isDirectory()) {
		prefix = localFile + File.separator;
	}

	JSch jsch = new JSch();
	Session session = jsch.getSession(user, host, 22);

	// username and password will be given via UserInfo interface.
	UserInfo userInfo = new UserInformation(password);
	session.setUserInfo(userInfo);
	session.connect();

	// exec 'scp -f remoteFile' remotely
	String command = "scp -f " + remoteFile;
	Channel channel = session.openChannel("exec");
	((ChannelExec) channel).setCommand(command);

	// get I/O streams for remote scp
	OutputStream out = channel.getOutputStream();
	InputStream in = channel.getInputStream();

	channel.connect();

	byte[] buf = new byte[1024];

	// send '\0'
	buf[0] = 0;
	out.write(buf, 0, 1);
	out.flush();
	
	readRemoteFileAndWriteToLocalFile(localFile, prefix, out, in, buf);

	session.disconnect();		
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:50,代碼來源:SCPUtility.java

示例4: create

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
@Override
public Session create(ServerDetails serverDetails) throws Exception {
	Session session = null;
	try {
		JSch jsch = new JSch();
		if (serverDetails.getPrivateKeyLocation() != null) {
			jsch.addIdentity(serverDetails.getPrivateKeyLocation());
		}
		session = jsch.getSession(serverDetails.getUser(), serverDetails.getHost(), serverDetails.getPort());
		session.setConfig("StrictHostKeyChecking", "no"); //
		UserInfo userInfo = new JschUserInfo(serverDetails.getUser(), serverDetails.getPassword());
		session.setUserInfo(userInfo);
		session.setTimeout(60000);
		session.setPassword(serverDetails.getPassword());
		session.connect();
	} catch (Exception e) {
		throw new RuntimeException(
				"ERROR: Unrecoverable error when trying to connect to serverDetails :  "
						+ serverDetails, e);
	}
	return session;
}
 
開發者ID:danielemaddaluno,項目名稱:command4j,代碼行數:23,代碼來源:SessionFactory.java

示例5: get

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * Gets SSH Client
 *
 * @return
 */
@SneakyThrows(JSchException.class)
public Session get() {
    JSch jsch = new JSch();
    UserInfo userInfo;
    Session session = jsch.getSession(username, hostname, port);
    if (useKey) {
        jsch.addIdentity(key);
        userInfo = new EmbeddedUserInfoInteractive();
    } else {
        session.setPassword(password);
        session.setConfig("StrictHostKeyChecking", "no");
        userInfo = EmbeddedUserInfo.builder().password(password).build();
    }
    session.setUserInfo(userInfo);
    session.setConfig("HashKnownHosts", "yes");
    session.setTimeout(10000);
    session.connect();
    return session;
}
 
開發者ID:asebak,項目名稱:embeddedlinux-jvmdebugger-intellij,代碼行數:25,代碼來源:EmbeddedSSHClient.java

示例6: connectAndGetSftpChannel

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
public ChannelSftp connectAndGetSftpChannel() throws JSchException {
    JSch jsch = new JSch();
    jsch.setKnownHosts(context.getFilesDir().getAbsolutePath() + File.separator + "jsch_known_hosts");

    String username = prefs.sshUserName().getOr(null);
    String host = prefs.sshServerAddress().getOr(null);
    String port = prefs.sshServerPort().getOr(null);
    if (username == null || host == null || port == null)
        throw new IllegalStateException("Please enter your server settings first");

    Session session = jsch.getSession(username, host, Integer.parseInt(port));

    UserInfo info = storedOrAskedUserInfo;
    session.setUserInfo(info);
    try {
        session.connect(5000);
        storedOrAskedUserInfo.confirmPasswordRight();
    }
    catch (JSchException je) {
        if ("auth fail".equals(je.getMessage().toLowerCase())) { // undocumented!
            storedOrAskedUserInfo.clearPassword();
        }
        throw je;
    }

    ChannelSftp channel = (ChannelSftp)session.openChannel("sftp");
    channel.connect(5000);
    return channel;
}
 
開發者ID:egueli,項目名稱:ETStreamHome,代碼行數:30,代碼來源:SftpManager.java

示例7: wrapAuthentication

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
void wrapAuthentication(TransportCommand command, UsernamePasswordCredentialsProvider ownerAuth,
                               String sshPassword, File credentialsFile, List<String> credentialsList,
                               UserInfo userInfo) {

    if (ownerAuth != null)
        command.setCredentialsProvider(ownerAuth);
    else
        command.setCredentialsProvider(new ElegitCredentialsProvider(credentialsList));

    command.setTransportConfigCallback(
            new TransportConfigCallback() {
                @Override
                public void configure(Transport transport) {

                    if (transport instanceof TransportGitSsh) {
                        SshTransport sshTransport = (SshTransport) transport;
                        sshTransport.setSshSessionFactory(sshSessionFactory);
                    }

                }
            });
}
 
開發者ID:dmusican,項目名稱:Elegit,代碼行數:23,代碼來源:RepoHelper.java

示例8: connect

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
@Override
public void connect() throws SocketException, IOException {
	try {
		session = jsch.getSession(username,host.getHostAddress() , port);
		java.util.Properties config = new java.util.Properties(); 
		config.put("StrictHostKeyChecking", "no");
		session.setConfig(config);
		
		UserInfo ui=new UserInfoImpl(password,null);
		session.setUserInfo(ui);
		if(timeout>0) session.setTimeout(timeout);
	    session.connect();
	    
	    Channel channel=session.openChannel("sftp");
	    channel.connect();
	    channelSftp = (ChannelSftp)channel;
	    
	    
	    // check fingerprint
		if(!StringUtil.isEmpty(fingerprint)) {
			if(!fingerprint.equalsIgnoreCase(fingerprint())) {
				disconnect();
				throw new IOException("given fingerprint is not a match.");
			}
        }
	    handleSucess();
	}
	catch(JSchException e){
		handleFail(e, stopOnError);
	}
}
 
開發者ID:lucee,項目名稱:Lucee,代碼行數:32,代碼來源:SFTPClientImpl.java

示例9: getMemoryUtilisation

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * Gets the information related to memory utilization for each node.
 * 
 * @param config
 *            the config
 * @param nodeIp
 *            the node ip
 * @return list of pojos containing memory utilization info for each node
 * @throws JSchException
 *             the j sch exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public Map<String, String> getMemoryUtilisation(Config config, String nodeIp) throws JSchException, IOException {
	
	JobConfig jobConfig = (JobConfig)config;
	Slave slave = RemoteFileUtil.findSlave(nodeIp, jobConfig.getSlaves());
	String user = slave.getUser();
	String rsaFilePath = jobConfig.getMaster().getRsaFile();
	String dsaFilePath = jobConfig.getMaster().getDsaFile();
	Session session = null;
	Map<String, String> vmStats = null;
	try {
		session = createSession(user, nodeIp, rsaFilePath, dsaFilePath);
		UserInfo ui = new JumbuneUserInfo();
		session.setUserInfo(ui);
		session.connect();
		vmStats = getVmStats(session);
	} finally {
		session.disconnect();
	}
	return vmStats;
}
 
開發者ID:Impetus,項目名稱:jumbune,代碼行數:34,代碼來源:ProfilerJMXDump.java

示例10: createSession

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * For creating a JSCH session.
 * 
 * @param user
 *            the user
 * @param host
 *            the host
 * @param rsaFilePath
 *            the rsa file path
 * @param dsaFilePath
 *            the dsa file path
 * @return a JSCH session
 * @throws JSchException
 *             the j sch exception
 */
public static Session createSession(String user, String host, String rsaFilePath, String dsaFilePath, CommandType commandType) throws JSchException {
	JSch jsch = new JSch();
	Session session = null;

	SwitchedIdentity switchedIdentity = changeIdentityAsPerCommand(user, rsaFilePath, dsaFilePath, commandType);
	if(commandType.equals(CommandType.FS)){
		jsch.addIdentity(switchedIdentity.getPrivatePath());
	}
	java.util.Properties conf = new java.util.Properties();
	session = jsch.getSession(switchedIdentity.getUser(), host, RemotingConstants.TWENTY_TWO);
	UserInfo info = getSwitchedUser(commandType, switchedIdentity);
	session.setUserInfo(info);
	conf.put(STRICT_HOST_KEY_CHECKING, "no");
	session.setConfig(conf);
	LOGGER.debug("Session Established, for user ["+switchedIdentity.getUser()+"]");
	return session;
}
 
開發者ID:Impetus,項目名稱:jumbune,代碼行數:33,代碼來源:JschUtil.java

示例11: verifyPassword

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
public static boolean verifyPassword(String user, String encryptedPasswrd) throws JSchException {
	JSch jsch = new JSch();
	Session session = null;
	java.util.Properties conf = new java.util.Properties();
	session = jsch.getSession(user, "localhost", RemotingConstants.TWENTY_TWO);
	UserInfo info = new JumbuneUserInfo(StringUtil.getPlain(encryptedPasswrd));
	session.setUserInfo(info);
	conf.put(STRICT_HOST_KEY_CHECKING, "no");
	session.setConfig(conf);
//	LOGGER.debug("Session Established, for user ["+user+"]");
	boolean isConnected = false;
	if(session!=null){
		session.connect();
		isConnected = session.isConnected();
		LOGGER.debug("Session Connected, for user ["+user+"]");
		session.disconnect();
	}
	return isConnected;
}
 
開發者ID:Impetus,項目名稱:jumbune,代碼行數:20,代碼來源:JschUtil.java

示例12: execCmd

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * Execute command
 * @param host
 * @param user
 * @param passwd
 * @param cmd
 * @return String the reply of remote session
 */
public String execCmd (String host, String user, String passwd, String cmd){
    String replyy = "";
    String reply = null;
    try{
        JSch jsch=new JSch();
        Session session=jsch.getSession(user, host, 22);
        UserInfo ui = new MyUserInfo(passwd);
        session.setUserInfo(ui);
        session.setTimeout(600000);
        session.connect();
        Channel channel=session.openChannel("exec");
        ((ChannelExec)channel).setCommand(cmd);
        channel.setInputStream(null);
        InputStreamReader in = new InputStreamReader(channel.getInputStream());
        OutputStreamWriter out = new OutputStreamWriter(channel.getOutputStream());
        BufferedWriter bw = new BufferedWriter(out);
        BufferedReader br = new BufferedReader(in);
        channel.connect();
        while ((reply = br.readLine()) != null) {
            bw.write(reply);
            replyy=replyy+"\n"+reply;
            bw.flush();
            Thread.sleep(100);
        }
        while(true){
            if(channel.isClosed()){
                break;
            } try{
                Thread.sleep(1500);
            } catch(Exception ee){
            }
        }
        in.close();
        out.close();
        br.close();
        bw.close();
        channel.disconnect();
        session.disconnect();
    }
    catch(Exception e){
        log.error("ERROR , Possible no connection with : "+user+" "+passwd+ " "+host+"\n\t\t please check LAN and vpn connection or host");
    }
    return replyy;
}
 
開發者ID:GiannisPapadakis,項目名稱:seletest,代碼行數:53,代碼來源:SSHUtils.java

示例13: outputCommandSSH

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
/**
 * Execute SSH command and return output
 * @param username The ssh user
 * @param host The host to connect
 * @param key The ssh key
 * @param commandssh The command to launch
 * @return the output of the command
 */
public String outputCommandSSH(String username, String host, String key, String commandssh){
	String res = "";
	try{
	      JSch jsch=new JSch();
	      java.util.Properties config = new java.util.Properties();
	      config.put("StrictHostKeyChecking", "no"); //avoid host key checking

	      int SSH_port = 22; 
	      
	      jsch.addIdentity(key , "passphrase");

	      Session session=jsch.getSession(username, host, SSH_port); //SSH connection
	 
			if(new Configuration().Debug){
				System.out.println("Connection to "+host+" on the port "+SSH_port+" with key: "+key+" and username: "+username);
			}
	      
	      // username and passphrase will be given via UserInfo interface.
	      UserInfo ui=new MyUserInfo();
	      session.setUserInfo(ui);
	      session.setConfig(config);
	      session.connect();

	      Channel channel=session.openChannel("exec"); // open channel for exec command
	      ((ChannelExec)channel).setCommand(commandssh);

	      channel.setInputStream(null);

	      ((ChannelExec)channel).setErrStream(System.err);
		
	      InputStream in=channel.getInputStream();
		
	      channel.connect();
		
		/*
		 * get output ssh command launched
		 */
		byte[] tmp=new byte[1024];
		while(true){
			while(in.available()>0){
				int i=in.read(tmp, 0, 1024);
				if(i<0)break;
				res += new String(tmp, 0, i);
				//System.out.print(new String(tmp, 0, i));
			}
			if(channel.isClosed()){
				if(in.available()>0) continue; 
				if(new Configuration().Debug){
					System.out.println("exit-status: "+channel.getExitStatus());
				}
				break;
			}
			try{Thread.sleep(1000);}catch(Exception ee){}
		}
		channel.disconnect();
		session.disconnect();
		}
		
		catch(Exception e){
			System.out.println(e);
		}
	return res;
}
 
開發者ID:franblas,項目名稱:Shavadoop,代碼行數:72,代碼來源:CommandSSH.java

示例14: connect

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
public void connect() {
	try {

		session = jsch.getSession(username, server, port);

		if (logger.isDebugEnabled())
			logger.debug(String.format(
				"login ssh to server %s:%d as user %s password %s", server,
				port, username, password));
		UserInfo ui = new MyUserInfo(password);

		java.util.Properties config = new java.util.Properties();
		config.put("StrictHostKeyChecking", "no");
		session.setConfig(config);
		session.setPassword(password);
		// session.setUserInfo(ui);

		session.connect();

	} catch (JSchException e) {

		throw new RuntimeException(e);
	}
}
 
開發者ID:jackhatedance,項目名稱:visual-programming,代碼行數:25,代碼來源:SshAgent.java

示例15: createSession

import com.jcraft.jsch.UserInfo; //導入依賴的package包/類
public Session createSession(PrintStream logger) {
	JSch jsch = new JSch();

	Session session = null;
	try {
		session = jsch.getSession(username, ip, port);
		session.setPassword(password);

		UserInfo ui = new GsshUserInfo(password);
		session.setUserInfo(ui);

		java.util.Properties config = new java.util.Properties();
		config.put("StrictHostKeyChecking", "no");
		session.setConfig(config);
		session.setDaemonThread(false);
		session.connect();
		logger.println("create ssh session success with ip=[" + ip
		 + "],port=[" + port + "],username=[" + username
		 + "],password=[*******]");
	} catch (Exception e) {
		logger.println("create ssh session failed with ip=[" + ip
				+ "],port=[" + port + "],username=[" + username
				+ "],password=[*******]");
		e.printStackTrace(logger);
		throw new GsshPluginException(e);
	}
	return session;
}
 
開發者ID:jenkinsci,項目名稱:ssh2easy-plugin,代碼行數:29,代碼來源:DefaultSshClient.java


注:本文中的com.jcraft.jsch.UserInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。