com.sshtools.j2ssh.authentication
Class AuthenticationProtocol

java.lang.Object
  |
  +--com.sshtools.j2ssh.transport.Service
        |
        +--com.sshtools.j2ssh.authentication.AuthenticationProtocol
All Implemented Interfaces:
java.lang.Runnable

public class AuthenticationProtocol
extends Service

Implements the SSH Authentication protocol as a Transport layer service. This class can authenticate with any authentication object implementing the SshAuthentication interface and returns the success, partial success or failure result synchronously.

The authentication process is as follows:

The authentication service is started
The server MAY reply with a banner message (which can be retreived using getBannerMessage
The user MAY request the list of available authorizations by calling getAvailableAuths
The user MUST request authentication by calling authenticate for each method they wish to try (with the Service instance to start)
The server responds with a success message and the desired service is started

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Constructor Summary
AuthenticationProtocol()
          Constructor for the AuthenticationProtocol
 
Method Summary
 int authenticate(SshAuthentication auth, Service serviceToStart)
           Authenticate a user with the given authentication method.
 java.util.List getAvailableAuths(java.lang.String username, java.lang.String serviceName)
           Gets the available authentication methods returned by the server.
 java.lang.String getBannerMessage()
           Gets the authentication banner message received from the server.
 AuthenticationProtocolState getState()
           Gets the current state of the authentication protocol.
 void onDisconnect(java.lang.String reason)
           Called by the framework if the remote computer disconnects.
protected  void onMessageReceived(SshMessage msg)
           Called by the Service framework when a registered message has been received.
protected  void onServiceAccept()
           Abstract method implementation called when the service is accepted by the server.
 void onServiceInit()
           Called by the framework when the service is initialized.
protected  void onServiceRequest()
           Abstract method implementation called when the service is request by a remote client.
protected  void onThreadException(java.lang.Exception e)
           Called by the framework when a exception occurs in a child thread
 
Methods inherited from class com.sshtools.j2ssh.transport.Service
getExchangeHash, getMessageStore, getServiceName, getTransportLayer, run, start, stop, waitForSingleMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthenticationProtocol

public AuthenticationProtocol()
Constructor for the AuthenticationProtocol

Method Detail

onServiceInit

public void onServiceInit()
                   throws ServiceOperationException

Called by the framework when the service is initialized. We do not currently perform any processing here.

Specified by:
onServiceInit in class Service
Throws:
ServiceOperationException

onDisconnect

public void onDisconnect(java.lang.String reason)

Called by the framework if the remote computer disconnects.

Specified by:
onDisconnect in class Service
Parameters:
reason - The reason for disconnection

onServiceAccept

protected void onServiceAccept()
                        throws ServiceOperationException

Abstract method implementation called when the service is accepted by the server. We register client side message notifications here.

Specified by:
onServiceAccept in class Service
Throws:
ServiceOperationException - Thrown if a message registration error occurs

onServiceRequest

protected void onServiceRequest()

Abstract method implementation called when the service is request by a remote client.

NOTE: The Authentication Protocol currently does not implement and processing here; we should register server side messages here.

Specified by:
onServiceRequest in class Service

onThreadException

protected void onThreadException(java.lang.Exception e)

Called by the framework when a exception occurs in a child thread

Specified by:
onThreadException in class Service
Parameters:
e - The excpetion thrown

getState

public AuthenticationProtocolState getState()

Gets the current state of the authentication protocol.

Returns:
The AuthenticationProtocolState

getBannerMessage

public java.lang.String getBannerMessage()

Gets the authentication banner message received from the server. This may be null.

Returns:
The banner message

onMessageReceived

protected void onMessageReceived(SshMessage msg)
                          throws ServiceOperationException,
                                 TransportProtocolException

Called by the Service framework when a registered message has been received.

Specified by:
onMessageReceived in class Service
Parameters:
msg - The message received
Throws:
ServiceOperationException
TransportProtocolException

getAvailableAuths

public java.util.List getAvailableAuths(java.lang.String username,
                                        java.lang.String serviceName)
                                 throws TransportProtocolException

Gets the available authentication methods returned by the server.

NOTE: The authentication protocol states that the server may return authentication methods that are not valid for the user.

Parameters:
username - The username to request authentication methods for
serviceName - The service name to start
Returns:
The list of authentication methods
Throws:
TransportProtocolException - Description of the Exception

authenticate

public int authenticate(SshAuthentication auth,
                        Service serviceToStart)
                 throws TransportProtocolException,
                        AuthenticationProtocolException,
                        ServiceOperationException

Authenticate a user with the given authentication method.

Parameters:
auth - The authentication method instance to try.
serviceToStart - The service instance to start.
Returns:
The result of the authentication; this is an AuthenticationProtocolState value.
Throws:
AuthenticationProtocolException
ServiceOperationException
TransportProtocolException - Description of the Exception


Copyright © 2002 Sshtools.com. All Rights Reserved.