HttpBasic和HttpForm认证方式
提示:本篇连上一篇
文章目录
- HttpBasic和HttpForm认证方式
- 一、在core模块中添加SpringSecurity启动类pom
- 二、编写SpringSecurityConfig类
- 三 、测试
- 四、HttpForm认证方式
-
喜欢的小伙伴可以点赞、关注、收藏哦 -
-- 技术源于追求,技术改变生活 --
一、在core模块中添加SpringSecurity启动类pom
上一篇已添加
二、编写SpringSecurityConfig类
1.SpringSecurityConfig 安全控制配置类作为安全控制中心, 用于实现身份认证与授权配置功能
上一篇添加类了,第一种测HttpBasic方式!
2.但没有加@Configuration 开启、
/**
* @author LIJW
* @date 2021/3/27 9:38 上午
* security 安全配置类
* 继承于webSecurityConfigurerAdapter抽象类
*/
@Configuration
@EnableWebSecurity //启动 SpringSecurity 过滤器链功能
public class springSecurity extends WebSecurityConfigurerAdapter {
/**
* 重写configure(AuthenticationManagerBuilder)身份认证管理器
* 1.认证信息提供方式(用户名、密码、当前用户的资源权
* 2.可采用内存存储方式,也可能采用数据库方式等
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
super.configure(auth);
}
/**
* configure(HttpSecurity http) 资源权限配置(过滤器链)
* 1.拦截的哪一些资源
* 2.资源所对应的角色权限
* 3.定制登录页面、登录请求地址、错误处理方式
* 4.自定义 spring security 过滤器等
* 5.定义认证方式:httpBasic httpForm
* @param http
* @throws Exception
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic()
.and() //链接符号
.authorizeRequests() //认证请求
.anyRequest().authenticated() //所有进入应用的HTTP请求都要进行认证
;
}
}
三 、测试
四、HttpForm认证方式
修改安全配置类中的HttpSecurity资源配置器
@Override
protected void configure(HttpSecurity http) throws Exception {
//HttpBasic和HttpForm2种认证方式
http.formLogin() //表单认证
.and() //链接符号
.authorizeRequests() //认证请求
.anyRequest().authenticated() //所有进入应用的HTTP请求都要进行认证
;
}
测试