前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
權限控制是shiro最核心的東西?
Shiro權限聲明通常是使用以冒號分隔的表達式。一個權限表達式可以清晰的指定資源類型,允許的操作,可訪問的數據。同時,Shiro權限表達式支持簡單的通配符,可以更加靈活的進行權限設置。?
下面以實例來說明權限表達式。?
可查詢用戶數據?
User:view?
可查詢或編輯用戶數據?
User:view,edit?
可對用戶數據進行所有操作?
User:* 或 user?
可編輯id為123的用戶數據?
User:edit:123
@ RequiresAuthentication
可以用戶類/屬性/方法,用于表明當前用戶需是經過認證的用戶。?
使用這個注解之前,需要先在spring-mvc.xml加入一段代碼(一定要寫在最先加載的xml中,寫在后面加載的xml中也不起作用)
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"depends-on="lifecycleBeanPostProcessor" />
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"><property name="securityManager" ref="securityManager" />
</bean>
lifecycleBeanPostProcessor和securityManager是在shiro配置文件中定義好的:
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean><!-- Shiro安全管理器 --><bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"><property name="realm" ref="jdbcRealm"></property><property name="cacheManager" ref="cacheManager"></property>
</bean>
?
在前端權限管理處寫上權限的字符串?
contraller里方法上寫上注解,括號里是前端對應的權限字符串?
這樣就可以控制已認證用戶權限了
轉自:https://blog.csdn.net/MOTU_/article/details/74941419?
?