public class RegisterServer
extends java.lang.Object
implements java.lang.Runnable
RegisterServer is responsible for registering VBS clients.
The server listens on the port given in the constructor.
When a client requests to be registered it must transfer the REGISTER_KEY, otherwise registration is ignored.
If the registration is accepted a clientId is generated and transferred to the client.
Client having already an identifier does not need to register, so instead of REGISTER_KEY the identifier is transferred.
If the identifier seems to be OK (the format is valid), then the client is treated as authenticated. The current big problem is that
there is no database where the client identifier are stored and compared during the validation process, so everyone can submit any
good-looking identifier and be considered as authenticated even without ever sending the REGISTER_KEY! This can be fixed by
storing the assigned identifier in the Clients database table and then comparing if such client really exists. For now the Clients table
is filled when a FDB file is transferred from the client to the server - the client identifier is copied from the FDB file.
It is intended to run in its own thread.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CLIENT_VALIDATED_MESSAGE
Message send to the client when the client is successfully validated.
|
private static org.apache.log4j.Logger |
log
Used to log different events.
|
private java.net.ServerSocket |
myServerSocket
Socket on which the registration server listens for connection from clients.
|
private java.net.Socket |
mySocket
Socket used to transfer data to the client.
|
static java.lang.String |
REGISTER_KEY
Shared key used for registration of the client.
|
private java.lang.Thread |
registerServerThread
Thread used by the class.
|
private boolean |
runFlag
The thread will stop when this flag is
false. |
| Constructor and Description |
|---|
RegisterServer(int port)
Constructs the object.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
authenticateNewRegistrer(java.lang.String key)
Checks if the obtained string equals to the registration key.
|
private java.lang.String |
getInputFromClient()
Gets an input from the client.
|
boolean |
isAlive()
Checks if the
RegisterServer is running. |
private boolean |
isGoodLookingClient(java.lang.String clientId)
Checks if the provided client identifier looks good.
|
private void |
registerClient()
Registers the client.
|
void |
run()
Runs the thread.
|
private void |
sendValidation()
Send an authorization message to the client.
|
void |
start()
Starts the thread.
|
void |
stop()
Stops the thread.
|
private static org.apache.log4j.Logger log
private java.lang.Thread registerServerThread
public static final java.lang.String REGISTER_KEY
public static final java.lang.String CLIENT_VALIDATED_MESSAGE
private java.net.ServerSocket myServerSocket
private java.net.Socket mySocket
private boolean runFlag
false.public RegisterServer(int port)
throws java.io.IOException
port - the port which the server listen onjava.io.IOException - if the server cannot bind to the portpublic void start()
public void stop()
public boolean isAlive()
RegisterServer is running.true if the thread is fully started and operational, false otherwisepublic void run()
run in interface java.lang.Runnableprivate java.lang.String getInputFromClient()
throws java.io.IOException
java.io.IOException - when a communication problem occursprivate boolean authenticateNewRegistrer(java.lang.String key)
throws java.io.IOException
key - the string obtained from the clienttrue if the string matches the registration key, false otherwisejava.io.IOException - if a communication problem occursprivate void registerClient()
throws java.io.IOException
java.io.IOException - when a communication problem occursprivate boolean isGoodLookingClient(java.lang.String clientId)
clientId - the client identifiertrue if the client identifier looks as valid, false otherwiseprivate void sendValidation()
throws java.io.IOException
java.io.IOException - if a communication problem occurs