既存のSpring Security(バージョン3.2.10)XML設定をJavaベースの設定に変換中です。私は交換しています XML-構成が設定された認証マネージャを持っていますバネセキュリティで認証マネージャを注入するとデリゲートビルダーがnullになる
<authentication-manager alias="authenticationManager">
<authentication-provider ref="kerberosServiceAuthenticationProvider"/>
<authentication-provider ref="samlAuthenticationProvider"/>
<authentication-provider ref="pkiAuthenticationProvider"/>
<authentication-provider ref="openIdConnectAuthenticationProvider"/>
</authentication-manager>
私のJava構成と同等である:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
{
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.authenticationProvider(kerberosServiceAuthenticationProvider())
.authenticationProvider(samlAuthenticationProvider())
.authenticationProvider(pkiAuthenticationProvider())
.authenticationProvider(openIdConnectAuthenticationProvider());
}
}
認証マネージャは、他の豆を構築する上での別名で呼ばれているように、私
@Override
@Bean(name = "authenticationManager")
public AuthenticationManager authenticationManagerBean() throws Exception
{
return super.authenticationManagerBean();
}
提案されているように、認証マニガービーンをオーバーライドしました。 How To Inject AuthenticationManager using Java Configuration in a Custom Filter にしかし、このBeanの作成については、次の例外がスローされます。
Caused by: java.lang.IllegalArgumentException: delegateBuilder cannot be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.<init>(WebSecurityConfigurerAdapter.java:426)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.authenticationManagerBean(WebSecurityConfigurerAdapter.java:220)
デリゲートビルダーは、スニペットは、スーパーの実装である(Beanをオーバーライドするとき、最初の引数として使用されている認証ビルダーです。 authenticationManagerBean())。これはnullです。
public AuthenticationManager authenticationManagerBean() throws Exception {
return new AuthenticationManagerDelegator(authenticationBuilder, context);
}
このBeanが作成されると、何かが見当たりません。
@Autowired
public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor)
{...}
をしかし、それは呼び出されません(と上書きすることを意図していないようです):このデリゲートビルダーだけWebSecurityConfigurerAdapterに、この方法で設定されています。 私はconfigureメソッドがまだ呼び出されていないことに気付きました。 私は明らかに何か不足していますが、それが何であるか分かりません。
すでに 'configure(AuthenticationManagerBuilder auth)'でBeanを公開しています。 Beanとして2つの 'AuthenticationManager'が必要ですか? – dur
いいえ、私はそうではありません:)だから、ビルダーから認証マネージャーをBeanとしてどのように公開すべきですか?私のセキュリティ設定でautowiredにすることはできますか? authオブジェクトの再利用とgetOrBuild()の呼び出しは機能しないため、認証マネージャーBeanを必要とする他のBeanが作成される前にconfigureメソッドが呼び出されないためです。 – DennisV
同様の質問については私の[answer](https://stackoverflow.com/a/39259519/5277820)を参照してください。 – dur