Shiro授权

本文详细介绍了Shiro的授权过程,包括在Mapper和服务层的实现,以及授权方法的设置。通过示例代码展示了如何进行角色和权限查询。接着,文章转向注解式开发,讲解了Shiro的授权注解如@RequiresAuthentication、@RequiresUser、@RequiresRoles和@RequiresPermissions的使用,并给出了SpringMVC中添加拦截器的配置说明。
摘要由CSDN通过智能技术生成

目录

一、shiro授权角色、权限

1.1、Shiro授权步骤

1.1.1Mapper层、service层

UserMapper.xml

1.1.2、shiro的授权的方法

​ 1.1.3、测试

二、注解式开发


一、shiro授权角色、权限

授角色:用户具备哪些角色

 SELECT roleid from t_shiro_user u,t_shiro_user_role ur
where u.userid = ur.userid and u.username = 'zs'

授权限:用户具备哪些权限:

SELECT rp.perid from t_shiro_user u, t_shiro_user_role ur,t_shiro_role_permission rp
where u.userid = ur.userid and ur.roleid= rp.roleid and u.username = 'ls'

1.1、Shiro授权步骤

1.1.1Mapper层、service层

UserMapper.xml

<select id="selelctRoleIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String">
  select roleid from t_shiro_user u,t_shiro_user_role ur
    where u.userid = ur.userid and  u.username = #{userName}
</select>

  <select id="selelctPerIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String">
  select rp.perid from t_shiro_user u,t_shiro_user_role ur,t_shiro_role_permission rp
  where u.userid = ur.userid and ur.roleid = rp.roleid and u.username = #{userName}
</select>

UserMapper 

package com.zwc.ssm.mapper;

import com.zwc.ssm.model.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
public interface UserMapper {
    int deleteByPrimaryKey(Integer userid);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Integer userid);
    //通过 账户名 查询用户信息
    User queryUserByUserName(@Param("userName") String userName);

    //通过 账户名 查询对应的角色信息
     Set<String> selelctRoleIdsByUserName(@Param("userName") String userName);

     //通过 账户名 查询对应的权限信息
     Set<String> selelctPerIdsByUserName(@Param("userName") String
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值