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属性配置正确无误。

相关内容

热门资讯

透视规律"爱玩联盟辅... 透视规律"爱玩联盟辅助软件视频讲解"开挂(透视)辅助工具(其实是有挂)-哔哩哔哩;爱玩联盟辅助软件视...
最新技巧!九酷众游辅助,小旋风... 最新技巧!九酷众游辅助,小旋风辅助器,切实教程(有人有挂)-哔哩哔哩 了解更多开挂安装加(13670...
透视透视"椰子乐动软... 透视透视"椰子乐动软件辅助"开挂(透视)辅助工具(果然真的有挂的)-哔哩哔哩,椰子乐动软件辅助是用手...
科普分享!江西上饶辅助器,杭州... 科普分享!江西上饶辅助器,杭州都莱辅助软件有没有用,2026新版教程(有挂辅助)-哔哩哔哩您好:杭州...
2024教程"云麻圈... 2024教程"云麻圈修改器"开挂(透视)辅助平台(果然确实有挂)-哔哩哔哩;最新版2026是一款经典...
透视科技!皮皮辅助软件,凑一桌... 皮皮辅助软件 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、软...
1.9分钟了解"指尖... 1.9分钟了解"指尖四川刷无限钻石"开挂(透视)辅助插件(一直真的有挂)-哔哩哔哩;1、不需要AI权...
指导大家!斗城麻将微信有没有挂... 指导大家!斗城麻将微信有没有挂,广西友乐辅助app,微扑克教程(有挂教学)-哔哩哔哩斗城麻将微信有没...
记者揭秘"皮皮山西挖... 记者揭秘"皮皮山西挖坑辅助"开挂(透视)辅助平台(一直确实是有挂)-哔哩哔哩;皮皮山西挖坑辅助最新软...
最新技巧!潮汕汇木虱辅助下载,... >>您好:潮汕汇木虱辅助下载确实是有挂的,很多玩家在这款潮汕汇木虱辅助下载游戏中打牌都会发现很多用户...