WebSecurityConfig:添加属性需要Bean



由于某种原因,每当我试图向此类添加属性时,应用程序就会中断。不知道我需要配置哪个concstructor。

@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);
}
}

启动ApplicationContext时出错。若要显示条件报告,请在启用"调试"的情况下重新运行应用程序。2021-12-17 00:40:17.874错误21160-[main]o.s.b.d.LoggingFailureAnalysisReporter:


应用程序无法启动


描述:

com.example.demo.security.config.WebSecurityConfig中构造函数的参数2需要一个类型为"java.lang.String"的bean,但找不到该bean。

行动:

考虑在配置中定义一个类型为"java.lang.String"的bean。

进程结束,退出代码为1

使用RequiredArgsConstructor注释而不是AllArgsConstructor,并使此属性成为最终属性:

private final FacebookConnectionSignup facebookConnectionSignup;

相关内容

  • 没有找到相关文章

最新更新