UsernamePasswordAuthenticationToken은 Spring Security에서 사용되는 인증을 나타내는 클래스 중 하나입니다. 주로 사용자명과 비밀번호 기반의 인증 프로세스에서 사용됩니다. 이 클래스는 Authentication 인터페이스를 구현한 구체 클래스로, 사용자의 인증 정보를 담고 인증을 수행하는 데 활용됩니다.
주요 특징과 사용 예시는 다음과 같습니다:
- 구성 요소:
- principal: 인증 주체를 나타내는 객체 (일반적으로 사용자의 username 또는 email)
- credentials: 인증 주체의 자격 증명 (일반적으로 비밀번호)
- authorities: 사용자의 권한 목록을 나타내는 객체
- 사용 예시:
- 사용자가 입력한 사용자명(username)과 비밀번호(password)로 Authentication 객체를 생성하여 인증 프로세스에 활용됩니다.
- 보통 사용자가 로그인하는 경우에 사용자명과 비밀번호를 받아 UsernamePasswordAuthenticationToken을 생성하여 인증 매니저에게 전달합니다.
- 인증 프로세스:
- UsernamePasswordAuthenticationToken은 인증 필터를 통해 생성되고, AuthenticationManager를 통해 실제로 인증이 수행됩니다.
- AuthenticationProvider는 인증 요청을 처리하고, 사용자명 및 비밀번호가 올바른 경우 사용자의 권한 및 추가 정보를 포함한 Authentication 객체를 생성하여 반환합니다.
- 사용 예시 (간략한 코드 예시):
// 인증을 위한 UsernamePasswordAuthenticationToken 생성
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
// AuthenticationManager를 사용하여 실제 인증 수행
Authentication authentication = authenticationManager.authenticate(authenticationToken);
'SpringSecurity > 졸과' 카테고리의 다른 글
jwt 토큰을 이용한 다중서버 로그인 유지 (1) | 2024.07.16 |
---|---|
스프링시큐리티 csrf,cors (0) | 2024.07.16 |