com.mindbright.ssh2
public class SSH2Authenticator extends java.lang.Object
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.
SSH2UserAuth
,
SSH2AuthModule
Constructor and Description |
---|
SSH2Authenticator()
Special constructor for creating an "anonymouse" authenticator.
|
SSH2Authenticator(java.lang.String username)
Basic constructor most commonly used.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public SSH2Authenticator()
setUsername
.public SSH2Authenticator(java.lang.String username)
username
- the name of the user we representpublic java.lang.String getMethods()
public java.lang.String getUpdatedMethods()
public java.lang.String getUsername()
public void setUsername(java.lang.String username)
username
- the name of the user to be representedpublic void displayBanner(java.lang.String banner)
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.banner
- the banner messagepublic SSH2AuthModule getModule(java.lang.String method)
SSH2AuthModule
implementing the given
authentication method.method
- the authentication method wantedpublic void peerMethods(java.lang.String methods)
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.methods
- the comma separated list of methodspublic void noMoreMethods()
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.public void moduleFailure(java.lang.String method, SSH2Exception e)
SSH2UserAuth
which reports that an exception
occured while running the given authentication method. This method does
nothing, it should be implemented in a subclass.method
- the authentication method that failede
- the exception that occured in that method's modulepublic void moduleCancel(java.lang.String method, java.lang.String reason)
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.method
- the authentication method that was canceledreason
- a string giving the reason for cancelation if anypublic void authFailure(java.lang.String method, boolean partial)
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.method
- the authentication method that failedpartial
- 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).public void authSuccess(java.lang.String method)
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.method
- the authentication method that succeededpublic void authError()
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.public final void addModule(SSH2AuthModule module)
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.module
- the authentication modulepublic final void addModule(java.lang.String method, SSH2AuthModule module)
getStandardName()
).method
- the name of the module used in the userauth protocolmodule
- the authentication modulepublic final void removeModule(java.lang.String method)
public final void clearModules()
public void clearSensitiveData()