Home > database >  WebSecurityConfig: adding property requires Bean?
WebSecurityConfig: adding property requires Bean?

Time:12-18

For some reason whenever i try to add property to this class the app breaks. Can't figure out which conctructor i need to configure.

    @Configuration
    @AllArgsConstructor
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        private final AppUserService appUserService;
        private final BCryptPasswordEncoder bCryptPasswordEncoder;
    
        //without this line it works
        private String newProp;
    
        private FacebookConnectionSignup facebookConnectionSignup;
    
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(daoAuthenticationProvider());
        }
    
        @Bean
        public DaoAuthenticationProvider daoAuthenticationProvider() {
            DaoAuthenticationProvider provider =
                    new DaoAuthenticationProvider();
            provider.setPasswordEncoder(bCryptPasswordEncoder);
            provider.setUserDetailsService(appUserService);
            return provider;
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .csrf().disable()
                    .authorizeRequests()
                    .antMatchers("/api/v*/registration/**")
                    .permitAll()
                    .anyRequest()
                    .authenticated().and()
                    .formLogin();
        }
        @Bean
        public ProviderSignInController providerSignInController() {
            ConnectionFactoryLocator connectionFactoryLocator =
                    connectionFactoryLocator();
            UsersConnectionRepository usersConnectionRepository =
                    getUsersConnectionRepository(connectionFactoryLocator);
            ((InMemoryUsersConnectionRepository) usersConnectionRepository)
                    .setConnectionSignUp(facebookConnectionSignup);
            return new ProviderSignInController(connectionFactoryLocator,
                    usersConnectionRepository, new FacebookSignInAdapter());
        }
    
        private ConnectionFactoryLocator connectionFactoryLocator() {
            ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
            registry.addConnectionFactory(new FacebookConnectionFactory("appId", "appSecret"));
            return registry;
        }
    
        private UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator
                                                                               connectionFactoryLocator) {
            return new InMemoryUsersConnectionRepository(connectionFactoryLocator);
        }
    }

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-17 00:40:17.874 ERROR 21160 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 2 of constructor in com.example.demo.security.config.WebSecurityConfig required a bean of type 'java.lang.String' that could not be found.

Action:

Consider defining a bean of type 'java.lang.String' in your configuration.

Process finished with exit code 1

CodePudding user response:

Instead of AllArgsConstructor use RequiredArgsConstructor annotation and make final this property:

private final FacebookConnectionSignup facebookConnectionSignup;
  • Related