0

우리는 AuthenticationProvider를 통해 맞춤 인증을 구현하는 webapp가 있습니다. 이제 제대로 작동합니다. 그러나 우리는 고객이 AuthenticationProvider를 구현하는 자체 인증 클래스를 구현할 수있는 옵션을 제공하고자합니다. 그래서 그들은 애플 리케이션에서 우리의 항아리를 삭제하고 클래스 패스에 항아리를 추가합니다. 그것은 보안 XML에 나타납니다Spring 보안이 맞춤 인증 공급자를 구현하는 클래스의 구현을 선택하도록

우리는 AuthenticationProvider에 구현에만 클래스를 지정해야하지만 어쨌든 인터페이스의 AuthenticationProvider에게이

<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; 
    } 
} 

는 현재 XML 및 클래스 구현되어

구현하는 모든 클래스를 선택하는 봄 말할 수 없다 AuthenticationProvider를 구현하는 클래스를 선택하도록 Spring에게 알릴 수 있습니까?

1은 IT가 클라이언트 및 삭제 된 항아리에 의해 추가 된 항아리 만 정의 유형에서 autowiring에 의해 주입 될 것이다 CustomAuthenticationProvider이 (정확히해야합니다 :

답변

1

어쩌면 당신은 형에서 autowiring과 팩토리 메소드를 사용하여 작업을 수행 할 수 있습니다 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"/> 
관련 문제