七、pom.xml 加入 shiro包
八、shiro配置
.java
package com.example.demo2.config;import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;import com.example.demo2.entity.Permission;import com.example.demo2.entity.Role;import com.example.demo2.entity.User;import com.example.demo2.service.UserService;import org.apache.shiro.authc.*;import org.apache.shiro.authz.AuthorizationInfo;import org.apache.shiro.authz.SimpleAuthorizationInfo;import org.apache.shiro.realm.AuthorizingRealm;import org.apache.shiro.subject.PrincipalCollection;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Lazy;import java.util.ArrayList;import java.util.List;import java.util.Set;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/17*/public class AuthRealm extends AuthorizingRealm {/*** @Lazy 延迟注入,不然redis注解会因为注入顺序问题失效*/@Autowired@Lazyprivate UserService userService;/*** 授权* @param principals* @return*/@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {User user = (User) principals.fromRealm(this.getClass().getName()).iterator().next();List permissionList = new ArrayList<>();List roleNameList = new ArrayList<>();Set
.java
package com.example.demo2.config;import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authc.UsernamePasswordToken;import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/17*/public class CredentialMatcher extends SimpleCredentialsMatcher {@Overridepublic boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;String password = new String(usernamePasswordToken.getPassword());String dbPassword = (String) info.getCredentials();return this.equals(password, dbPassword);}}
- vs2019项目部署到阿里云服务器与iis配置
- centos7.4系统的虚拟机网络配置教程
- lv3 嵌入式开发-1linux介绍及环境配置
- 掘金领航者全自动付费进群系统代理端域名配置教程
- servlet配置
- SVN版本控制器的安装和配置以及一些技巧svn开机自启动
- 阿里云服务器配置个人用户怎么选?CPU内存带宽系统盘?
- 华为交换机——策略路由配置实战
- 【Linux下进程的CPU配置和线程绑定】
- 三 【Audio】配置文档audio_policy_conf.xml