이 글은 정수원님의 Infrean 강의를 학습한 내용을 정리하여 작성합니다.
Form 인증 - 인증 사용자 정보 구하기
1. 애플리케이션 전역
Account account = (Account) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = account.getUsername();
2. Spring MVC
Authentication, Principal
public String getUsername(Authentication authentication, Principal principal) {
Account account = (Account) authentication.getPrincipal();
Account account = (Account)((UsernamePasswordAuthenticationToken)principal).getPrincipal();
String username = account.getUsername();
}
@AuthenticationPrincipal
- 인증 성공 이후 생성된 Authentication 객체의 principal 속성에 저장되어 있는 객체
public ModelAndView getUsername(@AuthenticationPrincipal Account account) {
String username = account.getUsername();
}
'스프링 시큐리티 > 실전프로젝트 - 인증 프로세스 Form 인증 구현' 카테고리의 다른 글
인증 거부 처리 - Access Denied (0) | 2023.02.12 |
---|---|
인증 실패 핸들러: CustomAuthenticationFailureHandler (0) | 2023.02.12 |
인증 성공 핸들러: CustomAuthenticationSuccessHandler (0) | 2023.02.12 |
인증 부가 기능 - WebAuthenticationDetails, AuthenticationDetailsSource (0) | 2023.02.12 |
로그아웃 및 인증에 따른 화면 보안 처리 (0) | 2023.02.12 |