Christian
Christian

Reputation: 7429

TokenStorage for Authentication in Java

I have a Map containing users that have been authenticated with my system. the key is the token that's being generated, the value is the actual user instance. Now I'd like to remove a user after a certain amount of inactivity. I am more than sure, there's a mechanism available for this (something like Googles LoadingCache but specially for this situation (login/tokenstorage) Could you suggest one?

Upvotes: 0

Views: 77

Answers (1)

Alexander Pranko
Alexander Pranko

Reputation: 1969

You could use ehcache for this purposes.

It's easy to use and it allows you to define various invalidation criteria for the tokens, such as timeToIdleSeconds and timeToLiveSeconds.

Another advantage of using ehcache for tokens is out of the box clustering support. Tokens can be synchronized (or deprovisioned in case of logout) between cluster nodes.

There a few ehcache hello world examples in SO. Your can extend them with dynamic configuration to archive what you need.

Upvotes: 1

Related Questions