I have got a requirement where i need to ensure that no user can do multiple login So for this , i have made it login system centralized that is once the User successflly logs in , i am storing it in a Authenticator class as shown below and removing it from the HashMap once user clicks on log out
public final class Authenticator {
private static Authenticator authenticator = null;
Map<String, String> usersStorage = new HashMap<String,String>();
private Authenticator() {}
public static Authenticator getInstance() {
if ( authenticator == null ) {
authenticator = new Authenticator();
}
return authenticator;
}
public Map<String, String> getusersStorage() {
return usersStorage;
}
}
Upto this , everything is working good .
I have got some negative scenarios to handle also that is
- User can close the browser without clicking on Logout (Ctrl + W / browser cross Mark Button)
In that case is to possible to remove the key and Value from HashMap , if its idle for 15 minutes ??
please share your ideas of approaching this requirement .