Java 在未从google.com注销的情况下注销appengine应用程序

Java 在未从google.com注销的情况下注销appengine应用程序,java,google-app-engine,Java,Google App Engine,以下代码将从appengine应用程序(本例中为自定义域)和google.com注销用户: public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserServic

以下代码将从appengine应用程序(本例中为自定义域)和google.com注销用户:

public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    UserService userService = UserServiceFactory.getUserService();

    String thisURL = req.getRequestURI();

    resp.setContentType("text/html");
    if (req.getUserPrincipal() != null) {
        resp.getWriter().println("<p>Hello, " +
                                 req.getUserPrincipal().getName() +
                                 "!  You can <a href=\"" +
                                 userService.createLogoutURL(thisURL) +
                                 "\">sign out</a>.</p>");
    }
}
}
公共类MyServlet扩展了HttpServlet{
公共无效数据集(HttpServletRequest请求、HttpServletResponse响应)
抛出IOException{
UserService UserService=UserServiceFactory.getUserService();
字符串thisURL=req.getRequestURI();
分别为setContentType(“文本/html”);
if(req.getUserPrincipal()!=null){
resp.getWriter()println(“Hello,”+
req.getUserPrincipal().getName()+
“!你可以。

”; } } }

我们如何才能只从appengine应用程序中注销,并让用户在google.com中继续登录?

直接从UserService API中无法做到这一点

您可以手动删除设置的AppEngine特定cookie,而不是使用UserService API注销。查看讨论如何这样做的文章(用Python编写,但您应该能够为Java修改它)。这将有效地让用户从您自己的应用程序中注销,而不是从其他谷歌服务中注销(尽管我自己还没有测试过)

更健壮的方法是创建自己的用户类并管理自己的会话cookie,同时包装UserService API。与非常易于使用的UserService API相比,这种方法的缺点是设置它需要额外的工作。然而,维护您自己的用户的优势在于,您可以使用除Google之外的其他身份验证方法(例如,现在您也可以使用Facebook登录,或者如果您选择设置,甚至可以使用本机登录)