Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
第3次登录失败时Jetty UserRealm重定向_Jetty_Basic Authentication_Embedded Jetty - Fatal编程技术网

第3次登录失败时Jetty UserRealm重定向

第3次登录失败时Jetty UserRealm重定向,jetty,basic-authentication,embedded-jetty,Jetty,Basic Authentication,Embedded Jetty,如果我有一个定制的Jetty UserRealm实现,并将其配置为基本身份验证(使用SSL),有没有办法让它在第三次登录失败后转到特定页面 嗯,我真的只想显示一些联系信息给用户,如果他们无法登录后,3次尝试 或者,是否可以显示我从 public Principal authenticate(final String username, final Object credentials, final Request request) 方法(当其配置为基本身份验证时) 谢谢 Neil当请求中没有

如果我有一个定制的Jetty UserRealm实现,并将其配置为基本身份验证(使用SSL),有没有办法让它在第三次登录失败后转到特定页面

嗯,我真的只想显示一些联系信息给用户,如果他们无法登录后,3次尝试

或者,是否可以显示我从

public Principal authenticate(final String username, final Object credentials, final Request request) 
方法(当其配置为基本身份验证时)

谢谢
Neil

当请求中没有有效凭据时,
基本验证人
负责发送403响应

查看Jetty 6源代码,您最好的选择可能是对BasicAuthenticator进行子类化,并覆盖
public void sendChallenge(用户领域,响应)

}

显然,这样做的问题是您无法访问
HttpServletRequest
,这可能会使跟踪请求的尝试更加困难。您可能可以通过
HttpConnection.getCurrentConnection()
访问此文件。否则,
BasicAuthenticator
的代码在没有一点复制/粘贴的情况下无法扩展,但在您的情况下,这可能没问题

我忽略了如何跟踪在相同身份验证尝试中发出的请求数量的问题,这将取决于客户端的连接方式

或者,您可以在上下文中设置
ErrorHandler
,在调用
HttpResponse.senderro
时使用,在域中引发异常时就是这种情况


我可能会选择使用第一种方法,因为它更清楚地划分了责任。

当请求中没有有效凭据时,
BasicAuthenticator
负责发送403响应

查看Jetty 6源代码,您最好的选择可能是对BasicAuthenticator进行子类化,并覆盖
public void sendChallenge(用户领域,响应)

}

显然,这样做的问题是您无法访问
HttpServletRequest
,这可能会使跟踪请求的尝试更加困难。您可能可以通过
HttpConnection.getCurrentConnection()
访问此文件。否则,
BasicAuthenticator
的代码在没有一点复制/粘贴的情况下无法扩展,但在您的情况下,这可能没问题

我忽略了如何跟踪在相同身份验证尝试中发出的请求数量的问题,这将取决于客户端的连接方式

或者,您可以在上下文中设置
ErrorHandler
,在调用
HttpResponse.senderro
时使用,在域中引发异常时就是这种情况


我可能会选择使用第一种方法,因为它更清楚地划分了责任。

对于未知凭据,Jetty现在会发送一个500错误,您知道如何返回登录而不是500错误页面吗?我有一个扩展的错误处理程序。我目前正在尝试找出500错误并注销用户,以清除http标头中的基本身份验证:Authorization:Basic QTo=对于未知凭据Jetty现在发送500错误您知道如何返回登录而不是500错误页面吗?我有一个扩展的错误处理程序。我目前正在尝试找出500错误并注销用户,以清除http头中的基本身份验证:Authorization:Basic QTo=
public class MyAuthenticator extends BasicAuthenticator {
    @Override
    public void sendChallenge(UserRealm realm, Response response) {
        int numberOfAttempts = getNumberOfAuthenticationAttempts();

        if (numberOfAttempts > 3) {
            sendContactDetails(realm, response);
        }
        else
            super.sendChallenge(realm, response);
    }

    protected int getNumberOfAuthenticationAttempts() { ... }
    protected void sendContactDetails(Response response) { ... }