AuthenticationVoters属性无效。SpringSecurity
创始人
2024-09-22 14:31:15
0

在Spring Security中,AuthenticationVoters属性用于配置投票器,用于决定是否允许特定的身份验证令牌。如果出现“AuthenticationVoters属性无效”的错误消息,可能是由于以下原因之一:

  1. 类型错误:检查AuthenticationVoters属性的值是否正确。它应该是一个List类型的对象。确保在属性中提供的值是一个有效的AuthenticationVoter列表。

示例代码:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .and()
                .httpBasic();
    }

    @Bean
    public AuthenticationProvider authenticationProvider() {
        DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
        authenticationProvider.setUserDetailsService(userDetailsService());
        authenticationProvider.setPasswordEncoder(passwordEncoder());
        return authenticationProvider;
    }

    @Bean
    public UserDetailsService userDetailsService() {
        // return your custom UserDetailsService implementation
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        // return your preferred PasswordEncoder implementation
    }

    @Bean
    public List> authenticationVoters() {
        List> authenticationVoters = new ArrayList<>();
        authenticationVoters.add(new RoleVoter());
        authenticationVoters.add(new AuthenticatedVoter());
        return authenticationVoters;
    }
}

在上面的示例中,我们使用authenticationVoters()方法返回一个包含两个投票器的列表:RoleVoterAuthenticatedVoter

  1. 配置错误:检查是否存在其他配置错误,可能导致无效的AuthenticationVoters属性。确保在配置中没有其他错误,并且所有其他属性都正确设置。

请根据您的具体情况检查和调整代码,确保AuthenticationVoters属性配置正确无误。

相关内容

热门资讯

九分钟实锤!德州ai辅助有用(... 九分钟实锤!德州ai辅助有用(德州ai)都是是有挂(详细辅助2025版教程);1、点击下载安装,德州...
第二分钟实锤!德州之星有辅助挂... 第二分钟实锤!德州之星有辅助挂(德扑之星)果然真的是有挂(详细辅助2025新版教程);1、每一步都需...
八分钟实锤!德扑之星有作弊(德... 八分钟实锤!德扑之星有作弊(德扑ai)一贯真的是有挂(详细辅助扑克教程)1、下载好德扑之星有作弊辅助...
第3分钟实锤!智星德州菠萝开挂... 第3分钟实锤!智星德州菠萝开挂(智星德州)都是真的是有挂(详细辅助详细教程)1、打开软件启动之后找到...
第九分钟实锤!德州ai辅助软件... 第九分钟实锤!德州ai辅助软件(云扑克德州)都是有挂(详细辅助技巧教程)1)德州ai辅助软件辅助挂:...
七分钟实锤!德州免费辅助神器a... 七分钟实锤!德州免费辅助神器app(wpk德州)果然存在有挂(详细辅助我来教教你)暗藏猫腻,小编详细...
第六分钟实锤!智星德州菠萝(德... 第六分钟实锤!智星德州菠萝(德州)本来是有挂(详细辅助透视教程)1、实时智星德州菠萝开挂更新:用户可...
第六分钟实锤!德州之星有辅助挂... 第六分钟实锤!德州之星有辅助挂(手机德州)真是真的有挂(详细辅助靠谱教程)德州之星有辅助挂辅助器中分...
第四分钟实锤!德州免费辅助神器... 第四分钟实锤!德州免费辅助神器app(德州俱乐部)竟然是有挂(详细辅助2025新版技巧)1)德州免费...
3分钟实锤!德扑ai助手(we... 3分钟实锤!德扑ai助手(wepower德州)原来是有挂(详细辅助2025新版总结)1、德扑ai助手...