|
|
@@ -136,17 +136,22 @@ public abstract class CachingUsernamePasswordRealm extends UsernamePasswordRealm
|
|
|
if (cachedResult.authenticationResult.isAuthenticated()) {
|
|
|
if (credsMatch) {
|
|
|
// cached credential hash matches the credential hash for this forestalled request
|
|
|
- handleCachedAuthentication(cachedResult.user, ActionListener.wrap(cacheResult -> {
|
|
|
- if (cacheResult.isAuthenticated()) {
|
|
|
- logger.debug("realm [{}] authenticated user [{}], with roles [{}]",
|
|
|
- name(), token.principal(), cacheResult.getUser().roles());
|
|
|
+ handleCachedAuthentication(cachedResult.user, ActionListener.wrap(authResult -> {
|
|
|
+ if (authResult.isAuthenticated()) {
|
|
|
+ logger.debug("realm [{}] authenticated user [{}], with roles [{}] (cached)",
|
|
|
+ name(), token.principal(), authResult.getUser().roles());
|
|
|
} else {
|
|
|
logger.debug("realm [{}] authenticated user [{}] from cache, but then failed [{}]",
|
|
|
- name(), token.principal(), cacheResult.getMessage());
|
|
|
+ name(), token.principal(), authResult.getMessage());
|
|
|
}
|
|
|
- listener.onResponse(cacheResult);
|
|
|
+ listener.onResponse(authResult);
|
|
|
}, listener::onFailure));
|
|
|
} else {
|
|
|
+ logger.trace(
|
|
|
+ "realm [{}], provided credentials for user [{}] do not match (known good) cached credentials," +
|
|
|
+ " invalidating cache and retrying",
|
|
|
+ name(), token.principal()
|
|
|
+ );
|
|
|
// its credential hash does not match the
|
|
|
// hash of the credential for this forestalled request.
|
|
|
// clear cache and try to reach the authentication source again because password
|
|
|
@@ -157,18 +162,42 @@ public abstract class CachingUsernamePasswordRealm extends UsernamePasswordRealm
|
|
|
} else if (credsMatch) {
|
|
|
// not authenticated but instead of hammering reuse the result. a new
|
|
|
// request will trigger a retried auth
|
|
|
+ logger.trace(
|
|
|
+ "realm [{}], provided credentials for user [{}] are invalid (cached result) status:[{}] message:[{}]",
|
|
|
+ name(),
|
|
|
+ token.principal(),
|
|
|
+ cachedResult.authenticationResult.getStatus(),
|
|
|
+ cachedResult.authenticationResult.getMessage()
|
|
|
+ );
|
|
|
listener.onResponse(cachedResult.authenticationResult);
|
|
|
} else {
|
|
|
+ logger.trace(
|
|
|
+ "realm [{}], provided credentials for user [{}] do not match (possibly invalid) cached credentials," +
|
|
|
+ " invalidating cache and retrying",
|
|
|
+ name(),
|
|
|
+ token.principal()
|
|
|
+ );
|
|
|
cache.invalidate(token.principal(), listenableCacheEntry);
|
|
|
authenticateWithCache(token, listener);
|
|
|
}
|
|
|
}, listener::onFailure), threadPool.executor(ThreadPool.Names.GENERIC), threadPool.getThreadContext());
|
|
|
} else {
|
|
|
+ logger.trace(
|
|
|
+ "realm [{}] does not have a cached result for user [{}]; attempting fresh authentication", name(), token.principal());
|
|
|
// attempt authentication against the authentication source
|
|
|
doAuthenticate(token, ActionListener.wrap(authResult -> {
|
|
|
- if (authResult.isAuthenticated() == false || authResult.getUser().enabled() == false) {
|
|
|
+ if (authResult.isAuthenticated() == false) {
|
|
|
+ logger.trace("realm [{}] did not authenticate user [{}] ([{}])", name(), token.principal(), authResult);
|
|
|
// a new request should trigger a new authentication
|
|
|
cache.invalidate(token.principal(), listenableCacheEntry);
|
|
|
+ } else if (authResult.getUser().enabled() == false) {
|
|
|
+ logger.debug(
|
|
|
+ "realm [{}] cannot authenticate [{}], user is not enabled ([{}])",
|
|
|
+ name(), token.principal(), authResult.getUser());
|
|
|
+ // a new request should trigger a new authentication
|
|
|
+ cache.invalidate(token.principal(), listenableCacheEntry);
|
|
|
+ } else {
|
|
|
+ logger.debug("realm [{}], successful authentication [{}] for [{}]", name(), authResult, token.principal());
|
|
|
}
|
|
|
// notify any forestalled request listeners; they will not reach to the
|
|
|
// authentication request and instead will use this result if they contain
|