package com.wonderant.ssh;

import java.io.File;
import java.util.Properties;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;

public class SecureContext {
	private String password;
	private File privateKeyFile;
	private boolean trustAllHosts = false;
	private String username;
	private String host;

	public SecureContext(String pUsername, String pHost) {
		super();
		username = pUsername;
		host = pHost;
	}

	public String getPassword() {
		return password;
	}

	public SecureContext setPassword(String pPassword) {
		password = pPassword;
		return this;
	}

	public File getPrivateKeyFile() {
		return privateKeyFile;
	}

	public SecureContext setPrivateKeyFile(File pPrivateKeyFile) {
		privateKeyFile = pPrivateKeyFile;
		return this;
	}

	public boolean isTrustAllHosts() {
		return trustAllHosts;
	}

	public SecureContext setTrustAllHosts(boolean pTrustAllHosts) {
		trustAllHosts = pTrustAllHosts;
		return this;
	}

	public String getUsername() {
		return username;
	}

	public SecureContext setUsername(String pUsername) {
		username = pUsername;
		return this;
	}

	public String getHost() {
		return host;
	}

	public SecureContext setHost(String pHost) {
		host = pHost;
		return this;
	}

	private UserInfo getUserInfo() {
		return new UserInfo() {
			public void showMessage(String pMessage) {
			}

			public boolean promptYesNo(String pMessage) {
				return false;
			}

			public boolean promptPassword(String pMessage) {
				return password != null;
			}

			public boolean promptPassphrase(String pMessage) {
				return false;
			}

			public String getPassword() {
				return password;
			}

			public String getPassphrase() {
				return null;
			}
		};
	}

	private Properties getConfig() {
		Properties config = new java.util.Properties();
		if (isTrustAllHosts()) {
			config.put("StrictHostKeyChecking", "no");
		}
		return config;
	}

	public Session createSession() throws JSchException {
		JSch jsch = new JSch();
		if (getPrivateKeyFile() != null) {
			jsch.addIdentity(getPrivateKeyFile().getAbsolutePath());
		}
		Session session = jsch.getSession(getUsername(), getHost(), 22);
		session.setConfig(getConfig());
		session.setUserInfo(getUserInfo());
		return session;
	}
}

@@ -377,16 +377,42 @@
 ng host;
+%0A        private int port;
 %0A%0A%09publi
@@ -467,16 +467,106 @@
 %7B%0A%09%09
-super();
+this(pUsername, pHost, 22);%0A%09%7D%0A%0A%09public SecureContext(String pUsername, String pHost, int pPort) %7B
 %0A%09%09u
@@ -598,24 +598,54 @@
 st = pHost;%0A
+                port = pPort;%0A
 %09%7D%0A%0A%09public 
@@ -1426,24 +1426,145 @@
 n this;%0A%09%7D%0A%0A
+%09public int getPort() %7B%0A%09%09return port;%0A%09%7D%0A%0A%09public SecureContext setPort(int pPort) %7B%0A%09%09port = pPort;%0A%09%09return this;%0A%09%7D%0A%0A
 %09private Use
@@ -2453,18 +2453,25 @@
 Host(), 
-22
+getPort()
 );%0A%09%09ses

Add another constructor to choose port in SecureContext