here is an example where UserAuth is a principal type for this realm
    
    /**
     * removed local cached authorization info in all realms from a particular 
user
     * @param id 
     */
    public void removeUserFromLocalCache(int id)
    {
        UserAuth auth = new UserAuth(id, true);
        realms.values().stream().forEach(realm -> realm.onLogout(new 
SimplePrincipalCollection(auth, 
                realm.getName())));
    }
    
    

> On Feb 21, 2015, at 2:32 AM, Karsten Priegnitz <[email protected]> wrote:
> 
> Hello,
> 
> I want to clear the cached data for a certain user. All I have in my hand is 
> the username, which is not the name of the user which is logged in. No 
> Principle objects, Realms and so on. What I tried is this:
> 
>        for (Realm realm : realms) {
>            if (!(realm instanceof AuthorizingRealm)) {
>                continue;
>            }
> 
>            final org.apache.shiro.cache.Cache<Object, AuthorizationInfo> 
> zcache = ((AuthorizingRealm) realm).getAuthorizationCache();
> 
>            LOG.debug("cached credentials found for {}", realm.getName());
> 
>            for (final Object key : zcache.keys()) { // zcache.keys() is 
> always empty
>                final PrincipalCollection principals = (PrincipalCollection) 
> key;
> 
>                // what to do now?
>                // I want to delete everything for String username
>            }
>        }
> 
> But I even don't get to the "what to do now" line, because zcache.keys() is 
> always empty.
> 
> I'm using shiro 1.2.3 and ehcache with standard config.
> 
> Best,
> Karsten
> 

Reply via email to