示例化bean失败:工厂方法“springsecurityfilterchain”引发nullpointerexception

cwdobuhd  于 2021-09-30  发布在  Java
关注(0)|答案(0)|浏览(297)

我想用spring security和KeyClope auth保护我的spring启动应用程序。KeyClope服务器已启动并正在接受请求。我添加了基本的spring安全配置类,如KeyClope/spring文档中所述:

@Configuration
@EnableWebSecurity
@KeycloakConfiguration
@EnableGlobalMethodSecurity(jsr250Enabled = true)
@ConditionalOnProperty(name = "keycloak.enabled", havingValue = "true")
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {

    @Value("${spring.profiles.active}")
    private String activeProfile;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);

        super.configure(http);
        http.authorizeRequests()
                //.antMatchers("/data/*")
                //.authenticated()
                // .hasRole("user") // <- WHY U NO WORK?
                .anyRequest()
                .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) {
        var keycloakAuthenticationProvider = keycloakAuthenticationProvider();
        keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
        auth.authenticationProvider(keycloakAuthenticationProvider);
    }

    @Bean
    public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
        return new KeycloakSpringBootConfigResolver();
    }

    @Bean
    @Override
    protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
        return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
    }

}

现在启动应用程序时,出现以下错误: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.NullPointerException 完整日志如下:https://pastebin.com/uewdvvuu
我尝试过的事情:
检查是否实现了文档中提到的所有功能
我不确定如何进一步解决此问题

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题