如何登录在AppEngine Java上使用UserService的用户 [英] How to login User using UserService on AppEngine Java
问题描述
我使用UserService来管理我的注册(Federated和OAuth - 混合)。我在各种位置(非servlet)中使用User.getCurrentUser来确定当前用户是谁。
我将API发给允许用户调用几个使用getCurrentUser的方法。我可以添加过滤器并控制我的身份验证,但是我无法强制UserService登录可以在应用程序的其余部分使用的用户 - User.getCurrentUser。
我是不知道如何继续在这一点上。
请帮助。
你必须包装你的 getCurrentUser()
像:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if(user == null){
session.setAttribute(isLoggedIn,true);
session.setAttribute(authenticatingSite,google);
try {
response.sendRedirect(userService.createLoginURL(redirectURLAfterLogin);
I use UserService to manage my registrations (Federated and OAuth - Hybrid). I use User.getCurrentUser inside of the app at "various" places (non-servlets too) to determine who the current user is.
I am giving out my API to allow users to call few methods which uses getCurrentUser. I can add a filter and control my authentication but I cannot force UserService to login a user which can be used in the rest of the app - User.getCurrentUser.
I am stumped and am not sure how to continue at this point.
Please help.
If you redirect to the createLoginURL method, it will force the user to signin.
You have to wrap your getCurrentUser()
API method to detect if it sees a null user and
force a login in that case.
like:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
session.setAttribute("isLoggedIn", true);
session.setAttribute("authenticatingSite", "google");
try {
response.sendRedirect(userService.createLoginURL(redirectURLAfterLogin);
这篇关于如何登录在AppEngine Java上使用UserService的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!