본문 바로가기

Spring/Security

Hello, Spring Security

 

1. 스프링 시큐리티란?

    인증, 인가 등 스프링 웹 개발 시 필요한 사용자 관리 기능을 구현하는데 도움을 주는 프레임워크이다.

    이를 사용함으로써 보안 관련 기능을 보다 간편하고 빠르게 구현할 수 있다.

 

 

2. 작동원리?

스프링 시큐리티의 구조

 

1. 인증 요청을 하면 AuthenticationFilter가 요청을 가로채어 UsernamePasswordAuthenticationToken 인증 객체를 생성한다.

2. 이 객체가 ProviderManager에게 전달되면 AuthenticationProvider(s)에 토큰을 보내 인증을 요구한다. 

3. AuthenticationProvider(s)는 UserDetailsService에게 해당 로그인 폼에 대한 정보를 db에서 가져오라고 시킨다.

4. UserDetailsService는 해당 ID에 해당하는 정보를 UserDetails 형으로 가져온다.

5. AuthenticationProvider는 UserDetails와 로그인 정보를 비교하여 인증을 한다.

6. 인증이 완료되면 Authentication 객체를 반환한다.

7. 최종적으로 AuthenticationFilter가 Authentication 객체를 반환하고, 이는 SecurityContext에 저장된다.(세션)

 

 

 

자세한 개발은 webClass 프로젝트에서 직접 하기로 하자