spring security无法添加自定义身份验证提供程序

spring security无法添加自定义身份验证提供程序,spring,authentication,spring-security,spring-boot,Spring,Authentication,Spring Security,Spring Boot,我已经创建了其他身份验证提供程序。我正在按如下方式注册它们: @Configuration @EnableWebMvcSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) class SecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(AuthenticationManagerBuilder

我已经创建了其他身份验证提供程序。我正在按如下方式注册它们:

@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
class SecurityConfig extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(tokenAP());
        auth.authenticationProvider(usernameAndPasswordAP());
        auth.userDetailsService(getUserDetailsService());
    }

稍后在我的代码中,我将使用AuthenticationManager对用户进行身份验证。问题是,我在身份验证管理器中只注册了一个身份验证提供程序,即DaoAuthenticationProvider。看起来我的身份验证提供商根本没有注册。我应该做一些额外的配置来让它工作吗?我正在使用spring boot 1.2.6,提前感谢您提供的提示。最好的祝愿

我们在Spring Boot web应用程序中配置身份验证提供程序的方式与中讨论的类似,它修改了默认的autowired
AuthenticationManagerBuilder
。使用您的方法,它可能看起来像:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  auth.authenticationProvider(tokenAP())
    .authenticationProvider(usernameAndPasswordAP())
    .userDetailsService(getUserDetailsService());
}
如果我的阅读正确,当您重写此方法时,您必须指定自己的
AuthenticationManager
。通过如上所述使用自动连线实例,默认的
AuthenticationManager
(即
ProviderManager
,它依次委托给一个或多个已配置的
AuthorizationProvider
实例)

您可能还需要使用以下内容对配置类进行注释:

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)

因此,您的访问控制规则将在Spring Boot将为您配置的默认值之前应用。

我们在Spring Boot web应用程序中配置身份验证提供程序的方式与中讨论的类似,它修改了默认的autowired
AuthenticationManagerBuilder
。使用您的方法,它可能看起来像:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  auth.authenticationProvider(tokenAP())
    .authenticationProvider(usernameAndPasswordAP())
    .userDetailsService(getUserDetailsService());
}
如果我的阅读正确,当您重写此方法时,您必须指定自己的
AuthenticationManager
。通过如上所述使用自动连线实例,默认的
AuthenticationManager
(即
ProviderManager
,它依次委托给一个或多个已配置的
AuthorizationProvider
实例)

您可能还需要使用以下内容对配置类进行注释:

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)

因此,您的访问控制规则将在Spring Boot将为您配置的默认值之前应用。

我们在Spring Boot web应用程序中配置身份验证提供程序的方式与中讨论的类似,它修改了默认的autowired
AuthenticationManagerBuilder
。使用您的方法,它可能看起来像:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  auth.authenticationProvider(tokenAP())
    .authenticationProvider(usernameAndPasswordAP())
    .userDetailsService(getUserDetailsService());
}
如果我的阅读正确,当您重写此方法时,您必须指定自己的
AuthenticationManager
。通过如上所述使用自动连线实例,默认的
AuthenticationManager
(即
ProviderManager
,它依次委托给一个或多个已配置的
AuthorizationProvider
实例)

您可能还需要使用以下内容对配置类进行注释:

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)

因此,您的访问控制规则将在Spring Boot将为您配置的默认值之前应用。

我们在Spring Boot web应用程序中配置身份验证提供程序的方式与中讨论的类似,它修改了默认的autowired
AuthenticationManagerBuilder
。使用您的方法,它可能看起来像:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  auth.authenticationProvider(tokenAP())
    .authenticationProvider(usernameAndPasswordAP())
    .userDetailsService(getUserDetailsService());
}
如果我的阅读正确,当您重写此方法时,您必须指定自己的
AuthenticationManager
。通过如上所述使用自动连线实例,默认的
AuthenticationManager
(即
ProviderManager
,它依次委托给一个或多个已配置的
AuthorizationProvider
实例)

您可能还需要使用以下内容对配置类进行注释:

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)

这样,您的访问控制规则将在Spring Boot将为您配置的默认值之前应用。

当您覆盖
配置(AuthenticationManagerBuilder auth)
时,底层AuthenticationManager将以以下两种方式之一公开:

1) 在SecurityConfig中,您只需调用
authenticationManager()

2) 如果需要SecurityConfig之外的AuthenticationManager,则需要将其作为bean公开,例如:

class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(tokenAP());
        auth.authenticationProvider(usernameAndPasswordAP());
        auth.userDetailsService(getUserDetailsService());
    }

   @Bean
   @Override
   public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
   }
}

重写
配置(AuthenticationManagerBuilder auth)
时,底层AuthenticationManager将以以下两种方式之一公开:

1) 在SecurityConfig中,您只需调用
authenticationManager()

2) 如果需要SecurityConfig之外的AuthenticationManager,则需要将其作为bean公开,例如:

class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(tokenAP());
        auth.authenticationProvider(usernameAndPasswordAP());
        auth.userDetailsService(getUserDetailsService());
    }

   @Bean
   @Override
   public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
   }
}

重写
配置(AuthenticationManagerBuilder auth)
时,底层AuthenticationManager将以以下两种方式之一公开:

1) 在SecurityConfig中,您只需调用
authenticationManager()

2) 如果需要SecurityConfig之外的AuthenticationManager,则需要将其作为bean公开,例如:

class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(tokenAP());
        auth.authenticationProvider(usernameAndPasswordAP());
        auth.userDetailsService(getUserDetailsService());
    }

   @Bean
   @Override
   public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
   }
}

重写
配置(AuthenticationManagerBuilder auth)
时,底层AuthenticationManager将以以下两种方式之一公开:

1) 在SecurityConfig中,您只需调用
authenticationManager()

2) 如果需要SecurityConfig之外的AuthenticationManager,则需要将其作为bean公开,例如:

class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(tokenAP());
        auth.authenticationProvider(usernameAndPasswordAP());
        auth.userDetailsService(getUserDetailsService());
    }

   @Bean
   @Override
   public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
   }
}