Web/Spring

Spring Security

Kim Jinung 2023. 6. 12. 12:50

https://spring.io/guides/gs/securing-web/

 

Getting Started | Securing a Web Application

Suppose that you want to prevent unauthorized users from viewing the greeting page at /hello. As it is now, if visitors click the link on the home page, they see the greeting with no barriers to stop them. You need to add a barrier that forces the visitor

spring.io

 

간단한 로그인 구현 예제인데 사용만 할 뿐 내부가 어떻게 돌아가는지 이해하기에는 어렵다.

 

https://docs.spring.io/spring-security/reference/servlet/authentication/architecture.html

 

Servlet Authentication Architecture :: Spring Security

ProviderManager is the most commonly used implementation of AuthenticationManager. ProviderManager delegates to a List of AuthenticationProvider instances. Each AuthenticationProvider has an opportunity to indicate that authentication should be successful,

docs.spring.io

Authentication and Access Control

 

Who are you? (Authentication)

What are you allowed to do? (Access control, authorization)

 

인증을 거치면 인가를 확인해야한다.

 

 

Authentication

인증에는 오직 한가지의 인터페이스와 메서드가 존재함 AuthenticationManager 그리고 authentication

그리고 대표적인 구현체는 Provide AuthenticationProvider가 존재한다. 

 

 

생각보다 볼륨이 크다.

1. 자주 사용 하는 기능 위주로 빠르게 사용해보기

2. 내부 코드 뜯어보기

 

 

https://docs.spring.io/spring-security/reference/servlet/authentication/architecture.html

 

Servlet Authentication Architecture :: Spring Security

ProviderManager is the most commonly used implementation of AuthenticationManager. ProviderManager delegates to a List of AuthenticationProvider instances. Each AuthenticationProvider has an opportunity to indicate that authentication should be successful,

docs.spring.io

SecutiryContextHolder가 JPA의 Persist Context와 유사한 역할을 하는 것으로 보이고, 요 안에 빈과 같이 Authentication 객체를 가지고 인증된 사용자 정보를 관리한다. SecurityContextHolder는 내부적으로 쓰레드로컬을 사용한다. 따라서 서버를 클러스터로 구성한 경우에, 유저가 A 노드에 요청하고 다음에 B에 요청하면 인증을 받을 수가 없다. 이런 경우 인증서버 or Single signon 서버를 앞으로 따로 빼낸다. 

 

아니면 SecutiryContextRepository 구현체를 사용해서 Redis같은 key-value 스토어에 저장할 수도 있는 듯

(확실히 인프라나 아키텍처에 더 관심ㅇ 많은거 같은데 지금 당장은 필요한게 아니므로 패스)