μ€νλ§ μν리ν°(Spring Security)λ μλΈλ¦Ώ μ€νμ νν°λ§(Filtering) κΈ°μ μ μ΄μ©νκ³ μμ΅λλ€. κ·Έλμ νν°μ κ°λ μ μ νμκ° μμ΅λλ€. μλΈλ¦Ώ 4μμλ νν°μ λν΄ λ€μκ³Ό κ°μ΄ μ€λͺ ν©λλ€.
A filter is a reusable piece of code that can transform the content of HTTP requests, responses, and header information. Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.
μλΈλ¦Ώ μ€νμ μΉ κΈ°μ μ μ νλ κ²μ΄λ―λ‘ νν° μμ HTTP μμ²κ³Ό μλ΅μ μ²λ¦¬νλ κΈ°λ₯μ μνν©λλ€. λ€λ§ μμ μ€λͺ μ μλ―μ΄ μλΈλ¦Ώμ΄ μλ΅ μ체λ₯Ό μλ‘ μμ±νλ κ²μ΄λΌλ©΄ νν°λ κ·Έλ κ² μμ±λ μλ΅μ λ³ννλ μν μ ν©λλ€. λ€μ΄μ€λ μμ²μ λν΄μλ κ·Έ μμ²μ΄ 컨νΈλ‘€λ¬μ λλ¬νκΈ° μ μ κ°μ νμ¬ μ΄λ€ κΈ°λ₯μ μνν μ μμ΅λλ€.
μ°Έκ³ λ‘ μ¬μ©μ μμ²μ λν΄ "μΈλ°μ΄λ(inbound)", "λ€μ΄μ€νΈλ¦Ό(downstream)"μ΄λΌλ ννμ μ¬μ©νκ³ λ°λλ‘ μλ²μμ 리ν΄λλ μλ΅μ λν΄ "μμλ°μ΄λ(outbound)", "μ μ€νΈλ¦Ό(upstream)"μ΄λΌλ μ©μ΄λ₯Ό μ¬μ©ν©λλ€.
νν°μ κ°μ₯ μ€μν νΉμ§μ λ€μμ νν°λ€μ μμλλ‘ κ±°μΉλ νν° "체μΈ"μΌλ‘ λμμν¬ μ μλ€λ κ²μ
λλ€. Filter μΈν°νμ΄μ€λ doFilter(ServletRequest request, ServletResponse response, FilterChain chain)λΌλ λ©μλλ₯Ό μ€ννμ¬ ν΄λΉ νν°μ κΈ°λ₯μ μννκ³ λ€μ FilterChain μΈν°νμ΄μ€μ doFilter(ServletRequest request, ServletResponse response)μ νΈμΆνμ¬ λ€μ νν°μ doFilterλ₯Ό μ€ννλ μμΌλ‘ "chaining" λμ΄ μμ΅λλ€.
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
}
μ€νλ§ μνλ¦¬ν° κ³΅μ λ¬Έμμ μ΄λ¬ν νν° κΈ°μ μ μ΄λ»κ² μ΄μ©νκ³ μλμ§ μ μ€λͺ
λμ΄ μμ΅λλ€. μ€νλ§ νλ μμν¬μ DelegatingFilterProxyλΌλ νν°λ₯Ό μ¬μ©νμ¬ μν리ν°μ FilterChainProxyλΌλ λΉμκ² κ·Έ μν μ μμνκ³ μ΄κ²μ λ€μ μν리ν°κ° μ 곡νλ "Security filter chain"μ ꡬλνλλ‘ λμ΄ μμ΅λλ€. 곡μ λ¬Έμμ κ·Έλ¦Όμ κ·Έλλ‘ μΈμ©ν΄λ³΄κ² μ΅λλ€.
Security filter chainμ μ¬λ¬ κ°μ 보μ νν°λ€λ‘ ꡬμ±λμ΄ λ€μν 보μ κ΄λ ¨ κΈ°λ₯λ€μ κ°λ°μμκ² μ 곡ν©λλ€.
Security filter chain: [
DisableEncodeUrlFilter
WebAsyncManagerIntegrationFilter
SecurityContextPersistenceFilter
HeaderWriterFilter
CsrfFilter
LogoutFilter
UsernamePasswordAuthenticationFilter
DefaultLoginPageGeneratingFilter
DefaultLogoutPageGeneratingFilter
BasicAuthenticationFilter
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor
]
곡μ λ¬Έμμ μ€λͺ μ μΈμ©ν©λλ€.
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.
보μ νν°λ€μ μμλ μλ μ½λλ₯Ό μ°Έκ³ νλ©΄ λκ² μ΅λλ€(μκ³ μΆλ€λ©΄).
