2016-08-31 4 views
3

"해킹"으로 작동하는 SPNEGO와 함께 스프링 보안 구성이 있습니다. 다음과 같습니다 :WebSecurityConfigurerAdapter with custom authentication 필터 - 종속성 문제

  • 내가 spnegoAuthenticationProcessingFilter (1)
  • 는이 필터의 AuthenticationManager에 의존성이 (2)
  • 내가 인증을 추가해야 추가해야합니다 : 무슨 일이 일어나고 무엇

    @Configuration 
    @EnableWebSecurity 
    public class SpnegoConfig extends WebSecurityConfigurerAdapter { 
    
        @Override 
        protected void configure(HttpSecurity http) throws Exception { 
         http 
           ... 
           .addFilterBefore(
             spnegoAuthenticationProcessingFilter(authenticationManagerBean()), 
             BasicAuthenticationFilter.class); // 1 
        } 
    
        @Override 
        @Autowired // 3 
        protected void configure(AuthenticationManagerBuilder auth) 
          throws Exception { 
         auth 
           .authenticationProvider(kerberosAuthenticationProvider()) 
           .authenticationProvider(kerberosServiceAuthenticationProvider()); 
        } 
    
    
        @Bean 
        public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
          AuthenticationManager authenticationManager) { // 2 
         SpnegoAuthenticationProcessingFilter filter = 
           new SpnegoAuthenticationProcessingFilter(); 
         filter.setAuthenticationManager(authenticationManager); 
         return filter; 
        } 
        ... 
    } 
    

    제공 업체 (3)

포인트가있는 클래스는 WebSecurityConfigurerAdapter입니다. 이 방법 rriding :

  1. configure(HttpSecurity http) -이 이미 사용자 정의 필터를 통해 AuthenticationManager 내장에 의존성이를
  2. configure(AuthenticationManagerBuilder auth) -이 명확하게 AuthenticationManager에 관련되지 아니 아직 건설되고 - 우리는

경우를 구축하고 나는 방법 (3)에 @Autowired을 가지고 있지 않다. AuthenticationManager은 너무 일찍 만들어졌고 나의 추가는 AuthenticationProvider이다. 아무런 효과가 없다. 적절한 AuthenticationProvider이 없으면 인증이 실패합니다.

@Autowired이 제대로 작동하면 작동하지만 잘못된 것입니다. 나는 그것이 왜 일하기 시작하는지조차 확신하지 못한다.

올바른 방법에 대한 조언을 구하십시오.

편집 : 실제로는 @Autowired없이 작동합니다. 그러나 요점은 인정 된 대답에있다. AuthenticationManager@Configuration에 의존하는 경우 노출되었거나 authenticationManagerBean() 방법을 통해 참조되어 있는지 확인하십시오.

답변

2

AuthenticationManager을 잘못 사용하십시오.

당신은 의존성 주입과 SpnegoConfig에서 AuthenticationManager를 사용하려는 경우, 당신이 그것을 노출해야 JavaDoc 참조 : 구성 (AuthenticationManagerBuilder)에서의 AuthenticationManager를 노출

재정이 메소드를 Bean으로 노출되는 . 예를 들어 당신이 (당신 만이, 즉 글로벌 인증을 구성하려면

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

전역 AuthenticationManager을 구성 할 경우, AuthenticationMangerBuilder를 autowire하기 필요는, 예를 들어, Spring Security 3.2.0.RC2 Released

참조 단일 AuthenticationManager)를 사용하려면 AuthenticationMangerBuilder를 autowire해야합니다.

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) { 
    // ... configure it ... 
}