Jetty - 在配置Gerrit时,Basic Auth发送403而不是401

时间:2012-06-04 19:43:05

标签: jetty basic-authentication http-authentication gerrit

我有一个war文件(具体来说,gerrit.war),期望容器(特别是jetty)到handle basic HTTP authentication and pass that information down to the webapp。所以我无权访问代码或web.xml文件。

我正在关注these instructions使用现有的jetty configs将gerrit包装在一个领域中,但是当我访问基本URL(/ login /)时,我得到一个403(Forbidden)错误。我希望得到一个401,它会提示我的浏览器要求提供凭据(不是吗?)

我可以发布我的文件,但我没有改变上面的例子。但是,请告诉我它是否会有所帮助。

1 个答案:

答案 0 :(得分:0)

可能有很多方法可以发生这种情况。在我的情况下它发生,因为我的约束没有角色集。此代码生成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);
}

在角色线上进行评论会提示码头以401:s代替回答。