Java 安全约束不会强制用户登录

Java 安全约束不会强制用户登录,java,google-app-engine,Java,Google App Engine,我有一个只希望管理员访问的应用程序。我在web.xml文件中添加了以下内容: <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CO

我有一个只希望管理员访问的应用程序。我在web.xml文件中添加了以下内容:

<security-constraint>
  <web-resource-collection>
      <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
      <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
  <auth-constraint>
       <role-name>admin</role-name>
  </auth-constraint>
</security-constraint>

/*
保密的
管理
但是,这并不像文档中所说的那样强制用户登录。如果用户已登录,并且有管理员,则可以访问该站点。否则返回403

该应用程序使用app Engine SDK v1.8.9和GWT SDK v2.6.0构建


我是误解了文档还是做错了什么?

在项目中添加一个简单的AuthServlet。在web.xml中将它映射到
/\u ah/
-或另一个类似
/login
的处理程序。使用它检查您是否登录到谷歌帐户

public class AuthServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

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

        HashSet<String> attributes = new HashSet<String>();

        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        if (user != null) {
            out.println("Hello <i>" + user.getNickname() + "</i>!");
            out.println("[<a href=\""
                    + userService.createLogoutURL(req.getRequestURI())
                    + "\">sign out</a>]");
        } else {
            String redirect = req.getRequestURI();
            out.println("Sign in at: ");
                String loginUrl = userService.createLoginURL(
                        redirect, null, "www.google.com/accounts/o8/id", attributes);
                out.println("[<a href=\"" + loginUrl + "\">Google</a>] ");
        }
     }
}
公共类AuthServlet扩展了HttpServlet{ @凌驾 public void doGet(HttpServletRequest-req、HttpServletResponse-resp)引发IOException{ UserService UserService=UserServiceFactory.getUserService(); User=userService.getCurrentUser(); HashSet attributes=新的HashSet(); 分别为setContentType(“文本/html”); PrintWriter out=resp.getWriter(); 如果(用户!=null){ out.println(“Hello”+user.get昵称()+“!”; out.println(“[]”); }否则{ String redirect=req.getRequestURI(); out.println(“登录:”; 字符串loginUrl=userService.createLoginURL( 重定向,空,“www.google.com/accounts/o8/id”,属性); out.println(“[]”); } } }
为您的应用程序设置了哪个身份验证选项?我正在使用Google Accounts API。请在应用程序的域中尝试/_ah/以确保您已注销所有Google帐户。尝试访问/_ah/时出现404错误。奇怪,这是一个保留处理程序。当您点击开发服务器时会发生什么?