springSecurityConcepts
์คํ๋ง ์ํ๋ฆฌํฐ ์ฃผ์ ๊ฐ๋
์ ๋ฆฌ
์ธ์ฆ์ ์ฒ๋ฆฌํ๋
AuthenticationManager
๋ authenticate๋ผ๋ ํ๋์ ๋ฉ์๋๋ง์ ๊ฐ์ง๊ณ ์๋ค. ์๋ฅผ ๋ค์ด, formLogin ์งํ ์ ์์ด๋์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ด ๋ฉ์๋๋ฅผ ํตํด ์ฒ๋ฆฌํ๋ค.authenticate
ํจ์์Authentication๊ฐ์ฒด
๋ฅผ ์ ๋ฌํ๊ณAuthentication๊ฐ์ฒด
๋ฅผ ๋ฐํํ๋๋ฐ ์ธ์ฆ๋๊ธฐ ์ ์๋Authentication
์ ํ๋์ธisAuthenticated
๊ฐ false์ธ ์ํ์ด๊ณ , ํจ์ ์คํ ํ์ ์ธ์ฆ์ด ์๋ฃ๋๋ฉดisAuthenticated
๋ true๊ฐ ๋๋ค.AuthenticationManager
์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ ๊ตฌํ์ฒด๋ ์ผ๋ฐ์ ์ผ๋กProviderManager
์ด๋ค.AuthenticationManager
์ ๊ธฐ๋ฅ์ด ์ ์ฌํ์ง๋ง ๋ค์ํAuthentication
ํ์ ์ ์ง์ํ๋supports
๋ฉ์๋๊ฐ ์ถ๊ฐ๋์ด ์๋ค.(ProviderManager -> AuthenticationProvider -> AuthenticationManager)
ProviderManager
๋ ์ ํ์ ์ผ๋ก parent๋ฅผ ๊ฐ์ง ์ ์๋๋ฐ ์ด parent๋ ๋ชจ๋ supports๋ฉ์๋์์ ํ์ ์ง์์ ์ฒดํฌํ์์๋ ์คํจํ ์fallback
์ฒ๋ผ ๋์ํ๋ค.์ธ๊ฐ์ ๊ถํ์ ํ๋จํ๊ธฐ ์ํด์
AccessDecisionVoter
๋ฅผ ์ฌ์ฉํ๋๋ฐ, vote๋ฉ์๋์์authentication
๊ฐ์ฒด์ ์ ๊ทผ ๋์์ธObject
, ์ ๊ทผ ๊ถํ์ธConfigAttribute
ํ๋ผ๋ฏธํฐ๋ก ๋๊ธด๋ค. ์ดํ ๋ฉ์๋๊ฐ ์คํ๋๋ฉด vote์ฌ๋ถ(๊ถํ ์ธ๊ฐ ์ฑ๊ณต ์ฌ๋ถ)๋ฅผ int๋ก ๋ฐํํ๋ค.default
AccessDecisionManager
๋ ํ ๊ฐ์ voter๋ผ๋ affirmํ๋ฉด ํด๋น ์์์ ์ก์ธ์ค๋ฅผ ํ์ฉํ๋ค.
DelegatingFilterProxy
๋ ์๋ธ๋ฆฟ ์ปจํ ์ด๋์ lifecycle๊ณผ Springโs ApplicationContext๋ฅผ ์๋ ์ญํ ์ ํ๋ค. ์๋ธ๋ฆฟ ํํฐ๋ ์คํ๋ง ์ปจํ ์ด๋์ bean๋ค์ ์ธ์ํ ์ ์์ผ๋ฏ๋ก bean์ธFilterChainProxy
์ ๋ชจ๋ ์์ ์ ์์ํ๋ค.์๋ธ๋ฆฟ ์ปจํ ์ด๋์
DelegatingFilterProxy
์ ์ํด ์ญํ ์ ์์๋ฐ๋FilterChainProxy
๋ ์ผ๋ฐ์ ์ผ๋ก bean์ด๋ค.FilterChainProxy
๋ ์คํ๋ง ์ํ๋ฆฌํฐ์ ์๋ธ๋ฆฟ ์ง์์ ์์์ ์ด๋ค. ๋ฐ๋ผ์ ๋๋ฒ๊ทธํ๊ธฐ ์ข์ ์์น์ด๋ค.FilterChainProxy
๋ ์คํ๋ง ์ํ๋ฆฌํฐ์ ํต์ฌ์ด๋ค. ๋ฐ๋ผ์ ์ต์ ์ผ๋ก ์ ์ฉ๋์ง ์๋ ํ์์ ์ธ ๊ธฐ๋ฅ์ ์คํํ๊ธฐ์ ์ข์ ์์น์ด๋ค. ์๋ฅผ ๋ค์ด, ๋ฉ๋ชจ๋ฆฌ ๋์๋ฅผ ๋ง๊ธฐ ์ํดThreadLocal
๋ก ์ฌ์ฉ๋ SecurityContext๋ฅผ clearํ๋ ๊ฒ์ด ์๋ค.์๋ธ๋ฆฟ ์ปจํ ์ด๋์์ ์๋ธ๋ฆฟ Filter๋ ์ค์ง
url
์ ๊ทผ๊ฑฐํด์ ๋ฐ๋๋์ง๋ง,FilterChainProxy
๋HttpServletRequest
๋ด๋ถ์ ํ๋๋ค์ ์ฌ์ฉํ ์ ์์ด ์ธ๋ฐํ ๋งค์นญ์ด ๊ฐ๋ฅํ๋ค. ๋ฐ๋ผ์FilterChainProxy
๋ ์ด๋คSecurity Filter Chain
์ด ๋ฐ๋๋์ด์ผ ํ๋์ง๋ฅผ ๊ฒฐ์ ํ ์ ์๋ค.์๋ ๊ทธ๋ฆผ์์ Bean Filter๋ฅผ
FilterChainProxy
๋ผ๊ณ ํด์ํ ์ ์๋ค.

SecurityContextHolder > SecurityContext > Authentication > principal, credentials, authorities
์์ผ๋ก ๊ฐ์ฒด์ ํ๋๊ฐ ์ ํด์ง๋ ๊ตฌ์กฐ์์SecurityContextHolder
๋ThreadLocal
์ ์ฌ์ฉํด์SecurityContext
์ ๊ฐ์ ํ ๋นํ๋ค. ๋ฐ๋ผ์ ๊ฐ์ ์ค๋ ๋์ ๋ฉ์๋๋ผ๋ฉด ๊ตณ์ด ํ๋ผ๋ฏธํฐ๋ก ๋๊ธธ ํ์ ์์ด ํญ์ availableํ๋ค.์ค๋ ๋ํ์ ์ฌ์ฉํ๋ ๊ตฌ์กฐ์์ ๋ณด์์ ์ด์ ๋ก ํ๊ฑฐ๋ ์ ํํ ์ฒ๋ฆฌ๋ฅผ ์ด์ ๋ก ํด์ ThreadLocal์ธ SecurityContext๋ฅผ ์ฌ์ฉ ํ์๋ ํญ์ thread๋ฅผ clearํด์ผ ํ๋๋ฐ, ์ด๋ฅผ
FilterChainProxy
์์ ์ฒ๋ฆฌํด์ค๋ค.GrantedAuthority
๋ ์ ์ ์๊ฒ ํ๋ฝ๋ ๊ถํ์ ๋ํ๋ธ๋ค. ํ๋์ ์ญํ ์ ์ฌ๋ฌ ๊ฐ์ ๊ถํ์ ๊ฐ์ง ์ ์๋ค. ๊ถํ์ ๋ณดํตROLE_ADMINISTRATOR
orROLE_HR_SUPERVISOR
์ด๋ฌํ ํํ๋ก ์ฐ์ธ๋ค.GrantedAuthority
s๋ ๋ณดํตUserDetailsService
์ ์ํด load๋๋ค.AuthenticationEntryPoint
๋ฅผ ๊ตฌํํ๋ ๊ฒ์ ํด๋ผ์ด์ธํธ๋ก๋ถํฐcredential
์ ์์ฒญํ๋ ์ญํ ์ ํ๋ค.์ด๋ ๋ก๊ทธ์ธ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธํ๊ฑฐ๋, WWW-Authenticate header๋ก ์๋ตํ๋ ๊ฒ์ด ๋ ์ ์๊ฒ ๋ค.AbstractAuthenticationProcessingFilter
๋ ์ ์ ์credential
์ ์ธ์ฆํ๋ base filter๋ก ์๋ํ๊ณ , ์ ํ์ ์ผ๋กAuthenticationEntryPoint
์ ์ฌ์ฉํ์ฌcredential
์ ์์ฒญํ๋ค.์ ์ ๊ฐ
credentials
์ ์ ์ถํ๋ฉด,AbstractAuthenticationProcessingFilter
๋HttpServletRequest
๋ก๋ถํฐ ์ธ์ฆ ๊ณผ์ ์ ๊ฑฐ์นAuthentication
๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค. ์์ฑ๋Authentication
๊ฐ์ฒด๋AbstractAuthenticationProcessingFilter
์ ํ์ํด๋์ค์ ๋ฐ๋ผ ๋ค๋ฅด๋ค. ์๋ฅผ ๋ค์ด, For example,UsernamePasswordAuthenticationFilter
๋HttpServletRequest
๋ก๋ถํฐUsernamePasswordAuthenticationToken
์ ์์ฑํ๋ค.Authentication
๊ฐ์ฒด๋ ์ธ์ฆ ๊ณผ์ ์ ๊ฑฐ์น๊ธฐ ์ํดAuthenticationManager
๋ก ์ ๋ฌ๋๋ค. ํ์ฌisAuthenticated
์ ์ํ๋ true๊ฐ ์๋ ๊ฒ์ด๋ค.์ธ์ฆ์ด ์คํจํ๋ฉด 3๋ฒ ๊ณผ์ ์ ๊ฑฐ์น๋ฉฐ,
SecurityContextHolder
๋ clear out๋๋ค.์ธ์ฆ์ด ์ฑ๊ณตํ๋ฉด 4๋ฒ ๊ณผ์ ์ ๊ฑฐ์น๋ค.
SessionAuthenticationStrategy
๊ฐ ์๋ก์ด ๋ก๊ทธ์ธ์ ๊ฐ์งํ๋ค.SecurityContextHolder
์Authentication
๊ฐ์ฒด๊ฐ set๋๋ค. ๊ทธ ํ,SecurityContextPersistenceFilter
๊ฐHttpSession
์SecurityContext
๋ฅผ ์ ์ฅํ๋ค.๋ฆฌ๋ฉค๋ฒ๋ฏธ ๊ธฐ๋ฅ์ ํ์ฑํํ์ ๊ฒฝ์ฐ
RememberMeServices.loginSuccess
๊ฐ ๋ฐ๋๋๋ค.ApplicationEventPublisher
๋InteractiveAuthenticationSuccessEvent
๋ฅผ ๋ฐํํ๋ค. 5.AuthenticationSuccessHandler
๊ฐ ๋์ํ๋ค.
์๋๋ Form Login์ธ์ฆ ๊ณผ์ ์ด๋ค.
๋จผ์ ์ ์ ๊ฐ ์ธ์ฆ๋์ง ์์ ์์ฒญ์ /private (์ ์ ๋ ์ด url์ ๋ํด ๊ถํ์ด ์์)๋ก ๋ณด๋ธ๋ค.
FilterSecurityInterceptor
๋ ์ธ์ฆ๋์ง ์์ ์์ฒญ์ ๋ํดAccessDeniedException
์ throwํ๋ค.์ ์ ๊ฐ ์ธ์ฆ๋์ง ์์๊ธฐ ๋๋ฌธ์,
ExceptionTranslationFilter
๋ ์ค์ ๋AuthenticationEntryPoint
์ ์ฌ์ฉํด ๋ก๊ทธ์ธ ํ์ด์ง๋ก ์์ฒญ์ ๋ฆฌ๋ค์ด๋ ํธํ๋ค. ๋๋ถ๋ถ์ ์ผ์ด์ค์์AuthenticationEntryPoint
์LoginUrlAuthenticationEntryPoint
์ ์ธ์คํด์ค๋ก ๋ํ๋๋ค.๋ธ๋ผ์ฐ์ ๋ ๋ก๊ทธ์ธ ํ์ด์ง๋ก get์์ฒญ์ ๋ณด๋ธ๋ค.
์๋ฒ์์ ๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ๋ด๋ ค์ค๋ค.
์๋๋ username & password ์ธ์ฆ๊ณผ์ ์ด๋ค. Servlet Applications - Authentication - Authentication Architecture ์์ ์ดํด๋ดค๋
AbstractAuthenticationProcessingFilter
์ ์ธ์ฆ๊ณผ์ ๊ณผ ์๋นํ ์ ์ฌํ๋ฉฐ,AbstractAuthenticationProcessingFilter
์ดUsernamePasswordAuthenticationFilter
๋ก ๋ฐ๋๊ณAuthentication
๊ฐ์ฒด๊ฐUsernamePasswordAuthenticationToken
์ผ๋ก ๋ฐ๋์๋ค. ์ฌ๊ธฐ์์UsernamePasswordAuthenticationFilter
๋AbstractAuthenticationProcessingFilter
์ ์์ํ ํด๋์ค์ด๋ค.
UserDetails
๋UserDetailsService
์ ์ํด ๋ฆฌํด๋๋ค.DaoAuthenticationProvider
๋UserDetails
์ด ์ ํจํ์ง ์ฒดํฌํ ํAuthentication
์ ๋ฆฌํดํ๋ค.UserDetailsService
๋ username, password, and other attributes๋ฅผ ๋ฐ๊ธฐ ์ํดDaoAuthenticationProvider
์ ์ํด ์ฌ์ฉ๋๋ค. Spring Security๋UserDetailsService
๋ฅผ ๊ตฌํํ in-memory์ JDBC์ ๋ ๊ฐ์ง ๋ฐฉ์์ ๊ตฌํ์ฒด๋ฅผ ์ ๊ณตํ๋ค.DaoAuthenticationProvider
๋AuthenticationProvider
์ ๊ตฌํ์ฒด ์ค ํ๋๋กUserDetailsService
์PasswordEncoder
๋ฅผ ์ฌ์ฉํด์ username๊ณผ password๋ฅผ ์ธ์ฆํ๋ค.
Last updated