分布式项目中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 ...
随机推荐
- Vue学习笔记【32】——Vue路由(watch、computed和methods之间的对比)
computed属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算.主要当作属性来使用: methods方法表示一个具体的操作,主要书写业务逻辑: watch一个对象,键是需要观察的表达式,值是 ...
- web服务器和后端语言的关系
1.web服务nginx和php的相互关系 : https://www.cnblogs.com/luckylihuizhou/p/6387171.html 个人理解:web服务器本身没有处理后端语言 ...
- 如何让EditText不能自动获取焦点(转)
转载地址:http://blog.csdn.net/subaohao/article/details/9043895 在activity中放置了1个或1个以上的EditText,进入该activity ...
- PHP基础知识总结(二) 数据类型、数组、变量和运算符
一.PHP是服务器端的脚本语言.在服务器端解析完成后,向前端浏览器发送html. PHP文件的部署位置在:xampp\htdocs文件夹下,当然这个位置可以修改.二.PHP基本语法 1.文件后缀名是p ...
- linux教程及常用命令手册
Linux 教程 Linux 教程.Linux 简介.Linux 安装.Linux 系统启动过程.Linux 系统目录结构.Linux 忘记密码解决方法.Linux 远程登录.Linux 文件基本属性 ...
- oracle 中和mysql的group_concat有同样作用的写法
所有版本的oracle都可以使用select wm_concat(name) as name from user;但如果是oracle11g,使用select listagg(name, ',') w ...
- 用 Flask 来写个轻博客 (6) — (M)VC_models 的关系(one to many)
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 前言 一对多 再一次 sync db How to use ...
- 二级域名解析设置及Apache 子域名配置
域名管理解析项 如: cy.wanggangg.top 为wanggangg.top域名添加解析 主机记录设为 cy 记录值 为服务器ip地址 打开apache配置文件 新增如下:<Virtua ...
- Django框架(二十)—— Django rest_framework-认证组件
目录 Django rest_framework-认证组件 一.什么是认证 二.利用token记录认证过的用户 1.什么是token 2.token的原理 3.cookie.session.token ...
- Uva10817_Headmaster's Headache
大致题意就是: 一个学校招聘人,自带老师m个,n个求职的人,需要讲授s个课程,已经知道了每个人工资,问怎么才能让各科至少有两个老师(自带的必须要) 这题刚看的时候大概知道是要状态转移,可问题是,状态转 ...