Filter์™€ Interceptor

HeoSeungYeonยท2022๋…„ 1์›” 19์ผ
1

Spring Study

๋ชฉ๋ก ๋ณด๊ธฐ
4/7
post-thumbnail

๐Ÿ’ก Spring framework์˜ ๋‚ด๋ถ€ ๋™์ž‘์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋‹ค๋ณด๋ฉด Filter์™€ Interceptor๋Š” ๋บด๋†“์„ ์ˆ˜ ์—†๋Š” ์š”์†Œ์ž…๋‹ˆ๋‹ค. ์™œ ๋‚ด๋ถ€ ๋กœ์ง์— Filter๋ž‘ Interceptor๋ฅผ ๋’€์„๊นŒ?๋ฅผ ์•Œ๊ณ  ์ด๋ฅผ ํ™œ์šฉํ•  ์ค„ ์•Œ์•„์•ผ ์ˆ˜์ค€ ๋†’์€ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹จ์ˆœํžˆ ์•„ Filter๋ž‘ Interceptor๊ฐ€ ์žˆ๊ตฌ๋‚˜ ํ•˜๊ณ  ๋„˜์–ด๊ฐ€๋ฉด Filter์™€ Interceptor์˜ ์กด์žฌ์—์„œ ๋‚˜์˜ค๋Š” ์žฅ์ ๋“ค์„ ๋†“์นœ ์ฑ„ ๊ฐœ๋ฐœ์„ ํ•˜๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ์— ์™œ Filter์™€ Interceptor๋ฅผ ๋’€์„๊นŒ, ๋ฌด์Šจ ์—ญํ• ์„ ํ• ๊นŒ, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ์„๊นŒ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ ธ๋ณผ๊นŒ ํ•ฉ๋‹ˆ๋‹ค. โœŒ๏ธ

์™œ ํ•„์š”ํ•œ๋ฐ?


์ž๋ฐ” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋‹ค๋ณด๋ฉด ์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๋Š” API ๊ฐœ๋ฐœ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ•„์ˆ˜์ ์œผ๋กœ ๊ฐœ๋ฐœํ•ด์•ผ ๋˜๋Š” ์š”์†Œ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์‚ฌ์šฉ์ž ์ธ์ฆ
  • ๊ถŒํ•œ ๊ฒ€์‚ฌ(์ธ๊ฐ€)
  • ๋ณด์•ˆ
    • XSS, CORS
  • ๋กœ๊น…
  • ์ด๋ฏธ์ง€ ์••์ถ• ๋ฐ ๋ฐ์ดํ„ฐ ํ˜•์‹ ๋ณ€ํ™˜

API์˜ URL์— ๋”ฐ๋ผ ์ƒ์ดํ•œ ๋™์ž‘์„ ์š”๊ตฌํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ, ๊ฐ™์€ ๋™์ž‘์ด๋“  ๋‹ค๋ฅธ ๋™์ž‘์ด๋“  ๊ณตํ†ต์ ์œผ๋กœ ๋ชจ๋“  API์— ํ•„์ˆ˜๋กœ ์ ์šฉ๋˜์–ด์•ผ ํ•˜๋Š” ์š”์†Œ๋“ค์ž…๋‹ˆ๋‹ค.

์œ„ ๋‚ด์šฉ์„ ์–ธ๊ธ‰ํ•œ ์ด์œ ๋Š” ๋‹ค๋“ค ๋ˆˆ์น˜์ฑ˜๋‹ค์‹œํ”ผ Filter์™€ Interceptor๊ฐ€ ์œ„ ์š”์†Œ๋“ค์— ๋Œ€ํ•œ ์ฑ…์ž„ ๋ฐ ๊ตฌํ˜„์— ์—ญํ• ์„ ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์™œ ์ € ์—ญํ• ๋“ค์„ ํ•˜๊ธฐ ์œ„ํ•ด ์ € 2๊ฐ€์ง€ ๊ฐœ๋…์ด ํƒ„์ƒํ•˜๊ณ  ๋งŒ๋“ค์–ด์ง€๊ฒŒ ๋˜์—ˆ์„๊นŒ์š”?

์—†์„ ๋•Œ๋ฅผ ์ƒ๊ฐํ•˜๋ฉด ์‰ฌ์šธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ € 2๊ฐ€์ง€ layer๊ฐ€ ์—†์„ ๊ฒฝ์šฐ, ์šฐ๋ฆฌ๋Š” ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋Œ€ํ•ด Controller, Service Layer์—์„œ ์ € ๋™์ž‘๋“ค์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค. ์œ„ ์š”์†Œ๋“ค์€ ๋ชจ๋“  API์— ๋Œ€ํ•ด ๊ณตํ†ต์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒƒ๋“ค์ธ๋ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ปค์ง€๋ฉด ์ปค์งˆ์ˆ˜๋ก ์ฝ”๋“œ์˜ ์–‘์€ ๋ฐฉ๋Œ€ํ•ด์ง€๊ณ , ์ค‘๋ณต๋˜์–ด์ง€๊ณ , ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋ฌด๊ฑฐ์›Œ์งˆ ์ˆ˜ ๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ธฐ์— ์šฐ๋ฆฌ๋Š” ์‹œ์ ์— ๋”ฐ๋ผ ๊ด€์‹ฌ์‚ฌ์˜ ๋ถ„๋ฆฌ๋ฅผ ํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ด€์‹ฌ์‚ฌ์˜ ๋ถ„๋ฆฌ๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์ ๋“ค์„ ๊ณ ์Šค๋ž€ํžˆ ์–ป์„ ์ˆ˜ ์žˆ๋Š”๋ฐ์š”,

  • ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์‰ฌ์›€.
  • ๊ฐœ๋ฐœ ์‹œ, ํ•˜๋‚˜์˜ ๊ด€์‹ฌ์‚ฌ์— ๋Œ€ํ•ด ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ์Œ.
  • ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ (์ค‘๋ณต ์ œ๊ฑฐ)

๊ทธ๋Ÿฌ๋ฉด ์–ด๋–ค ์‹œ์ ์— ๋”ฐ๋ผ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ด€์‹ฌ์‚ฌ๋ฅผ ๋ถ„๋ฆฌํ•˜์˜€์„๊นŒ์š”?

Spring MVC ๋‚ด๋ถ€ ๋™์ž‘

  • ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘๊ทผํ•˜๊ธฐ ์ „ (1)

  • ์š”์ฒญ์ด DispatcherServlet์œผ๋กœ ๋ถ€ํ„ฐ Controller๋กœ ์ ‘๊ทผํ•˜๊ธฐ ์ „ (2)

  • Controller์—์„œ Service - Repository ~ (3)

  • +์ถ”๊ฐ€) DispatcherServlet์ด๋ž€?

    DispatcherServlet์ด๋ž€ ํด๋ผ์ด์–ธํŠธ๋กœ ๋“ค์–ด์˜จ HTTP ์š”์ฒญ์„ Controller๋กœ ์ „๋‹ฌํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. Controller๋ณด๋‹ค ์•ž๋‹จ์—์„œ ์š”์ฒญ์„ ์ „๋‹ฌ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— Front Controller๋ผ๊ณ ๋„ ํ•ฉ๋‹ˆ๋‹ค. ์š” ๋…€์„๋„ Filter์™€ Interceptor์˜ ํƒ„์ƒ ๋ฐฐ๊ฒฝ๊ณผ ๋น„์Šทํ•œ ๋ถ€๋ถ„์ด ์žˆ๋Š”๋ฐ์š”, DispatcherServlet์ด ๋“ฑ์žฅํ•˜๊ธฐ ์ „์—” HTTP ์š”์ฒญ์„ ํ•˜๋Š” API์— ๋งž๋Š” ์„œ๋ธ”๋ฆฟ์„ ์ผ์ผ์ด ๊ตฌํ˜„ํ•ด์•ผ๋งŒ ํ–ˆ๊ณ  ๊ฐ๊ฐ์˜ ์„œ๋ธ”๋ฆฟ์— ๋งž๋Š” Controller์— ๋งคํ•‘์„ ํ•ด์•ผ๋งŒ ํ–ˆ์Šต๋‹ˆ๋‹ค.

    ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด DispatcherServlet์ด ๋“ฑ์žฅํ•˜์˜€๋Š”๋ฐ์š”,

    DispatcherServlet์€ ํ•˜๋‚˜์˜ ์„œ๋ธ”๋ฆฟ ๊ฐœ๋…์œผ๋กœ ๋ชจ๋“  HTTP ์š”์ฒญ์„ ๋ฐ›์€ ๋’ค, ์š”์ฒญ์— ๋Œ€ํ•œ ๊ณตํ†ต์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰(ex, ํ•œ๊ธ€/์˜์–ด ์ธ์ฝ”๋”ฉ)ํ•˜๊ณ  ์ด๋ฅผ Controller์— ๋ฟŒ๋ ค์ฃผ๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

    ๋˜ํ•œ DispatcherServlet๋Š” resources ํด๋”์— ์žˆ๋Š” ์ •์  ๋ฆฌ์†Œ์Šค(์ด๋ฏธ์ง€, ํŒŒ์ผ, html)์— ์š”์ฒญ์„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์š”์ฒญ๊ณผ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ๋„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ์š”, ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด controller(์• ํ”Œ๋ฆฌ์ผ€์ด์…˜)์— ํ•ด๋‹น ์š”์ฒญ์— ๋Œ€ํ•œ ๋งคํ•‘์ด ์žˆ๋Š”์ง€ ํƒ์ƒ‰ํ•˜๊ณ  ์—†์„ ์‹œ, resources ๋กœ ์ ‘๊ทผํ•˜๋Š” ๋กœ์ง์„ ํ†ตํ•ด ์œ„ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๋ฌด์Šจ ์—ญํ• ์„ ํ• ๊นŒ?


์œ„ ๊ทธ๋ฆผ์„ ํ†ตํ•ด 3๊ฐ€์ง€๋กœ ๋ถ„๋ฆฌํ•œ ์‹œ์ ์— ๋Œ€ํ•ด ์ž˜ ์ดํ•ดํ•ด ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

(1) ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์ด ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์— ์ ‘๊ทผํ•˜๊ธฐ ์ „ : Filter์˜ ์—ญํ• 

ServletContainer ์˜ DispatcherServlet์œผ๋กœ ์š”์ฒญ์˜ ๋„๋‹ฌํ•˜๊ธฐ ์ „๊ณผ DispatcherServlet์œผ๋กœ ๋ถ€ํ„ฐ ์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๊ณ  ํด๋ผ์ด์–ธํŠธ๋กœ ๊ฐ€๊ธฐ ์ „์˜ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ž‘์—…์„ Filter๊ฐ€ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋ณดํ†ต ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ „์—ญ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋Š” ์ž‘์—…๋“ค(ex) ๋ณด์•ˆ ์ฒ˜๋ฆฌ)์„ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ์š”,

  • CORS
  • XSS
  • ์ธ์ฆ

๋ณด์•ˆ๊ณผ ๊ด€๋ จ๋œ ์ž‘์—… ์™ธ์—๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ์ž‘์—…๋„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ๋ฌธ์ž์—ด ์ธ์ฝ”๋”ฉ
  • ์ด๋ฏธ์ง€ ๋ฐ ๋ฐ์ดํ„ฐ ์••์ถ•

(2) ์š”์ฒญ์ด DispatcherServlet์œผ๋กœ ๋ถ€ํ„ฐ Controller๋กœ ์ ‘๊ทผํ•˜๊ธฐ ์ „ : Interceptor์˜ ์—ญํ• 

  • dispatcherServlet โ†’ Controller
  • Controller โ†’ dispatcherServlet

์œ„ 2๊ฐ€์ง€ ๊ณผ์ • ์‚ฌ์ด์—์„œ Interceptor๊ฐ€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋ณดํ†ต ๊ถŒํ•œ ๊ฒ€์‚ฌ(์ธ๊ฐ€), View ๋ Œ๋”๋ง ์ „ ์ถ”๊ฐ€ ์ž‘์—…๋“ฑ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

(3)Controller์—์„œ Service - Repository ~

์œ„์—์„œ ๋‹ค๋ฃฌ Filter, Interceptor์˜ ์—ญํ• ์— ๋•๋ถ„์— App์—์„œ ๋ถ„๋ฆฌ๋˜์–ด์ง€๋Š” Controller - Service - Repository ๊ณ„์ธต์€ ๊ฐ๊ฐ์˜ ์—ญํ• ๊ณผ ์ฑ…์ž„์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ญ๊ฐ€ ์ข‹์•„์ง„๊ฑฐ์ง€? ๐Ÿ—ฏ๏ธ

  • ๊ณ„์ธต ๋ณ„ ์‘์ง‘๋„๊ฐ€ ๋†’์•„์กŒ๋‹ค!
  • ๊ณ„์ธต ๋ณ„ ๊ฒฐํ•ฉ๋„๊ฐ€ ๋‚ฎ์•„์กŒ๋‹ค!
  • ํšจ์œจ์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๊ณ , ์œ ์ง€๋ณด์ˆ˜ํ•˜๊ธฐ ์‰ฝ๋‹ค!

์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ์„๊นŒ?


A. Filter


public interface Filter {

    
    public default void init(FilterConfig filterConfig) throws ServletException {}

    
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException;

    
    public default void destroy() {}

}

B. Interceptor


public interface HandlerInterceptor {

	
	default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		return true;
	}

	
	default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			@Nullable ModelAndView modelAndView) throws Exception {
	}

	
	default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
			@Nullable Exception ex) throws Exception {
	}

}

์œ„์—์„œ ์‹คํ–‰ ์‹œ์ ์ด ๋‹ค๋ฅด๊ณ , ํ•˜๋Š” ์—ญํ• ์ด ๋‹ค๋ฅธ ๊ฒƒ์€ ๋‹ค๋ค„๋ณด์•˜๊ธฐ ๋•Œ๋ฌธ์— ํฌ๊ฒŒ 2๊ฐ€์ง€ ์ฐจ์ด์ ์— ๋Œ€ํ•ด ๋‹ค๋ค„๋ณด๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

  1. Exception Handling

์Šคํ”„๋ง์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋Š” ๋ฐœ์ƒ ์œ„์น˜์— ๋”ฐ๋ผ 2๊ฐ€์ง€๋กœ ๋ถ„๋ฆฌ๋˜์–ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Dispatcher Servlet ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ (root Spring Container ํฌํ•จ)
    • ์œ„ ๊ฒฝ์šฐ, HandlerExceptionResolver ์„ ํ†ตํ•ด ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Interceptor๋Š” ์œ„ ๊ฒฝ์šฐ์ด๋ฏ€๋กœ HandlerExceptionResolver์„ ์‚ฌ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Dispatcher Servlet ๋ฐ–์˜ย ์„œ๋ธ”๋ฆฟ(Filter)์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ (Web Application ๋ ˆ๋ฒจ ์˜ˆ์™ธ)
    • Filter ๋‚ด๋ถ€์— ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ Filter์„ ๋‘๊ณ  try-catch๋กœ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰
      • Security ์˜ ์ธ๊ฐ€ ์ฒ˜๋ฆฌ์˜ ๊ฒฝ์šฐ, ExceptionTranslationFilter ์— ์˜ˆ์™ธ๋ฅผ ๋˜์ ธ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    • HandlerExceptionResolver์„ bean์œผ๋กœ ๋“ฑ๋กํ•˜๊ณ  GlobalExceptionHandler์—์„œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
  1. ์š”์ฒญ/์‘๋‹ต์— ๋Œ€ํ•œ ์กฐ์ž‘ ๊ฐ€๋Šฅ ์—ฌ๋ถ€

Filter ์—์„œ๋Š” ServletRequest, ServletResponse ๊ฐ์ฒด๋กœ ์š”์ฒญ/์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณต๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ๋Œ€ํ•œ ์กฐ์ž‘์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด์— Interceptor์—์„œ๋Š” HttpServletRequest, HttpServletResponse ๊ฐ์ฒด๋กœ ์š”์ฒญ/์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณต๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์กฐ์ž‘์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ธฐ์— Filter์—์„  ๋Œ€๊ฐœ ์ด๋ฏธ์ง€ ๋ฐ ๋ฐ์ดํ„ฐ ์••์ถ•์„ ์ˆ˜ํ–‰ํ•˜๋ฉฐ Interceptor์—์„œ๋Š” ๊ฐ์ฒด ๋‚ด๋ถ€ ๊ฐ’์„ ํ†ตํ•ด ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์š”๊ตฌํ•˜๋Š” ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ ๊ฐ€๊ณต์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

ํšŒ๊ณ 


์‚ฌ์‹ค ํฌ์ŠคํŒ…์„ ๊ฒฐ์ •ํ–ˆ๋˜ ๊ฑด Spring Security๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ Filter์— ๊ณต๋ถ€ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ , Spring์—์„  Filter์™€ Interceptor๊ฐ€ ์ค‘์š”ํ•œ ์—ญํ• ์„ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์ด๋ฒˆ ํฌ์ŠคํŒ…์„ ์ž‘์„ฑํ•˜๋ฉด์„œ Spring Security์—์„œ ์™œ ์ž๊พธ ์—ฌ๋Ÿฌ๊ฐ€์ง€ Filter๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ Secureํ•œ ์ž‘์—…๋“ค์„ ์ˆ˜ํ–‰ํ•˜๋Š”์ง€ ์•Œ๊ฒŒ ๋˜์–ด Spring Security๋ฅผ ์ ์šฉํ•˜๊ณ  ํ•™์Šตํ•  ๋•Œ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ํฌ์ŠคํŒ…์œผ๋กœ Spring Security์—์„œ์˜ Filter์™€ ํ”„๋กœ์ ํŠธ์—์„œ ๋งก์•˜๋˜ CorsFilter ์ ์šฉ์— ๋Œ€ํ•ด์„œ ์ž‘์„ฑํ•ด๋ณด๊ณ , ์œ„ 2๊ฐ€์ง€ ๊ฐœ๋…๊ณผ ๋น„์Šทํ•œ AOP ์— ๋Œ€ํ•ด์„œ๋„ ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿคญ

์ฐธ๊ณ ๋ฌธ์„œ


[Spring] ํ•„ํ„ฐ(Filter) vs ์ธํ„ฐ์…‰ํ„ฐ(Interceptor) ์ฐจ์ด ๋ฐ ์šฉ๋„

(Spring)Filter์™€ Interceptor์˜ ์ฐจ์ด

Spring Filter, Interceptor ๊ทธ๋ฆฌ๊ณ  AOP

[Spring] Filter, Interceptor, AOP ์ฐจ์ด ๋ฐ ์ •๋ฆฌ

[์นด์นด์˜ค ๋ฉด์ ‘] Spring Filter, Interceptor, AOP

Filter ์™€ Interceptor์˜ ์ฐจ์ด๋ž€?

[Java][Spring] Filter์™€ Interceptor

Spring Interceptor๋ž€ ๋ฌด์—‡์ธ๊ฐ€. ํ•„ํ„ฐ์™€ ์ธํ„ฐ์…‰ํ„ฐ์˜ ์ฐจ์ด

Filter VS Interceptor

[Spring]Dispatcher-Servlet(๋””์ŠคํŒจ์ฒ˜ ์„œ๋ธ”๋ฆฟ)์ด๋ž€?

์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ์™€ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ

[์Šคํ”„๋ง] ์Šคํ”„๋ง์—์„œ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ

0๊ฐœ์˜ ๋Œ“๊ธ€