org.esupportail.cas.server.util
Class Server

java.lang.Object
  extended by org.esupportail.cas.server.util.log.Debug
      extended by org.esupportail.cas.server.util.Server
Direct Known Subclasses:
DatabaseServer, LdapServer, NisServer, NtServer

public abstract class Server
extends Debug

This abstract class implements a generic server class, inherited by DatabaseServer and LDAPServer.

Author:
Pascal Aubry

Field Summary
protected static int AUTHENTICATE_FAILURE
          The result of the authenticate() method on failure (when the server could not be accessed for instance).
protected static int AUTHENTICATE_NOAUTH
          The result of the authenticate() method when the user could not be authenticated (but the server was accessed without any problem).
protected static int AUTHENTICATE_SUCCESS
          The result of the authenticate() method on success (when the user has been authenticated).
protected static int CONNECT_FAILURE
          The error code set by the connect() method when the connection with the server could not be achieved because of a service failure.
protected static int CONNECT_NOAUTH
          The error code set by the connect() method when the connection with the server could not be achieved because of the bind information provided (the server responded but refused the connection).
protected static int CONNECT_SUCCESS
          The error set by the connect() method on success.
private  int connectError
          an integer to store the error code of the connect() calls, set by setConnectError(), retrieved by getConnectError().
private  RedundantHandler handler
          The handler the server will be used for.
 
Constructor Summary
Server(java.lang.Boolean handlerDebug, RedundantHandler parentHandler, org.dom4j.Element serverElement)
          Constructor.
 
Method Summary
protected abstract  int authenticate(java.lang.String username, java.lang.String password)
          Try to authenticate a user.
protected  int getConnectError()
          Retrieve the error code of the last connect() call.
protected  RedundantHandler getHandler()
          Get the handler the server will be used by.
protected  java.lang.String getServerSubElementContent(org.dom4j.Element serverElement, java.lang.String elementName, boolean needed)
          Retrieve the content of a server sub-element.
protected  void setConnectError(int errCode)
          Set the error code of the last connect() call.
 
Methods inherited from class org.esupportail.cas.server.util.log.Debug
checkClass, elementDebugValue, isDebug, setDebug, trace, trace, traceBegin, traceEnd, traceEnd, traceEnd, traceThrow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTHENTICATE_FAILURE

protected static final int AUTHENTICATE_FAILURE
The result of the authenticate() method on failure (when the server could not be accessed for instance). When testing many servers, the next server will be called.

See Also:
Constant Field Values

AUTHENTICATE_NOAUTH

protected static final int AUTHENTICATE_NOAUTH
The result of the authenticate() method when the user could not be authenticated (but the server was accessed without any problem). When testing many servers, the next servers will not be called.

See Also:
Constant Field Values

AUTHENTICATE_SUCCESS

protected static final int AUTHENTICATE_SUCCESS
The result of the authenticate() method on success (when the user has been authenticated).

See Also:
Constant Field Values

CONNECT_FAILURE

protected static final int CONNECT_FAILURE
The error code set by the connect() method when the connection with the server could not be achieved because of a service failure. Returned by getConnectError().

See Also:
Constant Field Values

CONNECT_NOAUTH

protected static final int CONNECT_NOAUTH
The error code set by the connect() method when the connection with the server could not be achieved because of the bind information provided (the server responded but refused the connection). Returned by getConnectError().

See Also:
Constant Field Values

CONNECT_SUCCESS

protected static final int CONNECT_SUCCESS
The error set by the connect() method on success.

See Also:
Constant Field Values

connectError

private int connectError
an integer to store the error code of the connect() calls, set by setConnectError(), retrieved by getConnectError().


handler

private RedundantHandler handler
The handler the server will be used for.

Constructor Detail

Server

public Server(java.lang.Boolean handlerDebug,
              RedundantHandler parentHandler,
              org.dom4j.Element serverElement)
Constructor.

Parameters:
handlerDebug - debugging mode
parentHandler - the handler the server will be used by
serverElement - an XML element corresponding to the server configuration
Method Detail

authenticate

protected abstract int authenticate(java.lang.String username,
                                    java.lang.String password)
Try to authenticate a user.

Parameters:
username - the user's name
password - the user's password
Returns:
Server.AUTHENTICATE_SUCCESS, Server.AUTHENTICATE_NOAUTH or Server.AUTHENTICATE_FAILURE.

getConnectError

protected final int getConnectError()
Retrieve the error code of the last connect() call.

Returns:
Server.CONNECT_SUCCESS, Server.CONNECT_NOAUTH or Server.CONNECT_FAILURE.

getHandler

protected final RedundantHandler getHandler()
Get the handler the server will be used by.

Returns:
a RedundantHandler object.

getServerSubElementContent

protected final java.lang.String getServerSubElementContent(org.dom4j.Element serverElement,
                                                            java.lang.String elementName,
                                                            boolean needed)
                                                     throws java.lang.Exception
Retrieve the content of a server sub-element.

Parameters:
serverElement - the XML element representing the server in the configuration
elementName - the name of the XML element to look for
needed - false if the element can be absent or empty, true otherwise
Returns:
a String
Throws:
java.lang.Exception - Exception

setConnectError

protected final void setConnectError(int errCode)
Set the error code of the last connect() call.

Parameters:
errCode - an integer equal to Server.CONNECT_SUCCESS, Server.CONNECT_NOAUTH or Server.CONNECT_FAILURE.