2016-09-14 2 views
0

내 프로젝트에 2 개의 API가 있습니다. 첫 번째 인증에는 인증이 필요하고 두 번째 인증에는 인증이 필요하지 않습니다. 첫 번째 API /auth/uploadFile스프링 부트의 웹 API 중 하나에서 인증 필터 제거

에 대한 토큰 기반 인증 필터를 추가하는

나는 여기 WebSecurityConfigurerAdapter을 확장 의 SecurityConfig 클래스의 코드가 성공적으로 할 수 있었다.

@Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http.addFilterBefore(tokenAuthenticationFilter, BasicAuthenticationFilter.class).authorizeRequests() 
       .antMatchers("/auth/uploadFile/").permitAll().anyRequest() 
       .authenticated().and().csrf().disable(); 
    } 

나는는 antMatchers() 내 두 번째 API /noauth/uploadFile을 추가하지 않은 하지만 난 그것에 POST 호출을 할 때 여전히 사용자 정의 tokenAuthenticationFilter 들어갑니다. 내 필터가 두 번째 API에 적용해서는 안 즉 내 두 번째 API /noauth/uploadFile에 전화를 걸 때

는 어떻게 사용자 정의 필터 tokenAuthenticationFilter를 입력하지 않도록 할 수 있습니까?

답변

2

SecurityConfig 클래스에서 아래 메서드를 재정의하거나 추가 할 수 있습니다.

public void configure(WebSecurity web) throws Exception { 
    web 
     .ignoring() 
     .antMatchers("/noauth/**"); 
} 
관련 문제