0

私たちには、AuthenticationProvider経由でカスタム認証を実装するwebappがあります。 これで問題はありません。しかし、私たちは、顧客がAuthenticationProviderを実装する独自の認証クラスを実装するオプションを提供したいと考えています。彼らはアプリから私たちの瓶を削除し、クラスパスに彼らの瓶を追加します。Springセキュリティがカスタム認証プロバイダを実装するクラスの実装を選択する

セキュリティ、XMLに我々はAuthenticationProviderを実装するクラスのみを指定する必要がありますが、

現在のXMLとクラスの実装

<authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="customAuthenticationProvider"/> 
</authentication-manager> 

<beans:bean id="customAuthenticationProvider" class="w.x.y.z.CustomAuthenticationProvider"></beans:bean 



@Component 
public class CustomAuthenticationProvider implements AuthenticationProvider { 

    @Override 
    public Authentication authenticate(Authentication authentication) throws AuthenticationException { 
    //Implementation 
    } 

    @Override 
    public boolean supports(Class<?> arg0) { 
     return true; 
    } 
} 

が、私はとにかくあり、任意のクラスの実装インタフェースAuthenticationProviderを選ぶために春を伝えることはできません表示されますAuthenticationProviderを実装しているクラスを選択するようSpringに指示できますか?

答えて

1

たぶん、あなたは型オートワイヤリングとファクトリメソッドを使用してそれを行うことができます。

1-(それが正確でなければならないだけで、あなたのクライアントと削除瓶によって追加のjarで定義された型オートワイヤリングによって注入されますCustomAuthenticationProvider 1つの例はAuthenticationProvider)。

2次に、ファクトリメソッドを使用して、このプロバイダを認証マネージャに挿入します。ステップ

public class AuthenticationProviderFactory { 

    @Autowired 
    private AuthenticationProvider authProvider; 

    public AuthenticationProvider getAuthenticationProvider() { 
     return authProvider; 
    } 

} 

2秒ステップ

<bean name="authenticationProviderFactory" 
    class="w.x.y.z..AuthenticationProviderFactory"></bean> 

<bean name="authenticationProvider" factory-bean="authenticationProviderFactory" 
factory-method="getAuthenticationProvider"> 
</bean> 
<authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="authenticationProvider"/> 
</authentication-manager> 

1、第!!!!削除されたjarと新しいjarは、置換の働きをするために同じapplicationContext.xmlの名前(AuthenticationProviderが宣言されている)を持たなければなりません。

<import resource="applicationContextAuthProvider.xml"/> 
関連する問題