I work with a Java server at the enterprise level and I need to create token based authentication. The front end uses PHP and communicates with the back end of Java via SOAP.
I was thinking of using Guava HashBiMap to help me solve this problem. This would be useful for me, because I could generate UUID tokens as keys and store User objects as values ββin a static HashBiMap. When the user first successfully logs in, the User will be added to the HashBiMap, and the response to the input will return the generated UUID token. Subsequent SOAP requests for the same user will be made using only the token.
The problem I'm currently facing is the need for some sort of eviction logic that would allow these tokens to be squeezed out after 30 minutes of inactivity. In my research, it turned out that HashBiMap does not support eviction like Guava MapMaker .
Does anyone have any recommendations on how I can use HashBiMap and support eviction for inaction? If this approach is not perfect, I am open to other strategies.
Update:
I think I need to use HashBiMap because I want to be able to search for the User object on the map and get my existing token if the User is still on the map. For example, if a user closes his browser within a 30-minute window, and after a few minutes returns and logs in again, I need to check if the user exists on the map so that I can return my existing token (since it is still technically valid).
source share