์๋ ํ์ธ์, cool & softํ ๋ฐฑ์๋ ๊ฐ๋ฐ์๊ฐ ๋๊ณ ์ถ์ ํ ๋์ ๋๋ค.
| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- ๋ฐฑ์๋
- springSecurity
- MacOS
- ๊ณ ์ฉ๋ ธ๋๋ถ
- Linux
- network
- backend
- ubuntu
- Spring
- nlb
- java
- springboot
- ์๊ณ ๋ฆฌ์ฆ
- pfsense
- JPA
- ๋น ์ฑ
- CS
- ๋ณด์
- ์น
- ๋ก๋๋ฐธ๋ฐ์
- AUSG
- ์๋ฒ
- server
- ๋ฐฑ์ค
- ํด์ปคํค
- docker
- be
- ๊ตฌ๋ฆํค๋ฅ๋ค์ด๋ธ
- ๊ตฌ๋ฆํค
- kdt
- Today
- Total
Code Art Online
[Spring Security] docs : Architecture (1) - Filter ๋ณธ๋ฌธ
๐ป Spring Security docs ๊ฒ์๊ธ ๋ชฉ์ฐจ
1. [Spring Security] docs : Getting Started
[Spring Security] docs : Getting Started
Spring Security๋ ์ธ์ฆ, ๊ถํ๋ถ์ฌ ๋ฐ ์ผ๋ฐ์ ์ธ ๊ณต๊ฒฉ์ ๋ํ ๋ณดํธ๋ฅผ ์ ๊ณตํ๋ ํ๋ ์์ํฌ์ด๋ค. ๊ฐ๋ฐ์๊ฐ ๋ณด์ ์ค์ ์ ์ถ๊ฐ์ ์ผ๋ก ์ ๊ฒฝ์ฐ์ง ์๋๋ผ๋ ์์ ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น ๋ฅด๊ฒ ๊ตฌ์ถํ ์ ์๋
kiritoni.tistory.com
2. [Spring Security] docs : Architecture (1) - Filter
[Spring Security] docs : Architecture (1) - Filter
Spring Security docs Hello Spring Security :: Spring SecurityRunning Spring Boot Application $ ./mvnw spring-boot:run ... INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration : Using generated security password: 8e557245-73e2-4286-969a
kiritoni.tistory.com
๐ฑ Spring Security docs ๋ฐ๋ก๊ฐ๊ธฐ
Architecture :: Spring Security
The Security Filters are inserted into the FilterChainProxy with the SecurityFilterChain API. Those filters can be used for a number of different purposes, like authentication, authorization, exploit protection, and more. The filters are executed in a spec
docs.spring.io
Spring Security์ Servlet ์ง์์ Servlet Filters์ ๊ธฐ๋ฐ์ ๋๊ณ ์๋ค.
๋ฐ๋ผ์ ์ผ๋ฐ์ ์ธ ํํฐ์ ์ญํ ์ ๋จผ์ ์ดํด๋ณด์์ผ ํ๋ค.
๋จ์ผ HTTP ์์ฒญ์ ๋ํ ํธ๋ค๋ฌ ๊ณ์ธต

ํด๋ผ์ด์ธํธ๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ HTTP ์์ฒญ์ ๋ณด๋ด๋ฉด, ์น ์ปจํ ์ด๋๋ ์์ฒญ URI ๊ฒฝ๋ก๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฒ๋ฆฌํ FilterChain์ ๋ง๋ ๋ค.
FilterChain์ ์ฌ๋ฌ๊ฐ์ Filter ์ธ์คํด์ค์ ํ๋์ Servlet์ผ๋ก ๊ตฌ์ฑ๋์ด์์ผ๋ฉฐ, HttpServletRequest๊ฐ ๊ฐ ํํฐ๋ฅผ ๊ฑฐ์ณ ์ต์ข ์ ์ผ๋ก servlet์ผ๋ก ์ ๋ฌ๋๋ค.
๐ ์์ฝ. ver
์ปจํ ์ด๋๋
1. FilterChain์ ์์ฑํ๊ณ ,
2. ํด๋น ์ฒด์ธ์ด URI ๊ฒฝ๋ก์ ๋ฐ๋ผ ์ ์ ํ Filter์ Servlet ์ฌ์ฉํด ์์ฒญ์ ์ฒ๋ฆฌ
Spring MVC ์ ํ๋ฆฌ์ผ์ด์ ์์ Servlet์ DispatcherServlet์ ์ธ์คํด์ค์ด๋ค.
DispatcherServlet์ Spring MVC์ ํต์ฌ์ธ๋ฐ, ๋ชจ๋ HTTP ์์ฒญ์ ์ฒ๋ฆฌํ๋ '์ค์ ์ง์ ์ '์ญํ ์ ํ๋ค.
ํ ๋ฒ์ ํ๋์ Servlet์ด ํน์ HttpServletRequest์ HttpServletResponse๋ฅผ ์ฒ๋ฆฌํ ์ ์์ง๋ง, ์ฌ๋ฌ๊ฐ์ Filter๋ ์์ฒญ ์ฒ๋ฆฌ ๊ณผ์ ์์ ๋ค์ํ ์์ ์ ์ํํ ์ ์๋ค.
Filter์ ์ญํ ๊ณผ ๊ธฐ๋ฅ
- Downstream(ํ์) ํํฐ ์ธ์คํด์ค๋ ์๋ธ๋ฆฟ์ด ํธ์ถ๋์ง ์๋๋ก ๋ฐฉ์ง
- ์ฌ๊ธฐ์ ํ์์ด๋, ํ์ฌ ํํฐ ๋ค์์ ์คํ๋๋ ๊ฒ(ํํฐ/์๋ธ๋ฆฟ)์ ์๋ฏธํ๋ค.
- HttpServletRequest ๋๋ HttpServletResponse ์์
- ex. ์์ฒญ์ ๋ก๊น , ์์ฒญ ํค๋๋ฅผ ์ถ๊ฐ/์์ , ์๋ต์ ์ฝํ ์ธ ๋ฅผ ๋ฒ๊ฒฝํ ๊ฒฝ์ฐ
- FilterChain์ ํตํ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ ์ ๊ณต
- FilterChain์ ํ์ฌ ํํฐ๊ฐ ์์ฒญ ์ฒ๋ฆฌ๋ฅผ ์๋ฃํ ํ์, ๋ค์ ํํฐ/์๋ธ๋ฆฟ์ผ๋ก ์์ฒญ์ ์ ๋ฌํ๋ ๋ฉ์ปค๋์ฆ์ ์ ๊ณตํ๋ค.
- `chain.doFilter(request, response)`๋ฅผ ํธ์ถํ๋ฉด ๋ค์ ํํฐ ๋ก ์์ฒญ์ด ์ ๋ฌ๋๊ฑฐ๋, ๋ชจ๋ ํํฐ๋ฅผ ํต๊ณผํ ๊ฒฝ์ฐ ์๋ธ๋ฆฟ์ผ๋ก ์์ฒญ์ด ์ ๋ฌ๋๋ค.
- `doFilter()` ํธ์ถ์ด ์์ผ๋ฉด ํ์ฌ ํํฐ๊ฐ ์์ฒญ์ ์ฐจ๋จํ๊ฑฐ๋ ์๋ต์ ์ง์ ์์ฑํ๋ค.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
// do something before the rest of the application
chain.doFilter(request, response); // invoke the rest of the application
// do something after the rest of the application
}
ํํฐ๋ ํ์ ํํฐ ์ธ์คํด์ค์ ์๋ธ๋ฆฟ์๋ง ์ํฅ์ ๋ฏธ์น๋ค.
๋ฐ๋ผ์ ๊ฐ ํํฐ์ ์์๊ฐ ๊ฐ์ฅ ์ค์ํ๋ค.
ํํฐ์ ์คํ ์์์ ๋ฐ๋ผ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋์์ด ๋ฌ๋ผ์ง ์ ์๋ค.
๊ทธ๋ ๋ค๋ฉด ์ ํํฐ์ ์คํ ์์๊ฐ ์ค์ํ ๊น?
๊ฐ๊ฐ ์์๋ฅผ ๋ค์ด ์ดํดํด๋ณด์.
ํํฐ์ ์์๊ฐ ์ค์ํ ์ด์
1. ํํฐ์ ๊ธฐ๋ฅ์ด ์์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ค.
์ฒซ ๋ฒ์งธ ๊ฒฝ์ฐ
1. ์ธ์ฆ ํํฐ
2. ๊ถํ ๊ฒ์ฌ ํํฐ
์ ๊ฒฝ์ฐ์๋ ์ธ์ฆ์ด ๋ง์ฝ ์คํจํ๋ค๋ฉด, ๊ถํ ๊ฒ์ฌ ํํฐ์ ์์ฒญ์ด ๋๋ฌํ์ง ์๊ณ ์๋ต์ด ์์ฑ๋๋ค.
๋ ๋ฒ์งธ ๊ฒฝ์ฐ
1. ๊ถํ ๊ฒ์ฌ ํํฐ
2. ์ธ์ฆ ํํฐ
๋ฐ๋๋ก, ์ธ์ฆ ํํฐ๊ฐ ๋จผ์ ์คํ๋์ง ์๊ณ ๊ถํ ๊ฒ์ฌ ํํฐ๊ฐ ๋จผ์ ์คํ๋๋ฉด,
์ธ์ฆ๋์ง ์์ ์ฌ์ฉ์๊ฐ ๋ถํ์ํ ๊ถํ ๊ฒ์ฌ๋ฅผ ๋ฐ์ ๋ณด์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๋ค.
2. ์์ฒญ ๋ฐ ์๋ต ์์ ์ ์์๊ฐ ์ค์ํ๋ค.
1. ๋ก๊น ํํฐ ์คํ: ์์ฒญ ์ ๋ณด๋ฅผ ๋ก๊ทธ๋ก ๋จ๊ธด๋ค.
2. ๋ฐ์ดํฐ ์์ถ ํํฐ ์คํ: ์๋ต ๋ฐ์ดํฐ๋ฅผ ์์ถํ๋ค.
์ ์์๊ฐ ๋ฐ๋๋ฉด ๋ก๊น ํํฐ๊ฐ ์์ถ๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋กํ๋ ค๊ณ ํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๋ค.
3. ์์ฒญ ์ฐจ๋จ ๋ฐ ์์ธ ์ฒ๋ฆฌ
1. CSRF ๋ณดํธ ํํฐ: CSRF ๊ณต๊ฒฉ ์ฐจ๋จ
2. ์ธ์ฆ ํํฐ
๋ง์ฝ ์์ ์์๊ฐ ๋ฐ๋๋ค๋ฉด ์ธ์ฆ ํํฐ๊ฐ CSRF ๊ณต๊ฒฉ์ผ๋ก ์ธํด ๋ถํ์ํ ์์ ์ ์ํํ๊ฒ ๋๋ค.