강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

강성욱님의 프로필 이미지
강성욱

작성한 질문수

스프링 MVC 2편 - 백엔드 웹 개발 활용 기술

서블릿 필터 - 인증 체크

인터셉터 whitelist 사용

작성

·

281

0

영한님 안녕하세요. 인터셉터 강의를 듣고 whitelist가 왜 필요성에 대해서 잘 이해가 안 돼서 질문드립니다.

registry.addInterceptor(new LoginCheckInterceptor())
.order(2)
.addPathPatterns("/**")
.excludePathPatterns("/", "/members/add", "/login",
"/logout", "/cass/**", "/*.ico", "/error");

    @Bean
public FilterRegistrationBean logFilter() {
FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
filterRegistrationBean.setFilter(new LogFilter());
filterRegistrationBean.setOrder(1); // 필터 순서 정하기
filterRegistrationBean.addUrlPatterns("/*"); // 모든 URL에 적용

return filterRegistrationBean;
}

위에가 인터셉터가 아래가 필터 코드인데 영한님께서는 필터 코드 패턴 매칭을 할 때 우선 전체 루트 경로를 전부 열어놓으시고 LogFilter 클래스에서 추가적으로 whiteList를 만드셨습니다. 그리고 나중에 새로운 게 추가되면 whiteList에 추가할 거라고 하셨는데요.

제가 느끼기에 (패턴 매칭에 한해서) 필터랑 인터셉터 차이는 인터셉터가 조금 더 정교한 조작이 가능하다는 것 빼고는 패턴매칭은 별 차이점을 못 느끼겠는데, 인터셉터는 왜 LogCheckInterceptor 클래스에 whiteList를 안 만드셨는지 알려주실 수 있나요?

답변 1

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. 김말이님

서블릿 필터는 제약이 너무 많습니다.

서블릿 필터 URL 패턴으로 검색해보시면 이해가 되실거에요.

감사합니다.

강성욱님의 프로필 이미지
강성욱

작성한 질문수

질문하기