com.mindbright.ssh2
Class SSH2Authenticator

java.lang.Object
  extended by com.mindbright.ssh2.SSH2Authenticator

public class SSH2Authenticator
extends java.lang.Object

This is the base class for an "authenticator" representing a user and the methods available to authenticate that user. This class is also used to receive callbacks from the SSH2UserAuth with which it is used. Since this class is not abstract it can be used as is, however to be able to monitor the authentication process it is recommeded to subclass it.

The ordered list of available authentication methods is created by adding each method together with its SSH2AuthModule. The order in which modules are added is the order in which they will be used.

See Also:
SSH2UserAuth, SSH2AuthModule

Constructor Summary
SSH2Authenticator()
          Special constructor for creating an "anonymouse" authenticator.
SSH2Authenticator(java.lang.String username)
          Basic constructor most commonly used.
 
Method Summary
 void addModule(SSH2AuthModule module)
          Adds an authentication module (a class implementing SSH2AuthModule) to the list of available authentication methods.
 void addModule(java.lang.String method, SSH2AuthModule module)
          This method should only be used to add modules when one wants to asociate them with another name than the standard name that the module itself gives (method getStandardName()).
 void authError()
          Callback from SSH2UserAuth which reports that an error has occured.
 void authFailure(java.lang.String method, boolean partial)
          Callback from SSH2UserAuth which reports that the given authentication method failed.
 void authSuccess(java.lang.String method)
          Callback from SSH2UserAuth which reports that the given authentication method succeeded and that the user is now authenticated.
 void clearModules()
          Clear the list of auth modules
 void clearSensitiveData()
          Clears sensitive data from all modules
 void displayBanner(java.lang.String banner)
          Callback from SSH2UserAuth which gives a banner message as part of the authentication.
 java.lang.String getMethods()
          Gets a comma separated list of the authentication methods currently set.
 SSH2AuthModule getModule(java.lang.String method)
          Gets the SSH2AuthModule implementing the given authentication method.
 java.lang.String getUpdatedMethods()
          Gets an updated list of possible authentication methods.
 java.lang.String getUsername()
          Gets the name of the user we represent.
 void moduleCancel(java.lang.String method, java.lang.String reason)
          Callback from SSH2UserAuth which reports that the user canceled the given authentication method.
 void moduleFailure(java.lang.String method, SSH2Exception e)
          Callback from SSH2UserAuth which reports that an exception occured while running the given authentication method.
 void noMoreMethods()
          Callback from SSH2UserAuth which reports that there are no more authentication methods left to try to authenticate with.
 void peerMethods(java.lang.String methods)
          Callback from SSH2UserAuth which gives the available authentication methods as reported by peer.
 void removeModule(java.lang.String method)
          Removes the module associated with the given authentication method from the list of available methods.
 void setUsername(java.lang.String username)
          Sets the name of the user to be represented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSH2Authenticator

public SSH2Authenticator()
Special constructor for creating an "anonymouse" authenticator. Note, when using this constructor the username has to be set before authentication using the method setUsername.


SSH2Authenticator

public SSH2Authenticator(java.lang.String username)
Basic constructor most commonly used.

Parameters:
username - the name of the user we represent
Method Detail

getMethods

public java.lang.String getMethods()
Gets a comma separated list of the authentication methods currently set.

Returns:
a comma separated list of authentication methods

getUpdatedMethods

public java.lang.String getUpdatedMethods()
                                   throws SSH2Exception
Gets an updated list of possible authentication methods. This will be called if a method failed with the partial flag set. This method may return a new list of auth methods (or null which means keep the old one).

Returns:
a comma separated list of authentication methods
Throws:
SSH2Exception

getUsername

public java.lang.String getUsername()
Gets the name of the user we represent.

Returns:
the name of the user we represent

setUsername

public void setUsername(java.lang.String username)
Sets the name of the user to be represented.

Parameters:
username - the name of the user to be represented

displayBanner

public void displayBanner(java.lang.String banner)
Callback from SSH2UserAuth which gives a banner message as part of the authentication. As defined in the spec. of the userauth protocol. This method does nothing, it should be implemented in a subclass.

Parameters:
banner - the banner message

getModule

public SSH2AuthModule getModule(java.lang.String method)
Gets the SSH2AuthModule implementing the given authentication method.

Parameters:
method - the authentication method wanted

peerMethods

public void peerMethods(java.lang.String methods)
Callback from SSH2UserAuth which gives the available authentication methods as reported by peer. The list is comma separated. This method does nothing, it should be implemented in a subclass.

Parameters:
methods - the comma separated list of methods

noMoreMethods

public void noMoreMethods()
Callback from SSH2UserAuth which reports that there are no more authentication methods left to try to authenticate with. This method does nothing, it should be implemented in a subclass.


moduleFailure

public void moduleFailure(java.lang.String method,
                          SSH2Exception e)
Callback from SSH2UserAuth which reports that an exception occured while running the given authentication method. This method does nothing, it should be implemented in a subclass.

Parameters:
method - the authentication method that failed
e - the exception that occured in that method's module

moduleCancel

public void moduleCancel(java.lang.String method,
                         java.lang.String reason)
Callback from SSH2UserAuth which reports that the user canceled the given authentication method. That is a SSH2UserCancelException was thrown from the current SSH2AuthModule. This method does nothing, it should be implemented in a subclass.

Parameters:
method - the authentication method that was canceled
reason - a string giving the reason for cancelation if any

authFailure

public void authFailure(java.lang.String method,
                        boolean partial)
Callback from SSH2UserAuth which reports that the given authentication method failed. This is not an error, authentication will continue if more methods are available. This method does nothing, it should be implemented in a subclass.

Parameters:
method - the authentication method that failed
partial - a boolean indicating if this failure was a partial success or not (i.e. the method succeeded but more methods are needed for full authentication).

authSuccess

public void authSuccess(java.lang.String method)
Callback from SSH2UserAuth which reports that the given authentication method succeeded and that the user is now authenticated. This method does nothing, it should be implemented in a subclass.

Parameters:
method - the authentication method that succeeded

authError

public void authError()
Callback from SSH2UserAuth which reports that an error has occured. That is the server disconnected or that the authentication has been explicitly terminated (someone called the method terminate in SSH2UserAuth) and that the authentication is aborted. This method does nothing, it should be implemented in a subclass.


addModule

public final void addModule(SSH2AuthModule module)
Adds an authentication module (a class implementing SSH2AuthModule) to the list of available authentication methods. The module is added last in the current list, hence modules must be added in the order of preference.

Parameters:
module - the authentication module

addModule

public final void addModule(java.lang.String method,
                            SSH2AuthModule module)
This method should only be used to add modules when one wants to asociate them with another name than the standard name that the module itself gives (method getStandardName()).

Parameters:
method - the name of the module used in the userauth protocol
module - the authentication module

removeModule

public final void removeModule(java.lang.String method)
Removes the module associated with the given authentication method from the list of available methods.


clearModules

public final void clearModules()
Clear the list of auth modules


clearSensitiveData

public void clearSensitiveData()
Clears sensitive data from all modules