spring security ๊ธฐ๋ณธ ๊ฐ๋
์คํ๋ง ๊ณต๋ถํ๋ฉด์ ์ ๋ฆฌํ ๋ด์ฉ ์ ๋๋ค !
์ค๋ฅ๊ฐ ์๋ค๋ฉด ๋๊ธ๋ก ๋จ๊ฒจ์ฃผ์ธ์ :)
1. spring security
2. ๋์ ๊ณผ์
3. ์ฌ์ฉ ๋ฐฉ๋ฒ
1. spring security
์คํ๋ง ๊ธฐ๋ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ธ์ฆ, ๊ถํ, ๊ด๋ฆฌ, ๋ฐ์ดํฐ ๋ณดํธ ๋ฑ์ ๋ณด์ ์ค์ ์ ์ํ ํ๋ ์์ํฌ์ด๋ค.
- ์ธ์ฆ
์ฌ์ฉ์์ ์ ์์ ํ์ธํ๋ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ ๋ค๋ฃฌ๋ค.
ํผ ๊ธฐ๋ฐ์ ๋ก๊ทธ์ธ, OAuth, HTTP Basic ์ธ์ฆ ๋ฑ์ ์ง์ํ๋ค.
- ๊ถํ
์ธ์ฆ๋ ์ฌ์ฉ์์ ๋ํด ํน์ ๋ฆฌ์์ค์ ๋ํ ์ ๊ทผ ๊ถํ์ ๋ถ์ฌํ๋ค.
- ๋ณด์ ํํฐ
SecurityFilterChain์ HTTP ๋ณด์ ํํฐ๋ค์ ์ฒด์ธ์ ๊ตฌ์ฑํ๋ ์ญํ ์ ํ๋ค.
๋ณด์์ ๋ํ ์ค์ ์ ํ ๋ ์ ์ํ์ฌ ์ฌ์ฉํ๋ค.
์์ ์ค์ ํด๋์ค์์ OAuth2 ๋ณด์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋ค.
๊ทธ ์ธ์๋ UsernamePasswordAuthenticationFilter๋ ํผ ๊ธฐ๋ฐ ๋ก๊ทธ์ธ์ ์ฒ๋ฆฌ, BasicAuthenticationFilter๋ HTTP Basic ์ธ์ฆ ์ฒ๋ฆฌํ ์ ์๋ค.
2. ๋์ ๊ณผ์
1. ์ฌ์ฉ์์ ์ธ์ฆ ์์ฒญ์ด ๋ค์ด์จ๋ค.
2. Authotication Filter์์ ์ธ์ฆ ์์ฒญ์ ๊ฑธ๋ฌ Authotication Manger๋ก ๋ณด๋ธ๋ค.
3. Authotication Manager๋ ๋ฑ๋ก๋ Authotication Provider๋ฅผ ์กฐํํ๋ฉฐ ์ธ์ฆ์ ์์ฒญํ๋ค.
4. ํด๋น Authotication Provider์์ ์ค์ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋ค.
5. ์ค์ ๋ฐ์ดํฐ๋ฅผ UserDetails ๊ฐ์ฒด์ ๋ด์์ ๊ฐ์ฒด๋ฅผ returnํ๋ค.
6. ๊ฐ์ฒด๋ SecurityContextHolder์ ์ ์ฅ๋์ด ์ ์ ์ ๋ณด๋ฅผ Controller์์ ์ฌ์ฉํ๋ค.
3. ์ฌ์ฉ ๋ฐฉ๋ฒ
- build.gradle
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.boot:spring-security-test'
์ฒซ ๋ฒ์งธ๋ก spring security๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์์กด์ฑ์ ์ถ๊ฐํด์ค๋ค.
- SecurityConfig.java
public SecurityFilterChain ํจ์๋ช (HttpSecurity httpSecurity) throws Exception {} ๋ฉ์๋๋ฅผ ๋ง๋ค์ด์ ํ์ํ ๋ด์ฉ์ ์์ฑํด์ค๋ค.
์ฐธ๊ณ ํ ์ฌ์ดํธ
https://www.elancer.co.kr/blog/view?seq=235
https://spring.io/guides/gs/securing-web (spring security ๊ณต์ ์ฌ์ดํธ)
๋ค์ ํฌ์คํ ์์ ๋ง๋์ !
'๐ผ study > ๐ฒ tech' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[infra] AWS EC2 ๋ฐฐํฌํ๊ธฐ (0) | 2024.05.09 |
---|---|
[security] ์๋ฒ ๊ธฐ๋ฐ ์ธ์ฆ(์ฟ ํค, ์ธ์ )๊ณผ ํ ํฐ ๊ธฐ๋ฐ ์ธ์ฆ(JWT, oauth2) (0) | 2024.04.18 |
[javascript] javascript ๊ธฐ๋ณธ ๊ฐ๋ (feat. nodejs) (0) | 2024.04.15 |
[javascript] javascript ํต์ฌ ๋ฌธ๋ฒ (0) | 2024.04.08 |
[java] java ๊ธฐ์ด ๋ฌธ๋ฒ ์ ๋ฆฌ - ๋ฌธ์์ด, ๋ฌธ์ (0) | 2024.04.08 |