이 글은 정수원님의 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();
}
'기술(Tech) > Java & Spring' 카테고리의 다른 글
인증 필터 - AjaxAuthenticationFilter (0) | 2023.02.13 |
---|---|
Ajax 인증 - 흐름 및 개요 (0) | 2023.02.12 |
인증 거부 처리 - Access Denied (0) | 2023.02.12 |
인증 실패 핸들러: CustomAuthenticationFailureHandler (0) | 2023.02.12 |
인증 성공 핸들러: CustomAuthenticationSuccessHandler (0) | 2023.02.12 |