简体   繁体   English

Google App Engine上的UserService问题

[英]Problems with UserService on google app engine

I am trying to write an application for google app engine that would be available only for myself. 我正在尝试为Google App Engine编写一个仅对我自己可用的应用程序。 (I know it sounds strange..just for the time being) I am trying to write a Login servlet that would authenticate user using google's UserService and let the user into the app only if I login and would show a brief message prompting for logout for everyone else. (我暂时只知道这听起来很奇怪。)我正在尝试编写一个登录servlet,该服务器将使用google的UserService对用户进行身份验证,并且仅当我登录时才允许用户进入应用程序,并显示一条简短的消息提示您注销其他所有人。

Here is the code I have written : 这是我写的代码:

public class MainPageServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    resp.setContentType("text/html");

    UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        if (user != null) {

            if(user.getEmail().equals("aaadith@gmail.com")) {
                resp.getWriter().println("done");
            }
            else {
                resp.getWriter().println("Hello, " + user.getNickname()+"<br>");
                resp.getWriter().println("Thanks for your interest. But this application is still not available to everybody.");
                resp.getWriter().println("<a href="+UserServiceFactory.getUserService().createLogoutURL(userService.createLoginURL(req.getRequestURI()))+">Log out</a>");
            }
        } else {
            resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
        }       
}

} }

The code related to "driving away" all other users works fine. 与“驱走”所有其他用户有关的代码可以正常工作。 But I am facing problems when I login : After I login, it shows the message "done" as expected. 但是我登录时遇到问题:登录后,它按预期显示消息“完成”。 However, after this, if I open some other google service and logout from there and again invoke this servlet, it still shows the message "done". 但是,在此之后,如果我打开其他Google服务并从那里注销并再次调用此Servlet,它仍然显示消息“完成”。 I had expected that the app would prompt me for login again..which is not happening..I thought its happening because the result is getting cached and so disabled caching(1st line in the method)...but the problem persists even after that..whats wrong? 我原以为该应用会提示我再次登录..这没有发生..我以为发生这种情况是因为结果被缓存了,因此禁用了缓存(方法中的第一行)...但是问题仍然存在那..怎么了? How do I get the expected behavior? 如何获得预期的行为?

You don't. 你不知道 If you want the user to logout of your service, then they need to logout of your service (by you calling the logout method of UserManager). 如果要用户注销服务,则他们需要注销服务(通过调用UserManager的注销方法)。 The fact that they share the username and password with other google services doesn't mean that logging out of those other services auto-logs them out of yours. 他们与其他Google服务共享用户名和密码的事实并不意味着注销这些其他服务会自动将其注销。

Im not so sure about this, but when you login the first time to "appengine" application, you have to grant the privileges to access your profile information (I think this is OAuth standard). 我对此不太确定,但是当您首次登录“ appengine”应用程序时,必须授予访问您的个人资料信息的权限(我认为这是OAuth标准)。 You can limit this to number of days. 您可以将其限制为天数。 After that, the page can automatically read your email, nick and google ID till the access right expires. 之后,该页面可以自动读取您的电子邮件,昵称和Google ID,直到访问权限到期为止。

The way to go around this is to implement your own session mechanism and use google login just to retrieve userId (and from that your internal profile object) to start the session (aka. login). 解决此问题的方法是实现您自己的会话机制,并使用Google登录名只是为了检索userId(并从您的内部配置文件对象中)来启动会话(也称为登录名)。

If you then want to logout from your page only-you will just kill the session, and not logout from google user account 如果您只想从页面中注销,则只会终止会话,而不是从google用户帐户中注销

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UserService.getCurrentUser()在Google App Engine上返回null - UserService.getCurrentUser() returns null on Google App Engine Spring Security + Google App Engine + UserService:注销的正确方法是什么? - Spring Security + Google App Engine + UserService: What is the correct way to logout? App Engine中的UserService,OAuth和AJAX - UserService, OAuth, and AJAX in App Engine 登录后如何使用Java在应用引擎上保留查询字符串(使用Google的`userService`)? - How to preserve a Query String after Login(using Google's `userService`) on app engine using Java? 如何在使用Google帐户UserService时更新App Engine应用程序名称 - How to update the App Engine Application Name when using Google Account UserService Eclipse安装Google App Engine SDK问题 - Eclipse installing google app engine sdk problems Google App Engine Web服务的安全问题 - Security problems for google app engine webservices Servlet中的App Engine UserService调用引发线程异常-Eclipse Java - App Engine UserService calls in servlet throw thread exception - Eclipse java 登录问题,userService,丢失的会话-Google App Angine - Problem with login ,userService , lost session - google app angine Google App Engine Java:读取html文件中的问题 - Google App Engine Java: Reading in an html file problems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM