java - Spring Boot AuthenticationManagerBean 不起作用
问题描述
在我的项目中,当我试图AuthenticationManager
通过覆盖AuthenticationManagerBean()
它显示以下错误的方法来定义 bean 时,
The method authenticationManagerBean() of type SecurityConfiguration must override or implement a supertype method
虽然下面给出了我定义的方法,
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
我的整个SecurityConfiguaration
课程如下,
package com.toorjaridwan.introvertreadersauth.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import com.toorjaridwan.introvertreadersauth.Service.UserDetailService;
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Autowired
private UserDetailService userDetailService;
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailService);
}
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().antMatchers("/authenticate").permitAll()
.anyRequest().authenticated();
}
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
}
在之前使用 Spring Boot 版本2.1.9的项目中,一切都很顺利,完全没有问题。现在我使用的是 Spring Boot 版本2.2.6。不知道是不是这个原因。
在寻找解决方案时,我遇到了this和this。我发现事情和我做的一样。
我正在运行 64 位 Ubuntu 16.04 LTS 和 Java 版本 1.8
解决方案
尝试添加
extends WebSecurityConfigurerAdapter
到你的配置类
推荐阅读
- python - 机器人框架 selenium 如何从字典中检索密钥
- android - 如何将jetpack compose中的背景图像添加到compose布局中
- c# - C# 自定义 DynamicObject 强制转换为派生对象
- python - 从数据框中的经纬度查找最近的位置
- python - Docker 阻止传入连接
- sql - 如何获取两个日期范围之间的归档总和,其中从日期到日期在表中给出
- c++ - 如何使用包含多维向量的指针数组
- python - 使用 pyqt5 QAbstractTableModel 时将箭头键连接到方法
- javascript - 国际日期格式未按预期格式化数据nodeJS
- firebase - firestore 更新列表重叠值增量不起作用