2017-03-17 2 views
0

저는 봄 부팅 프로젝트에서 basicAuth을 사용하고 있습니다.SpringBoot 기본 인증 .wsdl로 끝나는 URL을 무시합니다.

서비스 URL을 인증해야한다는 요구 사항이 있지만 WSDL에서는 인증이 없어야합니다.

인증 된 모든 & URL을 application.yml 파일로 유지 관리하고 싶습니다. 같은

뭔가 : 코드 위

auth.authenticated: /onlineshop/v1/ecart,/onlineshop/v1/wishlist 
auth.ignored: /onlineshop/v1/ecart.wsdl,/onlineshop/v1/wishlist.wsdl 


@EnableWebSecurity 
@Configuration 
class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Value("${auth.authenticated}") 
    String[] allAuthenticated; 

    @Value("${auth.ignored}") 
    String[] allIgnored; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     // Something like 
     for (String ignored: allIgnored) { 
      http.authorizeRequests().antMatchers(ignored).permitAll(); 
     } 

     // Something like 
     for (String authenticated: allAuthenticated) { 
      http.authorizeRequests().antMatchers(authenticated).authenticated(); 
     } 
     .... 
    } 

} 

(즉 죄송 ) 초안이지만, 나는이 라인을 따라 코딩 해봤지만 작동하지 않습니다.

인증을 적용하지 않습니다.

이 작업을 어떻게 수행 할 수 있는지 제안하십시오. 내가 된 .wsdl

로 끝나는 모든 URL을 무시할 수있는 방법을

또한, 대신 된 .wsdl 종료 선택적 URL을 무시하고 당신에게 모든

답변

2

먼저 감사, 나는 당신이 인증되지 않은 수에 대한 화이트리스트 방식을 할 것으로 판단 액세스. 따라서 allAuthenticated 매개 변수를 제거하고 설계 상 안전한 allIgnored 매개 변수에없는 모든 URL에 대해 필요한 인증을 제거했습니다.

아래의 구성은 필요한 기능으로 충분합니다. antMatchers()String[] 필요로하기 때문에, 당신은 루프 스스로를 반복 할 필요가 없습니다

@EnableWebSecurity 
@Configuration 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Value("${auth.ignored}") 
    private String[] allIgnored; 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests() 
      .antMatchers(allIgnored).permitAll() 
      .anyRequest().authenticated() 
      .and() 
      .httpBasic(); 
    } 

} 

참고.

allAuthenticated으로 계속 구성하려면 .antMatchers(allAuthenticated).authenticated()을 구성에 추가하기 만하면됩니다.

+0

나는 당신이 내가 대답 한 것과 똑같은 말을했다는 것을 보았습니다. 보상 할 수 있도록 ;-) – GhostCat