본문 바로가기
Back-End/Spring Security

Spring Security Authentication (3) UserDetails

by sharekim 2021. 3. 16.

#UserDetails

UserDetails is returned by the UserDetailsService. The DaoAuthenticationProvider validates the UserDetails and then returns an Authentication that has a principal that is the UserDetails returned by the configured UserDetailsService.

UserDetails는 UserDetailService에 의해 반환된다. DaoAuthenticationProvider 가 UserDetails를 유효화하고 인증한다.

Authentication은 UserDetails의 핵심이며 UserDetailsService에 의해 반환된다.

 

#UserDetailsService

UserDetailsService is used by DaoAuthenticationProvider for retrieving a username, password, and other attributes for authenticating with a username and password. Spring Security provides in-memory and JDBC implementations of UserDetailsService.

UserDetailsService는 주로 DaoAuthenticationProvider에 의해 사용된다.

스프링시큐리티는 UserDetailsServices에 in-memory와 JDBC 를 제공한다.

 

You can define custom authentication by exposing a custom UserDetailsService as a bean. For example, the following will customize authentication assuming that CustomUserDetailsService implements UserDetailsService:

UserDetailsService를 Bean으로 생성하면 사용자화된 Authentication을 정의할 수 있다.

예시로 UserDetails를 구현하는 CustomUserDetailsService를 가정할 수 있다.

 

Example 70. Custom UserDetailsService Bean

<b:bean class="example.CustomUserDetailsService"/>

 

 

UserDetails는 클래스인데, 

Modifier and Type Method and Description
java.util.Collection<? extends GrantedAuthority> getAuthorities()

Returns the authorities granted to the user.

java.lang.String getPassword()

Returns the password used to authenticate the user.

java.lang.String getUsername()

Returns the username used to authenticate the user.

Username과 Password 그리고 AUthorities를 반환할 수 있다. 

 

스프링 시큐리티에서 정의하고 있는 인증이라는 것 자체가

 

Authentication is how we verify the identity of who is trying to access a particular resource

누가 특정 소스에 접근하려고 하는지를 확인하는 것

 

이기 때문에

Form-Login을 통한 로그인 시도 = > JDBC를 통한 인증 => UserDetails 객체 반환 => 객체정보에서 유저확인

의 과정으로 인증이 진행되는 것 같다.

 

* 모든 자료의 출처는 Spring.io 입니다.

댓글