Jetty-配置Gerrit时,基本身份验证发送403而不是401

Jetty-配置Gerrit时,基本身份验证发送403而不是401,jetty,basic-authentication,http-authentication,gerrit,Jetty,Basic Authentication,Http Authentication,Gerrit,我有一个war文件(具体地说,),它期望容器(具体地说,jetty)能够。因此,我无法访问代码或web.xml文件 我下面使用退出的jetty配置将gerrit包装到一个域中,但是当我访问基本URL(/login/)时,我得到一个403(禁止)错误。我希望得到401,这将提示我的浏览器要求凭据(否?) 我可以发布我的文件,但是我没有改变上面例子中的任何内容。但是,请告诉我这是否有帮助。可能有很多方法可以实现这一点。在我的例子中,发生这种情况是因为我的约束没有角色集。此代码生成403: priva

我有一个war文件(具体地说,),它期望容器(具体地说,jetty)能够。因此,我无法访问代码或web.xml文件

我下面使用退出的jetty配置将gerrit包装到一个域中,但是当我访问基本URL(/login/)时,我得到一个403(禁止)错误。我希望得到401,这将提示我的浏览器要求凭据(否?)


我可以发布我的文件,但是我没有改变上面例子中的任何内容。但是,请告诉我这是否有帮助。

可能有很多方法可以实现这一点。在我的例子中,发生这种情况是因为我的约束没有角色集。此代码生成403:

private void secureServlet(ServletContextHandler handler) {
    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    security.setRealmName(this.realm);
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(new WebLoginService(this.engine));

    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    //constraint.setRoles(new String[]{"user"});
    constraint.setAuthenticate(true);

    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setConstraint(constraint);
    mapping.setPathSpec("/*");

    security.addConstraintMapping(mapping);
    handler.setSecurityHandler(security);
}
角色行中的注释将提示jetty使用401:s进行回答