挑战登录,基本认证

时间:2016-04-22 05:21:46

标签: jetty basic-authentication embedded-jetty

我正在使用jetty 9,嵌入式。

我想在我的属性文件中不存在用户名时发送质询。

我已经扩展了BasicAuthenticator类来捕获当用户名不存在时通常抛出的异常。在再次登录后挑战用户后,我看不出怎么回事。

public class MyBasicAuthenticator extends BasicAuthenticator{
    @Override
    public Authentication validateRequest(ServletRequest req,
        ServletResponse res, boolean mandatory)
    {
        Authentication authentication = null;
        try{
            authentication = super.validateRequest(req,res,mandatory);
            return authentication;
        }catch (Exception e){
            return Authentication.SEND_FAILURE;
        } 
    }

Authentication.SEND_FAILURE会阻止调用ErrorHandler,但它只会加载空白页面。 SEND_FAILURE来自身份验证界面。

JavaDoc:http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/security/authentication/BasicAuthenticator.html

根据这个问题的答案,Jetty6有一个发送挑战方法,Jetty9没有。 Jetty UserRealm redirect on 3th failed login

1 个答案:

答案 0 :(得分:0)

这是一个基本身份验证问题。

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time


# Create a new instance of the Firefox driver

String URL = "http://www.google.com";

driver = webdriver.Firefox()


# go to the google home page
driver.get(URL);

返回401和包含“WWW-Authenticate”的http标头:“Basic”

Authentication.SEND_FAILURE可防止处理程序链中的异常。