I ended up exposing the private method "clearCachedAuthorizationInfo" in the extended Realm of AuthorizingRealm. Then just pass in the principals.
public class MyRealm extends AuthorizingRealm {
//...
@Override
public void clearCachedAuthorizationInfo(PrincipalCollection principals)
{
super.clearCachedAuthorizationInfo(principals);
}
//...
}
to clear the authorization cache:
realm.clearCachedAuthorizationInfo( SecurityUtils.getSubject().getPrincipals() );
I think this is a bit cleaner/safer because this method has additional checks against null
on the cache and will ensure you get a reference to the cache if one exists. Simply calling getAuthorizationCache()
doesn't do this and may or may not work all the time.
You do need to maintain a reference to the realm. I did this by initializing Shiro via Spring and then injecting it as a Singleton bean wherever I needed it.