2017-05-24 2 views
0

기본 스프링 부트 보안 설정으로 보호되는 작은 휴식 서비스가 있습니다. 기본적으로 OPTIONS, chrome을 포함하여 모든 http 메소드에 대한 인증이 필요하지만 비행도 오리를주지 않으며 프리 플라이트 요청에 권한 헤더를 포함하지 않으므로 401 응답이 발생합니다.SpringBoot 보안을 사용하여 OPTIONS에 대한 기본 http 인증을 비활성화하는 방법

특정 방법으로 http 기본 인증을 어떻게 비활성화 할 수 있습니까? 지금까지 시도 :

@Configuration 
@EnableWebMvc 
@EnableGlobalMethodSecurity(securedEnabled = true) 
public class Config { 
} 

그리고 컨트롤러를 :

@CrossOrigin(origins = {"http://localhost:4200"}, maxAge = 4800) 
@RestController 
public class MainController { 

    @Secured("IS_AUTHENTICATED_ANONYMOUSLY") 
    @RequestMapping(method = RequestMethod.OPTIONS) 
    public ResponseEntity handle() { 
     return new ResponseEntity(HttpStatus.OK); 
    } 
} 

분명히 작동하지 않았다. 방법에있어서

답변

1

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

.antMatchers(HttpMethod.OPTIONS, "/path/to/skip/check").permitAll() 
+0

덕분에 많이 추가,이 일했다. HttpMethod를 가져간 .antMatchers 메소드를 찾아야했습니다. 내 마지막 해결책은 다음과 같다 : http.httpBasic().(). authorizeRequests(). antMatchers (HttpMethod.OPTIONS) .permitAll();' –

관련 문제