프로젝트 정리/스프링과 JPA 기반 웹 애플리케이션 개발
17. 현재 인증된 사용자 정보 참조
JunGi Jeong
2021. 4. 24. 20:41
스프링 시큐리티의 스프링 웹 MVC 지원
- @AuthenticationPrincipal
- 핸들러 매개변수로 현재 인증된 Principal을 참조할 수 있다.
- Princial을 어디에 넣었더라?
public void login(Account account) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( account.getNickname(), account.getPassword(), List.of(new SimpleGrantedAuthority("ROLE_USER"))); SecurityContextHolder.getContext().setAuthentication(token); } |
- @AuthenticationPricipal은 SpEL을 사용해서 Principal 내부 정보에 접근할 수도 있다.
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : account") |
- 익명 인증인 경우에는 null로 설정하고, 아닌 경우에는 account 프로퍼티를 조회해서 설정하라.
@AuthenticationPrincipal -> Spring Security 에서 지원
알아볼 것 Principal객체란??
debug모드시
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended 에러가 뜨는데 이게 왜 뜨는지와 해결방법에 대해서
이메일 인증을 위한 창 및 이메일 다시 보내기 기능 구현