You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by w0lfshad3 <w0...@yahoo.com> on 2012/03/30 09:22:59 UTC

how to log out programatically; authentication cache problem

I breakpoint on this line during login:
((JNDIAndSaltAwareJdbcRealm)r).getAuthenticationCache();

which returns null in this:

public class JNDIAndSaltAwareJdbcRealm extends JdbcRealm {
...
protected SaltedAuthenticationInfo
doGetAuthenticationInfo(AuthenticationToken token) throws
AuthenticationException {
...
for (Realm r : ((RealmSecurityManager) SecurityUtils
				.getSecurityManager()).getRealms())
			if (JNDIAndSaltAwareJdbcRealm.class.isInstance(r)) {
				((JNDIAndSaltAwareJdbcRealm)r).getAuthenticationCache();
			}
...
}
}

I need to log out a given user that is currently logged in programmatically,
for the following use case and perhaps an admin command later.

The use case is this:
I've implemented logic for preventing an account being logged into
concurrently.
Suppose that somehow someone enters in possession of the user/password of
the account creator and uses his account w/ or w/o his permission. I want to
give the main user/creator, the one who registered the account and knows its
email, the ability to reclaim his account by doing the following:
> use an "I forgot my password" link
> enter account email (unique)
> get a confirmation link in email
> on link activation, the password is changed and all other instances of the
> account must be logged out (only one can exist, because there can't be any
> two other logged in at one time); the user gets the new password in his
> email (and recommended to change it after login)

That way the account is recoverable.

So the question is:

How to log out a logged in account programmatically?

--
View this message in context: http://shiro-user.582556.n2.nabble.com/how-to-log-out-programatically-authentication-cache-problem-tp7420486p7420486.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: how to log out another user programatically; authentication cache problem

Posted by w0lfshad3 <w0...@yahoo.com>.
I've set jndiSaltedJdbcRealm.authenticationCachingEnabled = true
doesn't work

I've even set:
public JNDIAndSaltAwareJdbcRealm() {
		setAuthenticationCachingEnabled(true);
	}
In my realm's constructor, but authenticationCachingEnabled is still false
when evaluating in 
AuthenticatingRealm.getAvailableAuthenticationCache();



I've enabled the cache doing this in my application instance initialization
	for (Realm r : ((RealmSecurityManager) SecurityUtils
				.getSecurityManager()).getRealms())
			if (JNDIAndSaltAwareJdbcRealm.class.isInstance(r)) {
				Cache cache = ((JNDIAndSaltAwareJdbcRealm) r).getCacheManager()
						.getCache(
								JNDIAndSaltAwareJdbcRealm.class.getName()
										+ ".authenticationCache");
				((JNDIAndSaltAwareJdbcRealm) r).setAuthenticationCache(cache);
			}
			
			
			

but, AuthenticatingRealm.isAuthenticationCachingEnabled(token, info) always
returns false in
in
private void
AuthenticatingRealm.cacheAuthenticationInfoIfPossible(AuthenticationToken
token, AuthenticationInfo info) {
        if (!isAuthenticationCachingEnabled(token, info)) {
            log.debug("AuthenticationInfo caching is disabled for info [{}]. 
Submitted token: [{}].", info, token);
            //return quietly, caching is disabled for this token/info pair:
            return;
        }

        Cache<Object, AuthenticationInfo> cache =
getAvailableAuthenticationCache();
        if (cache != null) {
            Object key = getAuthenticationCacheKey(token);
            cache.put(key, info);
            log.trace("Cached AuthenticationInfo for continued
authentication.  key=[{}], value=[{}].", key, info);
        }
    }

which means nothing gets cached anyway, looks like a bug?



--
View this message in context: http://shiro-user.582556.n2.nabble.com/how-to-log-out-another-user-programatically-authentication-cache-problem-tp7420486p7429528.html
Sent from the Shiro User mailing list archive at Nabble.com.