3

私はアプリケーションに複数の認証マネージャーを持っています。私は豆の名前でそれらを区別する。 OAuthの認証サーバに関連する私のXML設定の一部は次のようになり、それが正常に動作します:Java認証のカスタム認証マネージャーを持つOauth認証サーバー

<oauth:expression-handler id="oauthExpressionHandler" /> 
<oauth:web-expression-handler id="oauthWebExpressionHandler" /> 

<oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler" > 
    <oauth:authorization-code disabled="true" /> 
    <oauth:implicit disabled="false" /> 
    <oauth:refresh-token disabled="false" /> 
    <oauth:client-credentials disabled="false" /> 
    <oauth:password authentication-manager-ref="authenticationManager" /> 
</oauth:authorization-server> 

<oauth:resource-server id="resourceServerFilter" resource-id="resource-id" token-services-ref="tokenServices" /> 

<sec:authentication-manager id="clientAuthenticationManager"> 
    <sec:authentication-provider user-service-ref="clientDetailsUserService" /> 
</sec:authentication-manager> 

<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" 
     xmlns="http://www.springframework.org/schema/security"> 
    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" /> 
    <anonymous enabled="false" /> 
    <http-basic entry-point-ref="clientAuthenticationEntryPoint" /> 
    <!-- include this only if you need to authenticate clients via request parameters --> 
    <custom-filter ref="oauthClientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" /> 
    <access-denied-handler ref="oauthAccessDeniedHandler" /> 
</http> 

は、私がこれまで不足することなく、(いくつかのSecurityConfigクラス内)は、Javaベースの構成に移動しようとしています。私は明示的にendpoints.authenticationManager(authenticationManager)を設定するが、それはまだ、複数の認証マネージャ文句しかし

@Configuration 
@EnableAuthorizationServer 
protected static class OAuth2AuthConfig extends AuthorizationServerConfigurerAdapter { 

    @Resource(name = "authenticationManager") 
    private AuthenticationManager authenticationManager; 

    @Resource 
    private OAuth2AuthenticationEntryPoint authenticationEntryPoint; 

    @Resource(name = "clientDetails") 
    private ClientDetailsService clientDetailsService; 

    @Resource 
    private TokenStore tokenStore; 

    @Resource 
    private TokenStoreUserApprovalHandler userApprovalHandler; 

    @Override 
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { 
     security.authenticationEntryPoint(authenticationEntryPoint); 
    } 

    @Override 
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 
     endpoints.authenticationManager(authenticationManager) 
       .userApprovalHandler(userApprovalHandler) 
       .tokenStore(tokenStore); 
    } 

    @Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients.withClientDetails(clientDetailsService); 
    } 
} 

@Configuration 
@EnableResourceServer 
protected static class OAuth2ResourceConfig extends ResourceServerConfigurerAdapter { 

    @Resource 
    private DefaultTokenServices tokenServices; 

    @Resource(name = "authenticationManager") 
    private AuthenticationManager authenticationManager; 

    @Override 
    public void configure(ResourceServerSecurityConfigurer resources) { 
     resources.resourceId(RESOURCE_ID).tokenServices(tokenServices).authenticationManager(authenticationManager); 
    } 
} 

:私のようなものを試してみました。

いくつかのデバッグでは、WebSecurityConfigurerAdapterクラス内で設定しようとしていますが、authenticationManager()の複数の認証マネージャーを満たしています。私はそれを無効にすることができますか、私は何が欠けていますか?

答えて

1
  1. AuthorizationServer - explanation
  2. ResourceServer - - ここでは単に方法 org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)をオーバーライドすることで
    org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#authenticationManagerに失敗する春を防止するための方法があり、残念ながら問題に対応する同様の処理のための方法はありません。あなたができることは、グローバル認証マネージャのインスタンス数を正確に1つに減らすことです。