2017-02-24 2 views
1

RestController 정의 된 메소드를 사용하여 일부 엔드 포인트를 노출하는 스프링 부트 REST 서비스 (spring-boot-startter-parent : 1.3.2)가 있습니다. 나는 또한 봄 보안을 사용하고있다. "/ images"에 매핑 된 컨트롤러 메서드를 정의 할 때까지 모든 것이 잘 작동합니다. 이 API 경로에 액세스하려고하면 다음 오류가 발생합니다. 디버깅을 통해 컨트롤러 처리기가 매핑되는 것을 볼 수는 있지만 사전 승인 필터는 호출되지 않습니다 (다른 매핑의 경우 제대로 호출 됨). 다음 속성을 설정했지만 변경하지 않았습니다. 이것을 어떻게 수정하여 "/ images"를 사용할 수 있습니까?스프링 부트 Rest 컨트롤러에서 "/ images"경로를 어떻게 사용합니까?

spring.resources.add-mappings=false 
spring.mvc.static-path-pattern=/hide-me/** 

오류 :

"exception": "org.springframework.security.authentication.AuthenticationCredentialsNotFoundException", 
    "message": "An Authentication object was not found in the SecurityContext", 

코드 : 나는 다음 다음에 매핑을 변경하는 경우는 잘 작동

@RestController 
@PreAuthorize(value = "hasAnyAuthority('SOMEUSER')") 
public class ImageController { 
    ... 
    @RequestMapping(value = { "/images/{imageId}" }, method = RequestMethod.GET) 
    @ResponseBody 
    public Image getImage(@PathVariable UUID imageId) { 
    return imageDataService.getImage(imageId); 
    } 
    ... 

.

@RequestMapping(value = { "/image/{imageId}" }, method = RequestMethod.GET) 
    @ResponseBody 
    public Image getImage(@PathVariable UUID imageId) { 
    return imageDataService.getImage(imageId); 
    } 

나는 정적 리소스에 대한 설정이 preauth 필터의 "/ 이미지"경로를 무시하는 봄 보안을 알려주는 기본 항목을 가지고 생각하고 있어요. 내가 오버라이드 할 수있는 곳을 찾아 내려고 디버깅 중이다. 기본적으로

+0

(클래스 수준 및/또는 메서드 수준에서) 어떤 @@ RequestMapping을 사용하고 계십니까? 액세스하려는 URL은 무엇입니까? 스프링 보안 설정에 따르면'/ images' 경로가 API의 다른 경로와 다른 점은 무엇입니까? – aaguilera

+0

내 코드 섹션을 참조하십시오. @RequestMapping (value = { "/ images/{imageId}"}, method = RequestMethod.GET)을 사용하려고합니다. –

답변

2

SpringBoot 어떤 경로

https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" };

그리고이 경로 중 하나입니다/이미지를 사용 또한

Java Web Application. Spring Boot. Locating Images

하면 다음과 같은 제한 사항이있을 때 usind SpringSecurity

The basic features you get out of the box in a web application are:

An AuthenticationManager bean with in-memory store and a single user (see SecurityProperties.User for the properties of the user). Ignored (insecure) paths for common static resource locations (/css/, /js/, /images/, /webjars/ and **/favicon.ico). HTTP Basic security for all other endpoints. Security events published to Spring’s ApplicationEventPublisher (successful and unsuccessful authentication and access denied).

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/

일반적인 낮은 수준의 기능 (HSTS는, XSS, CSRF, 캐싱) 스프링 시큐리티에서 제공은 기본적으로 있습니다.

+0

나는 그 문서를 보았지만 쉬는 서비스를 만들 때 쉽게 끄는 방법이 없다고 믿는 것이 어려웠다. –

+1

이 프로젝트의 구성보기를 재정의 할 수 있습니다. https://github.com/bclozel/spring-resource-handling – reos

2

모든 요청에 ​​대해 보안을 수행해야합니다. 이것은 다음을 사용하여 수행 할 수 있습니다 SecurityConfiguration :

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests().anyRequest().authenticated(); 
    } 
} 
관련 문제