We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
로그인한 사용자의 정보를 파라미터로 받고 싶을 때 기존에는 다음과 같이 Principal 객체로 받아서 사용
@GetMapping("/") public String index(Model model,Principal principal){ ... }
위의 Principal 객체는 Spring Security가 제공하는 객체가 아닌, 자바에 정의되어있는 Principal 객체를 바인딩 해주는 것이라 사용할 수 있는 메소드가 getName() 밖에 없다.
@PostMapping("/new") private String itemNew( @Valid @ModelAttribute("insertItemDto") InsertItemDto dto, BindingResult bindingResult, @AuthenticationPrincipal UserDetailsImpl userDetails, RedirectAttributes redirectAttributes ){ ... }
실제 SecurityContextHolder 내 Principal(SecurityContextHolder.getContext().getAuthentication().getPrincipal())를 가져오기 위해서 @AuthenticationPrincipal를 사용한다.
@AuthenticationPrincipal
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Principal vs. @AuthenticationPrincipal
Principal
로그인한 사용자의 정보를 파라미터로 받고 싶을 때 기존에는 다음과 같이 Principal 객체로 받아서 사용
위의 Principal 객체는 Spring Security가 제공하는 객체가 아닌, 자바에 정의되어있는 Principal 객체를 바인딩 해주는 것이라 사용할 수 있는 메소드가 getName() 밖에 없다.
@AuthenticationPrincipal
실제 SecurityContextHolder 내 Principal(SecurityContextHolder.getContext().getAuthentication().getPrincipal())를 가져오기 위해서
@AuthenticationPrincipal
를 사용한다.The text was updated successfully, but these errors were encountered: