shiro 实现 用户 a 操作b 的权限 ,用户 b 能够及时获知。b不需要退出登陆 。 关闭鉴权缓存,或者不配置缓存

<bean id="myRealm" class="com.diancai.util.MyRealm">
        <property name="userService" ref="userService"/>
        <property name="credentialsMatcher" ref="credentialsMatcher"/>
        <!-- <property name="cachingEnabled" value="true"/>
        <property name="authenticationCachingEnabled" value="true"/>
        <property name="authenticationCacheName" value="authenticationCache"/>
        <property name="authorizationCacheName" value="authorizationCache"/> -->
        <property name="authorizationCachingEnabled" value="false"/>
        <!-- 如果设置成false,关闭鉴权缓存。那么每次验证权限的时候由于默认读取缓存中的权限信息,
            如果读取不到信息就会再次请求realm中的doGetAuthrizationInfo方法获得权限.
            需求:以此实现 权限的动态读取,而不是一次读取一直有效。保证管理员操作用户权限,用户能及时更新
            (也可以不配置缓存机制,自然实现上述需求)-->
    </bean>




<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="myRealm"></property>
        <property name="rememberMeManager" ref="rememberMeManager"></property>
        <property name="cacheManager" ref="shiroEhcacheManager" />
    </bean>
    <!-- 用户授权信息Cache, 采用EhCache -->
    <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:security/ehcache-shiro.xml"/>
    </bean>



<ehcache updateCheck="false" name="shiroCache">

    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="false"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            />
</ehcache>




原文地址:https://www.cnblogs.com/zhangchenglzhao/p/4435282.html