Spring Boot 配置 Security 密码加密
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
注入bean
@SpringBootApplication
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
@Bean
public BCryptPasswordEncoder encoding(){
return new BCryptPasswordEncoder();
}
}
安全配置类
authenticated()要求认证后才能访问。
如果用户没有认证的话,Spring Security的Filter将会捕获该请求,并将用户重定向到应用的登录页面。
/**
* 安全配置类
*/
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//authorizeRequests:声明配置是权限配置
//antMatchers:路径
//permitAll:任何权限都可以访问,不需要身份认证
//anyRequest:任何请求
//authenticated:认证后才能访问
//and().csrf().disable():固定写法,表示csrf拦截失效
http
.authorizeRequests()
.antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and().csrf().disable();
}
}
access(String) 如果给定的SpEL表达式计算结果为true,就允许访问
anonymous() 允许匿名用户访问
authenticated() 允许认证的用户进行访问
denyAll() 无条件拒绝所有访问
fullyAuthenticated() 如果用户是完整认证的话(不是通过Remember-me功能认证的),就允许访问
hasAuthority(String) 如果用户具备给定权限的话就允许访问
hasAnyAuthority(String…) 如果用户具备给定权限中的某一个的话,就允许访问
hasRole(String) 如果用户具备给定角色(用户组)的话,就允许访问
hasAnyRole(String…) 如果用户具有给定角色(用户组)中的一个的话,允许访问
hasIpAddress(String) 如果请求来自给定ip地址的话,就允许访问
not() 对其他访问结果求反
permitAll() 所有权限无条件允许访问
rememberMe() 如果用户是通过Remember-me功能认证的,就允许访问
密码加密与解密
@Autowired
private BCryptPasswordEncoder encoding;
public void add(Admin admin) {
//加密
admin.setPassword(encoding.encode(admin.getPassword()));
adminDao.save(admin);
}
encoding.matches(admin.getPassword(),sqlAdmain.getPassword())
Spring Boot 配置 Security 密码加密的更多相关文章
- spring boot配置druid连接池连接mysql
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Spring boot配置多个Redis数据源操作实例
原文:https://www.jianshu.com/p/c79b65b253fa Spring boot配置多个Redis数据源操作实例 在SpringBoot是项目中整合了两个Redis的操作实例 ...
- Spring Boot -- 配置切换指南
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- Spring Boot 配置优先级顺序
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- spring boot 配置注入
spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...
- spring boot配置springMVC拦截器
spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...
- spring boot配置mybatis和事务管理
spring boot配置mybatis和事务管理 一.spring boot与mybatis的配置 1.首先,spring boot 配置mybatis需要的全部依赖如下: <!-- Spri ...
- [转] Spring Boot配置多个DataSource
[From] https://www.liaoxuefeng.com/article/001484212576147b1f07dc0ab9147a1a97662a0bd270c20000 Sprin ...
- Spring boot 配置异步处理执行器
示例如下: 1. 新建Maven 项目 async-executor 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...
随机推荐
- LeetCode 1041. Robot Bounded In Circle (困于环中的机器人)
题目标签:Math 题目让我们判断机器人是否是一直在走一个圈. 当我们把 instructions 走完一遍时候: 1. 如果机器人回到了原点,那么它是在走一个圈. 2. 如果机器人的方向没有改变,那 ...
- ubantu 编译mysql++
sudo apt-get install mysql-server mysql-client 指定mysql-lib位置: ./configure --with-mysql-lib=/usr/lib/ ...
- Ngui之UI框架的层级处理
#region 处理层级问题 void DepthIncrease(UIWndBase uiWnd) { DepthIncrease(uiWnd.transform, UIFlag); } publi ...
- ncurses库的介绍与安装
Frm: http://blog.csdn.net/Mary_Jane/article/details/50769631 介绍 ncurses(new curses)是一套编程库,它提供了一系列的函数 ...
- mysql主从复制原理分析
1.主从复制这类NFS存储数据通过inotify+rsync同步到备份的NFS服务器,只不 过Mysql的复制方案是其自带的工具inotify 是一种文件系统的变化通知机制,如文件增加.删除等事件可以 ...
- Docker学习のDocker中部署静态页网站
前言:部署一个静态页网站,我们需要 常见映射80端口的交互式容器 安装Nginx(或其他服务器) 安装文本编辑器vim 创建静态页面 修改Ngnix的配置文件 运行Ngnix 验证网站的防高温 一.设 ...
- go 简介与包
简介 Go语言是一种新的语言,一种并发的.带垃圾回收的.快速编译的语言.它具有以下特点: 1.它可以在一台计算机上用几秒钟的时间编译一个大型的Go程序. 2.Go语言为软件构造提供了一种模型,它使依赖 ...
- PL SQL 12.0.7的安装及注册码,汉化包,连接Oracle远程数据库,中文乱码问题处理
首先,在官网下载PL SQL 的对应版本,本机是64位的就下载64位的,网址:https://www.allroundautomations.com/downloads.html#PLS 点击应用程序 ...
- dev设置子窗体的初始位置,grid控件表头的属性设置
当在父窗体上弹出子窗体时,一般设置子窗体的初始位置是居中, //在需要展示子窗体的父窗体上写这段,注意必须设置在show方法之前Form2 f2 = new Form2(); f2.MdiParent ...
- C++: string copy-on-write
https://blog.csdn.net/haoel/article/details/24058 https://www.cnblogs.com/promise6522/archive/2012/0 ...