目录
一:授权角色,权限
1.添加角色和权限的授权方法
//根据username查询该用户的所有角色,用于角色验证
Set<String> findRoles(String username);//根据username查询他所拥有的权限信息,用于权限判断
Set<String> findPermissions(String username);
2.自定义Realm配置Shiro授权认证
1) 获取验证身份(用户名)
2) 根据身份(用户名)获取角色和权限信息
3) 将角色和权限信息设置到SimpleAuthorizationInfo
SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
info.setRoles(roles);
info.setStringPermissions(permissions);
3.使用Shiro标签实现权限验证
导入Shiro标签库
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
4.图解
5.操作
UserMapper.xml
<select id="getRolesByUserId" resultType="java.lang.String" parameterType="java.lang.Integer">
select r.roleid from t_shiro_user u,t_shiro_user_role ur,t_shiro_role r
where u.userid = ur.userid and ur.roleid = r.roleid
and u.userid = #{userid}
</select>
<select id="getPersByUserId" resultType="java.lang.String" parameterType="java.lang.Integer">
select p.permission from t_shiro_user u,t_shiro_user_role ur,t_shiro_role_permission rp,t_shiro_permission p
where u.userid = ur.userid and ur.roleid = rp.roleid and rp.perid = p.perid
and u