9、Spring Boot安全
1.Spring Security简介??Spring Security是针对Spring项目的安全框架,也是Spring Boot底层安全模块默认的技术选型。他可以实现强大的web安全控制。对于安全控制,我们仅需引入spring-boot-starter-security模块,进行少量的配置,即可实现强大的安全管理。 ??WebSecurityConfigurerAdapter:自定义Security策略 ??AuthenticationManagerBuilder:自定义认证策略 ??@EnableWebSecurity:开启WebSecurity模式 ??应用程序的两个主要区域是'认证'和'授权'(或者访问控制)。 ??'认证'和'授权'主要区域是Spring Security 的两个目标。 ??认证(Authentication),是建立一个他声明的主体的过程(一个'主体'一般是指用户,设备或一些可以在你的应用程序中执行动作的其他系统) ??'授权'(Authorization)指确定一个主体是否允许在你的应用程序执行一个动作的过程。为了抵达需要授权的店,主体的身份已经有认证过程建立。 2.Spring Security使用(1).创建工程
(2).引入SpringSecurity
(3).导入文件(4).SpringSecurity配置类??HttpSecurity配置登陆、注销功能
注:如果出现There is no PasswordEncoder mapped for the id “null” ????或者 Encoded password does not look like bcrypt(Bad credentials)基本都是springsecurity版本的问题。只需要使用passwordEncoder(new BCryptPasswordEncoder())替换原来的即可。
(5).Thymeleaf提供的SpringSecurity标签支持[1].引入thymeleaf-extras-springsecurity5
[2].sec:authorize使用
? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |