Spring Bean初始化、预授权和全局身份验证ConfigureRadapter
跟随配置不起作用,因为我使用了@PreAuthorize注释。 我想在我自己的AuthenticationProvider中注入一个服务。如果我的服务不使用@PreAuthorize注释,它将起作用。如果我使用此注释,“my service”bean在“MyGlobalAuthenticationConfigurerAdapter”处将为null,因为创建my service bean时,身份验证提供程序创建得太早(太早)。那我该怎么办 我的服务:Spring Bean初始化、预授权和全局身份验证ConfigureRadapter,spring,spring-security,Spring,Spring Security,跟随配置不起作用,因为我使用了@PreAuthorize注释。 我想在我自己的AuthenticationProvider中注入一个服务。如果我的服务不使用@PreAuthorize注释,它将起作用。如果我使用此注释,“my service”bean在“MyGlobalAuthenticationConfigurerAdapter”处将为null,因为创建my service bean时,身份验证提供程序创建得太早(太早)。那我该怎么办 我的服务: interface MyService{ @P
interface MyService{
@PreAuthorize()
void foo(){
}
配置1:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class MyConfiguration {
@Bean
public MyService myService() {
return new MyServiceimpl();
}
配置2:
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class MyGlobalAuthenticationConfigurerAdapter extends GlobalAuthenticationConfigurerAdapter {
@Autowired
private MyService myService;
@Override
public void configure(final AuthenticationManagerBuilder auth) throws Exception {
final MyAuthenticationProvider myAuthenticationProvider = myAuthenticationProvider ();
auth.authenticationProvider(myAuthenticationProvider );
}
@Bean
public MyAuthenticationProvider myAuthenticationProvider () {
return new MyAuthenticationProvider (myService);
}