public class SimpleExpiryCache extends Object implements AuthenticationCache
Simple cache that has entries that expire after a certain amount of time.
Also, the cache has a JMX interface SimpleExpiryCacheManagementMBean
by which the entries for one or all users can be expired. The cache does not
do an automatic cleanup of expired items although it is possible to trigger
cleanup through JMX.
The cache exposes an MBean for remote management and for managing it from an
application. This access is unsecured so anyone can in principle clean the
cache. The main intention of the JMX MBean is to use it for invalidating the
cache for a specific user in case his authentication information has changed.
The MBean is exposed at the domain specified by JMX_DOMAIN with a
property specified by JMX_REALM_PROPERTY with the value of the
realm.
To clear a specific user, proceed as follows:
ObjectName objectName = new ObjectName(
"org.wamblee.glassfish.auth.FlexibleJdbcRealm", "realm", REALM_NAME);
ManagementFactory.getPlatformMBeanServer().invoke(objectName, "clearUser",
new Object[] { "username" }, new String[] { String.class.getName() });
| Modifier and Type | Class and Description |
|---|---|
static interface |
SimpleExpiryCache.Clock |
static class |
SimpleExpiryCache.SystemClock |
static class |
SimpleExpiryCache.UserEntry
Class representing cached information about a user.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_EXPIRY_TIME_SECONDS
Default expiry time in seconds.
|
static String |
JMX_DOMAIN |
static String |
PROP_EXPIRY_TIME_SECONDS
Name of the property that defines the timeout in seconds for caching.
|
static String |
PROP_REALM_NAME |
| Constructor and Description |
|---|
SimpleExpiryCache(Properties aProperties)
Constructs the cache.
|
SimpleExpiryCache(Properties aProperties,
SimpleExpiryCache.Clock aClock)
Constructor for unit test.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearExpired() |
SimpleExpiryCache.UserEntry |
evict(String aUsername) |
int |
getExpiryTimeSeconds() |
List<String> |
getGroups(String aUsername)
Gets the groups a user belongs to from the cache.
|
String |
getPassword(String aUsername)
Gets the cached password for a given user.
|
String |
getSeed(String aUsername)
Gets a cached seed for a given username based on the configured sql seed query.
|
void |
setGroups(String aUsername,
List<String> aGroups)
Sets the groups for a given user.
|
void |
setPassword(String aUserName,
String aPassword)
Sets the cached password for a user.
|
void |
setSeed(String aUsername,
String aSeed)
Sets the seed.
|
int |
size() |
String |
toString() |
public static final String PROP_EXPIRY_TIME_SECONDS
public static final String JMX_DOMAIN
public static final String PROP_REALM_NAME
public static final long DEFAULT_EXPIRY_TIME_SECONDS
public SimpleExpiryCache(Properties aProperties)
aProperties - Properties to configure the cache with.public SimpleExpiryCache(Properties aProperties, SimpleExpiryCache.Clock aClock)
aProperties - Properties.aClock - Clock.protected void clearExpired()
public int getExpiryTimeSeconds()
public int size()
public List<String> getGroups(String aUsername)
AuthenticationCachegetGroups in interface AuthenticationCacheaUsername - User.public String getPassword(String aUsername)
AuthenticationCachegetPassword in interface AuthenticationCacheaUsername - Username.public String getSeed(String aUsername)
AuthenticationCachegetSeed in interface AuthenticationCacheaUsername - Username.public void setGroups(String aUsername, List<String> aGroups)
AuthenticationCachesetGroups in interface AuthenticationCacheaUsername - User name.aGroups - Groups (must be non-null).public void setPassword(String aUserName, String aPassword)
AuthenticationCachesetPassword in interface AuthenticationCacheaUserName - Username.aPassword - Password.public void setSeed(String aUsername, String aSeed)
AuthenticationCachesetSeed in interface AuthenticationCacheaUsername - Username.aSeed - Seed (may not be null).public SimpleExpiryCache.UserEntry evict(String aUsername)
Copyright © 2019. All rights reserved.