如何获得当前登录用户在谷歌应用程序引擎
问题描述:
我发展的春天框架应用获得Gmail的使用如何获得当前登录用户在谷歌应用程序引擎
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
当前用户,但是当用户与代码返回Gmail和新用户登录登出旧用户。 如何清除春季chache。
答
Google App Engine应用程序不会自动跟踪用户会话的Gmail登录/注销。因此,注销Gmail不会将用户从应用程序中注销。
也就是说,Google ID可用于登录/退出您的应用。如果你想让你的用户从你的应用中注销,那么create a logout Url并让用户使用它来注销。
了解更多here。
答
如果您在GAE接线正确春季安全, 你只需要做:
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
... ...
UserDetails user = (UserDetails) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
这是一个很好的答案,但OP提到春天,所以还有其他事情在那里。 –
OP发布的代码显然是Google App Engine Api。也许,OP认为这个问题是因为一些弹簧缓存,但在这种情况下,它看起来不像我。 – kunal