Using Ehache to cache, you can log on to the authentication after the successful authentication authorization and permission information, but when the user exits, the user's corresponding permissions information can not be updated in real-time, so that the user will be able to exit the system to clean up their corresponding permissions information cache.
In configuring the Ehcache cache we configured the Myshirocache and specified the name of the permission cache in the Myrealm, so the user can get the information through CacheManager and cache name when exiting, and clean up the permission information when exiting the system.
PackageCom.copsec.railway.im.util;ImportOrg.apache.log4j.Logger;Importorg.apache.shiro.SecurityUtils;ImportOrg.apache.shiro.cache.Cache;ImportOrg.apache.shiro.cache.CacheManager;Importorg.apache.shiro.subject.SimplePrincipalCollection;ImportOrg.apache.shiro.subject.Subject; Public classShiroauthorizationhelper { Private StaticCacheManager CacheManager; Private StaticLogger Logger = Logger.getlogger (shiroauthorizationhelper.class); /*** Clear User's permissions * *@paramprincipal principal object for landing user*/ Public Static voidClearauthorizationinfo (simpleprincipalcollection principal) {Logger.info ("Clear the User:" + principal.tostring () + "' s Authorizationinfo"); Cache<object, object> cache = Cachemanager.getcache ("Myshirocache");Cache.remove (principal); } /*** Clear the current user's permissions*/ Public Static voidClearauthorizationinfo () {if(Securityutils.getsubject (). IsAuthenticated ()) {Subject Subject=Securityutils.getsubject (); String username=Subject.getprincipal (). toString (); String Realmname=subject.getprincipals (). Getrealmnames (). iterator (). Next (); Simpleprincipalcollection PrincipalCollection=Newsimpleprincipalcollection (username, realmname); Logger.debug ("Get user principalcollection:" +principalcollection); //invoke cleanup user rightsClearauthorizationinfo (principalcollection); } } /*** The object is injected by the spring Bean *@paramCacheManager*/ Public Static voidSetcachemanager (CacheManager cachemanager) {Shiroauthorizationhelper.cachemanager=CacheManager; }}
After completion, it can be called in the logout controller for cleanup permission information.
Ssm+apache Shiro--ehcache Cache cleanup