分布式项目中Spring security自定义权限类
package cn.lijun.core.service; import cn.lijun.core.pojo.seller.Seller;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.*;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import java.util.ArrayList;
import java.util.List; /**
* @author lijun
* @date 2019/9/18 16:55
* 自定义认证类
*/
public class UserDetailServiceImpl implements UserDetailsService { private SellerService sellerService;
public void setSellerService(SellerService sellerService){
this.sellerService=sellerService;
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 权限集合
List<GrantedAuthority> arrayList = new ArrayList<GrantedAuthority>();
// 具有什么样的权限
arrayList.add(new SimpleGrantedAuthority("ROLE_SELLER"));
// 1 判断用户名是否为空 如果为null 返回null
if(username==null){
return null;
} //2 根据名到数据库查询对应的用户对象
Seller seller = sellerService.findOne(username);
//3 如果用户名找不到 返回null
if(seller!=null){
// 4 如果找到了 判断用户审核状态 如果未通过 fanhui null
if("1".equals(seller.getStatus())){
// 5 返回springSecurity的User对象 将这个用户 密码 所应该具有的访问权限集合返回
return new User(username,seller.getPassword(),arrayList);
} } return null;
}
}
分布式项目中Spring security自定义权限类的更多相关文章
- Spring Boot中使用 Spring Security 构建权限系统
Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置的Bean,为应用系统提供声明式的安全 ...
- Spring Security控制权限
Spring Security控制权限 1,配置过滤器 为了在项目中使用Spring Security控制权限,首先要在web.xml中配置过滤器,这样我们就可以控制对这个项目的每个请求了. < ...
- spring boot+freemarker+spring security标签权限判断
spring boot+freemarker+spring security标签权限判断 SpringBoot+SpringSecurity+Freemarker项目中在页面上使用security标签 ...
- Spring Security 自定义登录认证(二)
一.前言 本篇文章将讲述Spring Security自定义登录认证校验用户名.密码,自定义密码加密方式,以及在前后端分离的情况下认证失败或成功处理返回json格式数据 温馨小提示:Spring Se ...
- 解决Spring Security自定义filter重复执行问题
今天做项目的时候,发现每次拦截器日志都会打两遍,很纳闷,怀疑是Filter被执行了两遍.结果debug之后发现还真是!记录一下这个神奇的BUG! 问题描述 项目中使用的是Spring-security ...
- (二)spring Security 自定义登录页面与校验用户
文章目录 配置 security 配置下 MVC 自定义登录页面 自定义一个登陆成功欢迎页面 效果图 小结: 使用 Spring Boot 的快速创建项目功能,勾选上本篇博客需要的功能:web,sec ...
- spring security自定义指南
序 本文主要研究一下几种自定义spring security的方式 主要方式 自定义UserDetailsService 自定义passwordEncoder 自定义filter 自定义Authent ...
- 使用Spring Security实现权限管理
使用Spring Security实现权限管理 1.技术目标 了解并创建Security框架所需数据表 为项目添加Spring Security框架 掌握Security框架配置 应用Security ...
- Maven项目中Spring整合Mybatis
Maven项目中Spring整合Mybatis 添加jar包依赖 spring需要的jar包依赖 <dependency> <groupId>org.springframewo ...
随机推荐
- 03.线程的通知notify与等待wait
wait().notify.notifyAll()方法 wait().notify().notifyAll()是三个定义在Object类里的方法,可以用来控制线程的状态. 这三个方法最终调用的都是jv ...
- Database基础(五):使用binlog日志、XtraBackup备份工具、MySQL AB复制
一.使用binlog日志 目标: 利用binlog恢复库表,要求如下: 启用binlog日志 创建db1库tb1表,插入3条记录 删除tb1表中刚插入的3条记录 使用mysqlbinlog恢复删除的3 ...
- mock 数据 解决方案
前端工程化之--Mock解决方案 https://www.jianshu.com/p/720b12b5d120 一.为什么要使用mock数据: 1.后端接口数据没有的时候,前端根据接口文档,使用 ...
- .content和.text的区别
python中内置库 requests的两种方法get()和post()返回的的一个对象,有两种方法.content和.text ..content返回的是字节码,.text返回的是字符串.
- vim 更改注释颜色
在 ~/.vimrc 添加命令: highlight Comment ctermfg=green
- css3水平垂直居中(不知道宽高同样适用)
css水平垂直居中 第一种方法: 在父div里加: display: table-cell; vertical-align: middle; text-align: center; 内部div设置: ...
- strtotime 获取当月最后一天的日期
strtotime('last day of this month', $timestamp);
- PHP简单导出Excel表格
<?php header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; ...
- Docker 容器使用
Docker 客户端 docker 客户端非常简单 ,我们可以直接输入 docker 命令来查看到 Docker 客户端的所有命令选项. runoob@runoob:~# docker :~# doc ...
- csdn加入暂时会话功能
版权声明:本文为博主原创文章.若要转载请注明出处! ^_^ https://blog.csdn.net/u010892841/article/details/25334153 ...