springboot+maven整合spring security
springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述。
1.pom.xml中添加spring security的起步依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.创建spring security的配置类,继承WebSecurityConfigurerAdapter类,重写里面的configure(HttpSecurity http)和configure(AuthenticationManagerBuilder auth)两个方法。这两个方法即自定义配置的内容。
3.对于configure(AuthenticationManagerBuilder auth)方法,有从内存获取和从数据库获取两种方式。如果采用后者,需要实现UserDetailsService接口,并将此实现类的对象传入auth.userDetailsService()方法中,后面跟上加密方式(不跟上加密方式可能会报java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"的错误),实例如下:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
MyUserDetailsService userService = new MyUserDetailsService();
auth.userDetailsService(userService).passwordEncoder(new BCryptPasswordEncoder());
}
另外,之前版本的springboot(2.0之前)可以在application.properties中使用security.basic.enable=false属性来禁用默认验证,新版本的springboot(2.0以上)移除了这一属性。spring security似乎是自行判断是启用默认配置还是自定义配置。在自定义配置的过程中如果只重写了configure(HttpSecurity http)方法,虽然此方法的自定义配置会起作用,但是登录验证依然是默认的,即用户名为user,密码为自动生成,后台会打印出来(这是默认情况,也可以自行设置),此时需要实现configure(AuthenticationManagerBuilder auth)方法来自定义验证策略。
ps:技巧是在一遍又一遍的重复中得以掌握,又在一遍又一遍的重复中得以精深。
springboot+maven整合spring security的更多相关文章
- SpringBoot学习(二)—— springboot快速整合spring security组件
Spring Security 简介 spring security的核心功能为认证(Authentication),授权(Authorization),即认证用户是否能访问该系统,和授权用户可以在系 ...
- springBoot整合spring security实现权限管理(单体应用版)--筑基初期
写在前面 在前面的学习当中,我们对spring security有了一个小小的认识,接下来我们整合目前的主流框架springBoot,实现权限的管理. 在这之前,假定你已经了解了基于资源的权限管理模型 ...
- springBoot整合spring security+JWT实现单点登录与权限管理--筑基中期
写在前面 在前一篇文章当中,我们介绍了springBoot整合spring security单体应用版,在这篇文章当中,我将介绍springBoot整合spring secury+JWT实现单点登录与 ...
- SpringBoot安全篇Ⅵ --- 整合Spring Security
知识储备: 关于SpringSecurity的详细学习可以查看SpringSecurity的官方文档. Spring Security概览 应用程序的两个主要区域是"认证"和&qu ...
- SpringBoot整合Spring Security
好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star,更多文章请前往:目录导航 前言 Spring Securi ...
- Spring Boot整合Spring Security
Spring Boot对于该家族的框架支持良好,但是当中本人作为小白配置还是有一点点的小问题,这里分享一下.这个项目是使用之前发布的Spring Boot会员管理系统重新改装,将之前filter登录验 ...
- 【手摸手,带你搭建前后端分离商城系统】03 整合Spring Security token 实现方案,完成主业务登录
[手摸手,带你搭建前后端分离商城系统]03 整合Spring Security token 实现方案,完成主业务登录 上节里面,我们已经将基本的前端 VUE + Element UI 整合到了一起.并 ...
- Springboot WebFlux集成Spring Security实现JWT认证
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 简介 在之前的文章<Springboot集成Spring Security实现JWT认证>讲解了如何在传统 ...
- Maven 整合 spring profile实现多环境自动切换
Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...
随机推荐
- CSS3 Vendor-prefixing
Browser vendors needed a way to add support for new features that were not yet standardized, but wit ...
- version `GLIBC_2.17' not found 解决方法
1.先查看是哪个函数用的是GLIBC_2.17 root@emb-pc:/home/emb/temp# nm lib61850.so | grep GLIBC_2.17 U clock_gettime ...
- C++类的组合例子
Line类调用Point类的两个对象p1,p2作为其数据成员,计算线段长度 组合类构造函数定义的一般形式为: 类名::类名(形参表):内嵌对象1(形参表),内嵌对象2(形参表)... {类的初始化} ...
- 【Eclipse】_Eclipse自动补全增强方法 & 常用快捷键
一,Eclipse自动补全增强方法 在Eclipse中,从Window -> preferences -> Java -> Editor -> Content assist - ...
- python css选择器
css 选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- 图片支持get请求访问
BufferedInputStream in = new BufferedInputStream(doc2.getContent());//读取文件到输入流 OutputStream out = re ...
- Sysbench 1.0.17安装与测试
Sysbench安装与测试 1.安装: cd /usr/local/src wget https://codeload.github.com/akopytov/sysbench/tar.gz/1.0. ...
- CentOS_6.5配置iptables防火墙策略
###############配置filter表防火墙############### #清除预设表filter中的所有规则链的规则iptables -F #清除预设表filter中使用者自定链中的规则 ...
- [java,2018-06-26] 扑克牌抽牌求和问题
问题: 一副扑克牌,除去大小王后共52张牌,随机从中抽八张牌,问八张牌的和最有可能是多少? 分析: 这52张牌,其实就是数字 1 2 3 ...13, 每个数字出现4次.随机抽出8个数,问组成的和最有 ...
- thunderbird 163 smtp
thunderbird 163 smtp 如果要正常发送,配置如下: server: smtp.163.com port: 465 auth: Normal password security: SS ...