로그인한 사람들을 어떻게 spring server가 정보를 알아낼 수 있는걸까?
가령 A라는 사람이 로그인을 한 후, /test url을 타고 서버에게 request를 했다고 가정하자.
spring은 controller에서 다음과 같이 작성하면 접근 회원 정보를 알 수 있다.
@GetMapping("/test")
public String infotest(@AuthenticationPrincipal Object principal){
System.out.println(principal.toString());
return "test.html";
}
출력시 User(id=53, password=xxxxxxxx, email=xxxx@gmail.com) 등과 같이 나온다.
'developing > spring' 카테고리의 다른 글
socket을 활용한 채팅 기능 (0) | 2024.02.23 |
---|---|
Pagination 구현 (0) | 2023.09.30 |
Spring security를 통해 회원가입 및 로그인 구현 thymeleaf 및 controller (0) | 2023.09.17 |
WebSecurity 코드 (이론x) (0) | 2023.09.17 |
MockMvc를 이용한 Test (0) | 2023.07.29 |
댓글