security的学习

**

security学习第一天

我使用的是前后端不分离方式----脚手架方式还没有使用习惯。我碰到了几个bug

  1. 项目启动时候爆出这样的错误:authenticationManager must be specified
    我查看源码时候在这里插入图片描述
    由于我的security配置类继承了WebSecurityConfigurerAdapter。在这个类里面有一个方法是生成这个对象的
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return new WebSecurityConfigurerAdapter.AuthenticationManagerDelegator(this.authenticationBuilder, this.context);
    }
`按照我的理解应该是生成一个``authenticationManager 对象 

```java
 //自定义的表单登录页面配置
    @Override
    protected void configure(HttpSecurity http) throws Exception {
       http.authorizeRequests()
               .anyRequest().authenticated()
               .and()
               .formLogin()
               .loginPage("/login.html")
               .loginProcessingUrl("/login")
               .permitAll()
               .and()
               .csrf().disable();
       http.addFilterAt(getLoginConfig(), UsernamePasswordAuthenticationFilter.class);  //这里将系统拦截器给替换了
    }
```UsernamePasswordAuthenticationFilter。。由于我自定义的拦截器没有声明authenticationManager 对象,所以报错最后解决办法

![解决办法](https://img-blog.csdnimg.cn/20210508212223740.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI2NTYyNzYz,size_16,color_FFFFFF,t_70#pic_center)
在配置LoginConfig定义好authenticationManager 对象


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值