`

shiro权限验证的方式

阅读更多

总的来说,shiro对权限验证的方式可分为三种:

1.通过注解进行验证:

     shiro官方例子中,有一个银行的例子,它的权限控制方式便是通过注解,如下代码,仅允许含有“bankAccount:read”权限的用户访问该方法

     @RequiresPermissions("bankAccount:read")
      public String getOwnerOf(long anAccountId) throws AccountNotFoundException {
        assertServiceState();
        log.info("Getting owner of account " + anAccountId);

        Account a = safellyRetrieveAccountForId(anAccountId);
        return a.getOwnerName();
    }

 

2.通过java代码验证

    if(!SecurityUtils.getSubject().isPermitted("editOperation")){

    syso("你有这个权限");

   }

3.再一个就是通过jsp标签控制了

       <shiro:hasPermission name="role:view">
         <a>你有这个权限</a>

       </shiro:hasPermission>

  • 大小: 858.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics