- Suppression de l'autorisation de se connecter avec le même compte depuis plusieurs client.
This commit is contained in:
parent
60fb6390b4
commit
92ca17f6df
@ -1,5 +1,7 @@
|
|||||||
package lightcontainer.domains.client;
|
package lightcontainer.domains.client;
|
||||||
|
|
||||||
|
import lightcontainer.repository.ClientHandlerRepository;
|
||||||
|
import lightcontainer.repository.ReadOnlyClientRepository;
|
||||||
import lightcontainer.storage.File;
|
import lightcontainer.storage.File;
|
||||||
import lightcontainer.storage.ReadOnlyFile;
|
import lightcontainer.storage.ReadOnlyFile;
|
||||||
import lightcontainer.storage.Repository;
|
import lightcontainer.storage.Repository;
|
||||||
@ -18,6 +20,7 @@ public class Context {
|
|||||||
// Variables
|
// Variables
|
||||||
private final Repository repository;
|
private final Repository repository;
|
||||||
private RequestBundle requestBundle;
|
private RequestBundle requestBundle;
|
||||||
|
private ReadOnlyClientRepository clientRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login de l'utilisateur
|
* Login de l'utilisateur
|
||||||
@ -30,8 +33,9 @@ public class Context {
|
|||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
// Constructeur
|
// Constructeur
|
||||||
public Context(Repository repository) {
|
public Context(Repository repository, ReadOnlyClientRepository clientRepository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
this.clientRepository = clientRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,6 +47,10 @@ public class Context {
|
|||||||
* @return TRUE si l'utilisateur a pu être créé
|
* @return TRUE si l'utilisateur a pu être créé
|
||||||
*/
|
*/
|
||||||
public boolean createUser(String login, String password) {
|
public boolean createUser(String login, String password) {
|
||||||
|
if (clientRepository.hasClient(login)) { // Empêcher double connection
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String key = AES_GCM.generateSecretKey();
|
String key = AES_GCM.generateSecretKey();
|
||||||
String hashedPassword = BCryptHasher.hashPassword(password);
|
String hashedPassword = BCryptHasher.hashPassword(password);
|
||||||
@ -73,7 +81,12 @@ public class Context {
|
|||||||
* @return TRUE si l'utilisateur a été authentifié
|
* @return TRUE si l'utilisateur a été authentifié
|
||||||
*/
|
*/
|
||||||
public boolean signIn(String login, String password) {
|
public boolean signIn(String login, String password) {
|
||||||
if (this.repository.verifyUser(login, password)) {
|
if (login == null || password == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empêcher double connection
|
||||||
|
if (!clientRepository.hasClient(login) && this.repository.verifyUser(login, password)) {
|
||||||
this.login = login;
|
this.login = login;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class UnicastServerListener implements Runnable {
|
|||||||
SSLSocket client = (SSLSocket) this.server.accept();
|
SSLSocket client = (SSLSocket) this.server.accept();
|
||||||
|
|
||||||
// Create a new Handler client by passing these dependencies to it
|
// Create a new Handler client by passing these dependencies to it
|
||||||
ClientHandler clientHandler = new ClientHandler(this.repository, client, ffe, protocolRep, new Context(repositoryStorage));
|
ClientHandler clientHandler = new ClientHandler(this.repository, client, ffe, protocolRep, new Context(repositoryStorage, repository));
|
||||||
// Add the client handler to its repository (clienthandlerrepository)
|
// Add the client handler to its repository (clienthandlerrepository)
|
||||||
this.repository.addClient(clientHandler);
|
this.repository.addClient(clientHandler);
|
||||||
// Start the thread
|
// Start the thread
|
||||||
|
@ -5,11 +5,12 @@ import lightcontainer.domains.server.MulticastServerListener;
|
|||||||
import lightcontainer.domains.server.UnicastServerListener;
|
import lightcontainer.domains.server.UnicastServerListener;
|
||||||
import lightcontainer.protocol.ProtocolWriter;
|
import lightcontainer.protocol.ProtocolWriter;
|
||||||
import lightcontainer.repository.ClientHandlerRepository;
|
import lightcontainer.repository.ClientHandlerRepository;
|
||||||
|
import lightcontainer.repository.ReadOnlyClientRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A communication interface between a {@link ClientHandler} and the {@link ClientHandlerRepository}.
|
* A communication interface between a {@link ClientHandler} and the {@link ClientHandlerRepository}.
|
||||||
*/
|
*/
|
||||||
public interface UnicastCHR {
|
public interface UnicastCHR extends ReadOnlyClientRepository {
|
||||||
/**
|
/**
|
||||||
* Setter, allow to define the ServerListener of a repository.
|
* Setter, allow to define the ServerListener of a repository.
|
||||||
*
|
*
|
||||||
@ -24,6 +25,7 @@ public interface UnicastCHR {
|
|||||||
*/
|
*/
|
||||||
void addClient(ClientHandler client);
|
void addClient(ClientHandler client);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de demander la déconnection d'un client
|
* Permet de demander la déconnection d'un client
|
||||||
*
|
*
|
||||||
|
@ -55,6 +55,22 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
|
|||||||
this.handlers.add(client);
|
this.handlers.add(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de savoir si un client est déjà connecté avec ce login.
|
||||||
|
*
|
||||||
|
* @param login Login du client.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean hasClient(String login) {
|
||||||
|
for (ClientHandler client : handlers) {
|
||||||
|
if (client.getLogin() != null && client.getLogin().equals(login)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(ClientHandler client) {
|
public void disconnect(ClientHandler client) {
|
||||||
if (handlers.remove(client))
|
if (handlers.remove(client))
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package lightcontainer.repository;
|
||||||
|
|
||||||
|
public interface ReadOnlyClientRepository {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de savoir si un client est déjà connecté avec ce login.
|
||||||
|
*
|
||||||
|
* @param login Login du client.
|
||||||
|
*/
|
||||||
|
boolean hasClient(String login);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user