Shiro的常用注解
@RequiresPermissions :要求當(dāng)前Subject在執(zhí)行被注解的方法時(shí)具備一個(gè)或多個(gè)對應(yīng)的權(quán)限。
@RequiresRoles :要求當(dāng)前Subject在執(zhí)行被注解的方法時(shí)具備所有的角色,否則將拋出AuthorizationException異常。
@RequiresAuthentication:要求在訪問或調(diào)用被注解的類/實(shí)例/方法時(shí),Subject在當(dāng)前的session中已經(jīng)被驗(yàn)證。
jsp中Shiro使用的標(biāo)簽
需要在jsp頁面中引入標(biāo)簽
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
標(biāo)簽:
<shiro:authenticated> 登錄之后
<shiro:notAuthenticated> 不在登錄狀態(tài)時(shí)
<shiro:guest> 用戶在沒有RememberMe時(shí)
<shiro:user> 用戶在RememberMe時(shí)
<shiro:hasAnyRoles name="abc,123" > 在有abc或者123角色時(shí)
<shiro:hasRole name="abc"> 擁有角色abc
<shiro:lacksRole name="abc"> 沒有角色abc
<shiro:hasPermission name="abc"> 擁有權(quán)限資源abc <shiro:lacksPermission name="abc"> 沒有abc權(quán)限資源
<shiro:principal> 顯示用戶身份名稱
<shiro:principal property="username"/> 顯示用戶身份中的屬性值
作者:我是邱邱
鏈接:http://www.itdecent.cn/p/b804a977d47a
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。