场景:
今天在做页面shiro标签权限控制时,意外发现,所有都无效,检查数据库权限设置及对当前账号的授权,都没问题,而且在对应的 Realm 中 的 doGetAuthorizationInfo() 方法中断点,发现刷新页面,根本就不会进入当前鉴权方法中,经过排查,发现是 shiroConfig中忘记开启页面上使用 Shiro 标签,添加 ShiroDialect 方法后就可以了。
代码:
页面
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
xmlns:shiro="http://www.w3.org/1999/xhtml">
<div class="btn-group">
<button type="button" name="delBtn" id="delBtn" class="btn btn-danger" shiro:hasPermission="task:delete:*">
<i class="fa fa-trash" aria-hidden="true"></i>
删除
</button>
</div>
<div class="btn-group">
<button type="button" name="addBtn" id="addBtn" class="btn btn-success" shiro:hasPermission="task:insert:*">
<i class="fa fa-plus" aria-hidden="true"></i>
新增
</button>
</div>
Java ShiroConfig
/**
* 页面上使用shiro标签
* @return
*/
@Bean(name = "shiroDialect")
public ShiroDialect shiroDialect(){
return new ShiroDialect();
}