本文整理汇总了Java中com.sshtools.j2ssh.authentication.PasswordAuthenticationClient类的典型用法代码示例。如果您正苦于以下问题:Java PasswordAuthenticationClient类的具体用法?Java PasswordAuthenticationClient怎么用?Java PasswordAuthenticationClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PasswordAuthenticationClient类属于com.sshtools.j2ssh.authentication包,在下文中一共展示了PasswordAuthenticationClient类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: connectSsh
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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: connect
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
public boolean connect(String host, String user, String password) {
try {
// Connect to host ignoring host key verification
ssh.connect(host, new IgnoreHostKeyVerification());
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
pwd.setUsername(user);
pwd.setPassword(password);
status = ssh.authenticate(pwd);
if (status == AuthenticationProtocolState.COMPLETE)
return true;
else
return false;
} catch (IOException ioe) {
System.out.println("Error in connecting to "+host+" with user "+user);
return false;
}
}
开发者ID:vagfed,项目名称:hmcScanner,代码行数:21,代码来源:SSHManager.java
示例3: connectToLinux
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例4: getSshAuthentication
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
private SshAuthenticationClient getSshAuthentication() throws Exception {
if (StringUtils.isNotEmpty(privateKeyFilePath)) {
PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
CredentialFactory pkcf = new CredentialFactory(getPrivateKeyAuthAlias(), getUsername(), getPrivateKeyPassword());
pk.setUsername(pkcf.getUsername());
SshPrivateKeyFile pkFile = SshPrivateKeyFile.parse(new File(privateKeyFilePath));
pk.setKey(pkFile.toPrivateKey(pkcf.getPassword()));
return pk;
}
CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
if (StringUtils.isNotEmpty(usercf.getPassword())) {
PasswordAuthenticationClient pac = new PasswordAuthenticationClient();
pac.setUsername(usercf.getUsername());
pac.setPassword(usercf.getPassword());
return pac;
}
throw new Exception("Unknown authentication type, either the password or the privateKeyFile must be filled");
}
开发者ID:ibissource,项目名称:iaf,代码行数:19,代码来源:FtpSession.java
示例5: makeConnection
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例6: showAuthenticationPrompt
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
/**
*
*
* @param instance
*
* @return
*
* @throws IOException
*/
protected int showAuthenticationPrompt(SshAuthenticationClient instance)
throws IOException {
instance.setUsername(getCurrentConnectionProfile().getUsername());
if (instance instanceof PasswordAuthenticationClient) {
PasswordAuthenticationDialog dialog = new PasswordAuthenticationDialog((Frame) SwingUtilities.getAncestorOfClass(
Frame.class, SshToolsApplicationClientPanel.this));
instance.setAuthenticationPrompt(dialog);
((PasswordAuthenticationClient) instance).setPasswordChangePrompt(PasswordChange.getInstance());
PasswordChange.getInstance().setParentComponent(SshToolsApplicationClientPanel.this);
} else if (instance instanceof PublicKeyAuthenticationClient) {
PublicKeyAuthenticationPrompt prompt = new PublicKeyAuthenticationPrompt(SshToolsApplicationClientPanel.this);
instance.setAuthenticationPrompt(prompt);
} else if (instance instanceof KBIAuthenticationClient) {
KBIAuthenticationClient kbi = new KBIAuthenticationClient();
((KBIAuthenticationClient) instance).setKBIRequestHandler(new KBIRequestHandlerDialog(
(Frame) SwingUtilities.getAncestorOfClass(Frame.class,
SshToolsApplicationClientPanel.this)));
}
return ssh.authenticate(instance);
}
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:32,代码来源:SshToolsApplicationClientPanel.java
示例7: SshConnection
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
private SshConnection(String host, String user, String pass) throws Exception {
ssh = new SshClient();
properties = new SshConnectionProperties();
properties.setHost(host);
pwd = new PasswordAuthenticationClient();
pwd.setUsername(user);
pwd.setPassword(pass);
assureAuthenticatedConnection();
}
开发者ID:hpiasg,项目名称:desij,代码行数:13,代码来源:SshConnection.java
示例8: connect
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例9: sshLogin
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例10: setInstance
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
/**
*
*
* @param instance
*
* @throws AuthenticationProtocolException
*/
public void setInstance(SshAuthenticationClient instance)
throws AuthenticationProtocolException {
if (instance instanceof PasswordAuthenticationClient) {
this.instance = (PasswordAuthenticationClient) instance;
} else {
throw new AuthenticationProtocolException(
"PasswordAuthenticationClient instance required");
}
}
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:17,代码来源:PasswordAuthenticationDialog.java
示例11: showPrompt
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的package包/类
/**
*
*
* @return
*/
public boolean showPrompt(SshAuthenticationClient inst)
throws AuthenticationProtocolException {
if (inst instanceof PasswordAuthenticationClient) {
instance = (PasswordAuthenticationClient) inst;
if (instance.getUsername() != null) {
jTextUsername.setText(instance.getUsername());
}
if (!jTextUsername.getText().equals("")) {
jPasswordField.grabFocus();
}
UIUtil.positionComponent(SwingConstants.CENTER, this);
setVisible(true);
if (!userCancelled) {
instance.setUsername(getUsername());
instance.setPassword(getPassword());
return true;
} else {
return false;
}
} else {
throw new AuthenticationProtocolException(
"PasswordAuthenticationClient instance required");
}
}
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:35,代码来源:PasswordAuthenticationDialog.java
示例12: main
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例13: main
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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
示例14: main
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; //导入依赖的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.authentication.PasswordAuthenticationClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论