JAVA/SPRING

[SPRING SECURITY] ignoring() - 필터에서 벗어나보자

gracelove91 2019. 10. 18. 16:58

1018 spring security

ignoring()

예를 들어 favicon 같은 스태틱한 리소스인 경우는 시큐리티 필터를 타게할 필요가 없다.

favicon을 보여주는데 무슨 인증이 필요하겠나?

하지만 별도의 설정이 없다면 favicon 요청마저 시큐리티 필터들을 타게되고, 그만큼의 자원이 낭비된다.

이런 경우 시큐리티필터를 안타게하려면 어떻게 해야할까?

SecurityConfig.java

@Override
public void configure(WebSecurity web) throws Exception {
  web.ignoring().mvcMatchers("/favicon.ico")
}

부트 쓸 경우

SecurityConfig.java

@Override
public void configure(WebSecurity web) throws Exception {
  web.ignoring().requestMatchers(PathRequest.toStaticResource().atCommonLocations());
}

이외에도 다양한 메소드들이 있으니 살펴볼 것.

ignoring() 적용 전


파비콘이 필터를 타는 것을 볼 수 있다.

ignoring() 적용 후


파비콘이 필터를 타지 않는 것을 볼 수 있다.