public class PasswordAuthentication extends Object implements SshAuthentication
Basic password authentication class used for SSH password authentication. Once a connection has been established to an SSH server the user is normally required to authenticate themselves. This class implements a basic password SshAuthentication that can be passed into the SshClient to authenticate. As a username is required to establish a connection it is not required that it be set on the password object, however if you wish to change the username you can do so (this may not be allowed by some server implementations).
Use password authentication as follows:
SshConnector con = SshConnector.getInstance(); SshClient ssh = con.connect(new SocketTransport("beagle2.mars.net", 22), "martianx"); PasswordAuthentication pwd = new PasswordAuthentication(); pwd.setPassword("likeidgivethataway!"); if(!ssh.isAuthenticated()) { if(ssh.authenticate(pwd)==SshAuthentication.COMPLETE) { // Transfer some files or do something else interesting } }
It is recommended that in situations where you may be connecting to an SSH2 server, that the Ssh2PasswordAuthentication subclass is used instead. This extends the basic functionality provided here by supporting the changing of the users password. Although this feature is not supported by SSH1 it does not break the authentication process to use the Ssh2PasswordAuthentication implementation .
Ssh2PasswordAuthentication
CANCELLED, COMPLETE, FAILED, FURTHER_AUTHENTICATION_REQUIRED, PUBLIC_KEY_ACCEPTABLE
Constructor and Description |
---|
PasswordAuthentication() |
PasswordAuthentication(String password) |
Modifier and Type | Method and Description |
---|---|
String |
getMethod()
The SSH authentication method name
|
String |
getPassword()
Get the password.
|
String |
getUsername()
Get the username.
|
void |
setPassword(String password)
Set the password.
|
void |
setUsername(String username)
Set the username.
|
public PasswordAuthentication()
public PasswordAuthentication(String password)
public void setPassword(String password)
password
- public String getPassword()
public String getMethod()
SshAuthentication
getMethod
in interface SshAuthentication
public void setUsername(String username)
setUsername
in interface SshAuthentication
public String getUsername()
getUsername
in interface SshAuthentication
Copyright © 2024. All rights reserved.