public abstract class QuickAuthenticator extends java.lang.Object implements Authenticator
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;
}
}
}
Constructor and Description |
---|
QuickAuthenticator() |
Modifier and Type | Method and Description |
---|---|
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.
|
public abstract boolean askAuthorisation(ClientHandler clientHandler) throws java.io.IOException, AppException
Authenticator
QuickServer
if Authenticator was set, to authenticate any client
connection.askAuthorisation
in interface Authenticator
java.io.IOException
- if there is socket errorAppException
- if ServerAuthenticator wants QuickServer to close the
client connection. public void sendString(ClientHandler clientHandler, java.lang.String msg) throws java.io.IOException
msg
- Message to send.
If null
is passed it will not send any thing.java.io.IOException
public java.lang.String askStringInput(ClientHandler clientHandler, java.lang.String msg) throws java.io.IOException
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.java.io.IOException
- if an I/O error occurspublic void sendObject(ClientHandler clientHandler, java.lang.Object msg) throws java.io.IOException
msg
- Message to send.
If null
is passed it will not send any thing.java.io.IOException
public java.lang.Object askObjectInput(ClientHandler clientHandler, java.lang.Object msg) throws java.io.IOException, java.lang.ClassNotFoundException
msg
- Message to send before reading input.
If null
is passed it will not send any thing.null
it will throw ConnectionLostException
.java.io.IOException
- if an I/O error occursjava.lang.ClassNotFoundException
public void sendByte(ClientHandler clientHandler, java.lang.String msg) throws java.io.IOException
msg
- Message to send.
If null
is passed it will not send any thing.java.io.IOException
public java.lang.String askByteInput(ClientHandler clientHandler, java.lang.String msg) throws java.io.IOException
msg
- Message to send before reading input.
If null
is passed it will not send any thing.null
it will throw ConnectionLostException
.java.io.IOException
- if an I/O error occurspublic void sendBinary(ClientHandler clientHandler, byte[] msg) throws java.io.IOException
msg
- binary data to send.
If null
is passed it will not send any thing.java.io.IOException
public byte[] askBinaryInput(ClientHandler clientHandler, byte[] msg) throws java.io.IOException
msg
- binary data to send before reading input.
If null
is passed it will not send any thing.null
it will throw ConnectionLostException
.java.io.IOException
- if an I/O error occursCopyright © 2003-2014 QuickServer.org