@AuthenticationPrincipal不会显示经过身份验证的用户

时间:2014-10-25 11:04:11

标签: java spring spring-security

我有以下代码,它使用@AuthenticationPrincipal查找经过身份验证的用户

@RequestMapping(value="/user/update",method=RequestMethod.POST)
public @ResponseBody User editUser(@RequestBody User newUser, @AuthenticationPrincipal User user, HttpServletResponse response) {
    System.out.println("Authenticated User="+user);
}

问题是,当我打印出用户的名字时,它显示为空用户,而不是登录的用户。我需要做些什么来使其工作?

1 个答案:

答案 0 :(得分:0)

经过一番搜索后,我找到了this form page。它指示我将@EnableWebMvcSecurity添加到我的应用程序中。添加之后,效果很好!

相关问题