QuickServer
v1.4.5

org.quickserver.net.server
Class ServerAuthenticator

java.lang.Object
  extended byorg.quickserver.net.server.ServerAuthenticator
All Implemented Interfaces:
Authenticator

public class ServerAuthenticator
extends java.lang.Object
implements Authenticator

This class is used to authenticate a client when it connects to QuickServer.

Every client connected will have separate instance of this class which will be used to handle the authentication. If single instance is needed use QuickAuthenticator. You should only use this class if your authentication need you to have dedicate an object.
Recommendations to be followed when extending ServerAuthenticator.

Ex:

package echoserver;

import org.quickserver.net.server.*;
import java.io.*;

public class MyServerAuthenticator extends ServerAuthenticator {

        public boolean askAuthorisation() throws IOException {		
                pout.println("User Name :");
                username=in.readLine();
                pout.println("Password :");
                password=in.readLine();

                if(username==null || password ==null)
                        return false;
                if(username.equals(password))
                        return true;
                else {
                        pout.println("Auth Failed");
                        return false;
                }
        }
}
 

Author:
Akshathkumar Shetty

Field Summary
protected  ClientData data
           
protected  java.lang.String error
           
protected  ClientHandler handler
           
protected  java.io.BufferedReader in
          Client input BufferedReader
protected  java.io.OutputStream out
          Client output OutputStream
protected  java.lang.String password
          Member to store password
protected  java.io.PrintWriter pout
          Client output PrintWriter
protected  java.lang.String username
          Member to store username
 
Constructor Summary
ServerAuthenticator()
           
 
Method Summary
 boolean askAuthorisation()
          This method is called by QuickServer if ServerAuthenticator was set, to authenticate any client connection.
 boolean askAuthorisation(ClientHandler clientHandler)
          This method is called by QuickServer if ServerAuthenticator was set, to authenticate any client connection.
 void cleanup()
          Called by ClientHandler ones.
 ClientData getClientData()
          Return ClientData object associated with Client being authenticated or null if no ClientData was set in QuickServer object.
 ClientHandler getClientHandler()
          Returns ClientHandler object associated with Client being authenticated.
 java.lang.String getError()
          Gives description for last Authorisation failure if any.
 boolean getFreeOnUse()
          Returns if ServerAuthenticator should be freed after client is authenticated.
 void setClientHandler(ClientHandler handler)
          Sets ClientHandler object associated with Client being authenticated.
 void setError(java.lang.String error)
          Sets description for last Authorisation failure if any.
 void setFreeOnUse(boolean flag)
          Sets if ServerAuthenticator should be freed after client is authenticated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

error

protected java.lang.String error

in

protected java.io.BufferedReader in
Client input BufferedReader


out

protected java.io.OutputStream out
Client output OutputStream


pout

protected java.io.PrintWriter pout
Client output PrintWriter


data

protected ClientData data

handler

protected ClientHandler handler

username

protected java.lang.String username
Member to store username


password

protected java.lang.String password
Member to store password

Constructor Detail

ServerAuthenticator

public ServerAuthenticator()
Method Detail

askAuthorisation

public boolean askAuthorisation()
                         throws java.io.IOException,
                                AppException
This method is called by QuickServer if ServerAuthenticator was set, to authenticate any client connection.

Returns:
result of authentication.
Throws:
AppException - if ServerAuthenticator wants QuickServer to close the client connection.
Can be used for exiting on Timeouts
Can be used when Quit commands is received when Authenticating.
java.io.IOException - if there is socket error

askAuthorisation

public boolean askAuthorisation(ClientHandler clientHandler)
                         throws java.io.IOException,
                                AppException
Description copied from interface: Authenticator
This method is called by QuickServer if ServerAuthenticator was set, to authenticate any client connection.

Specified by:
askAuthorisation in interface Authenticator
Returns:
result of authentication.
Throws:
java.io.IOException - if there is socket error
AppException - if ServerAuthenticator wants QuickServer to close the client connection.
Can be used for exiting on Timeouts
Can be used when Quit commands is received when Authenticating.

getError

public java.lang.String getError()
Gives description for last Authorisation failure if any. Ones getError() is called the error gets reset to null

Returns:
error description for last Authorisation failure.

setError

public void setError(java.lang.String error)
Sets description for last Authorisation failure if any.

Since:
1.3

cleanup

public void cleanup()
Called by ClientHandler ones. Used to close any resources that was opened by the inheriting class. Do call the base class version eg: super.cleanup() if you override. This will set all io/output streams, data, handler to null.


getClientData

public ClientData getClientData()
Return ClientData object associated with Client being authenticated or null if no ClientData was set in QuickServer object.


setClientHandler

public final void setClientHandler(ClientHandler handler)
Sets ClientHandler object associated with Client being authenticated.

See Also:
getClientHandler()

getClientHandler

public ClientHandler getClientHandler()
Returns ClientHandler object associated with Client being authenticated. Can be used to find out more information about the client, like ip eg:
getClientHandler().getSocket().getInetAddress()


setFreeOnUse

public void setFreeOnUse(boolean flag)
Sets if ServerAuthenticator should be freed after client is authenticated. If set true QuickServer will set ServerAuthenticator to null ones client is authenticated. Default is true

Since:
1.3
See Also:
getFreeOnUse()

getFreeOnUse

public boolean getFreeOnUse()
Returns if ServerAuthenticator should be freed after client is authenticated. Default is true

Since:
1.3
See Also:
setFreeOnUse(boolean)

QuickServer
v1.4.5

Copyright © 2003-2005 QuickServer.org