且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Spring Security 访问 Controller 中的用户详细信息?

更新时间:2023-12-04 09:21:16

这个代码上,身份验证UsernamePasswordAuthenticationTokengetPrincipal()的返回类型为String, 用户名.

On this code, actual type of Authentication is UsernamePasswordAuthenticationToken, and return type of getPrincipal() is String, username.

您可以将任何其他 Authentication 实现而不是 UsernamePasswordAuthenticationToken 设置为 Security>Context, 和也是免费的(因此您可以设置 MyUser).

You can set any other Authentication implementation instead of UsernamePasswordAuthenticationToken to SecurityContext, and principal type is free(so you can set MyUser), too.