본문 바로가기
developing/spring

Spring security로 구현한 로그인으로 입장한 회원 정보 알아내기

by pikkaso 2023. 9. 17.

로그인한 사람들을 어떻게 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) 등과 같이 나온다.

 

댓글