QuickServer
v1.4.7

org.quickserver.net.server
Class QuickAuthenticator

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

public abstract class QuickAuthenticator
extends java.lang.Object
implements Authenticator

This class is used to authenticate a client when it connects to QuickServer. Only single instance of this class will be used per QuickServer to handle all authentication. Should have a default constructor.

Ex:

 package echoserver;

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

public class EchoServerQuickAuthenticator extends QuickAuthenticator {

        public boolean askAuthorisation(ClientHandler clientHandler) 
                        throws IOException {		
                String username = askStringInput(clientHandler, "User Name :");
                String password = askStringInput(clientHandler, "Password :");

                if(username==null || password ==null)
                        return false;

                if(username.equals(password)) {
                        sendString(clientHandler, "Auth OK");
                        return true;
                } else {
                        sendString(clientHandler, "Auth Failed");
                        return false;
                }
        }
}
 

Since:
1.3
Author:
Akshathkumar Shetty

Constructor Summary
QuickAuthenticator()
           
 
Method Summary
abstract  boolean askAuthorisation(ClientHandler clientHandler)
          This method is called by QuickServer if Authenticator was set, to authenticate any client connection.
 byte[] askBinaryInput(ClientHandler clientHandler, byte[] msg)
          Sends the given binary data to the client and reads binary data input.
 java.lang.String askByteInput(ClientHandler clientHandler, java.lang.String msg)
          Prints the given message to the client and reads a line of input.
 java.lang.Object askObjectInput(ClientHandler clientHandler, java.lang.Object msg)
          Prints the given message to the client and reads a Object from input.
 java.lang.String askStringInput(ClientHandler clientHandler, java.lang.String msg)
          Prints the given message to the client and reads a line of input.
 void sendBinary(ClientHandler clientHandler, byte[] msg)
          Sends the given binary data to the client.
 void sendByte(ClientHandler clientHandler, java.lang.String msg)
          Prints the given message to the client.
 void sendObject(ClientHandler clientHandler, java.lang.Object msg)
          Sends the given object to the client.
 void sendString(ClientHandler clientHandler, java.lang.String msg)
          Prints the given message to the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuickAuthenticator

public QuickAuthenticator()
Method Detail

askAuthorisation

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

Specified by:
askAuthorisation in interface Authenticator
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

sendString

public void sendString(ClientHandler clientHandler,
                       java.lang.String msg)
                throws java.io.IOException
Prints the given message to the client.

Parameters:
msg - Message to send. If null is passed it will not send any thing.
Throws:
java.io.IOException

askStringInput

public java.lang.String askStringInput(ClientHandler clientHandler,
                                       java.lang.String msg)
                                throws java.io.IOException
Prints the given message to the client and reads a line of input.

Parameters:
msg - Message to send before reading input. If received String is null it will throw ConnectionLostException. If null is passed it will not send any thing.
Returns:
the line of input read from the client.
Throws:
java.io.IOException - if an I/O error occurs

sendObject

public void sendObject(ClientHandler clientHandler,
                       java.lang.Object msg)
                throws java.io.IOException
Sends the given object to the client.

Parameters:
msg - Message to send. If null is passed it will not send any thing.
Throws:
java.io.IOException

askObjectInput

public java.lang.Object askObjectInput(ClientHandler clientHandler,
                                       java.lang.Object msg)
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
Prints the given message to the client and reads a Object from input.

Parameters:
msg - Message to send before reading input. If null is passed it will not send any thing.
Returns:
the Object from input read from the client. If received Object is null it will throw ConnectionLostException.
Throws:
java.io.IOException - if an I/O error occurs
java.lang.ClassNotFoundException

sendByte

public void sendByte(ClientHandler clientHandler,
                     java.lang.String msg)
              throws java.io.IOException
Prints the given message to the client.

Parameters:
msg - Message to send. If null is passed it will not send any thing.
Throws:
java.io.IOException
Since:
1.3.2

askByteInput

public java.lang.String askByteInput(ClientHandler clientHandler,
                                     java.lang.String msg)
                              throws java.io.IOException
Prints the given message to the client and reads a line of input.

Parameters:
msg - Message to send before reading input. If null is passed it will not send any thing.
Returns:
the line of input read from the client. If received byte is null it will throw ConnectionLostException.
Throws:
java.io.IOException - if an I/O error occurs
Since:
1.3.2

sendBinary

public void sendBinary(ClientHandler clientHandler,
                       byte[] msg)
                throws java.io.IOException
Sends the given binary data to the client.

Parameters:
msg - binary data to send. If null is passed it will not send any thing.
Throws:
java.io.IOException
Since:
1.4

askBinaryInput

public byte[] askBinaryInput(ClientHandler clientHandler,
                             byte[] msg)
                      throws java.io.IOException
Sends the given binary data to the client and reads binary data input.

Parameters:
msg - binary data to send before reading input. If null is passed it will not send any thing.
Returns:
the binary data input read from the client. If received byte is null it will throw ConnectionLostException.
Throws:
java.io.IOException - if an I/O error occurs
Since:
1.4

QuickServer
v1.4.7

Copyright © 2003-2006 QuickServer.org