AuthenticationPrincipal is empty when using EnableWebSecurity

后端 未结 4 850
挽巷
挽巷 2021-01-13 03:25

As of Spring Security doc: 34.1 @EnableWebMvcSecurity states, the @EnableWebMvcSecurity was replaced by @EnableWebSecurity.

But when I try

4条回答
  •  终归单人心
    2021-01-13 03:37

    AuthenticationPrincipal is empty.
    But I can get the UserDetails by the traditional way, like this:

    SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    

    Configuring of argument-resolvers helped for me

    
        
            
        
    
    

    Also you can see 34.2 @AuthenticationPrincipal section

    Once AuthenticationPrincipalArgumentResolver is properly configured, you can be entirely decoupled from Spring Security in your Spring MVC layer.

    How i understand this mean you should add argument resolver manually. Or

    By using Section 34.1, “@EnableWebMvcSecurity” you will automatically have this added to your Spring MVC configuration

    Also related question

提交回复
热议问题