2016-04-22 27 views
0

私は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

答えて

0

これは基本認証の問題です。

try { 
     authentication = super.validateRequest(req, res, mandatory); 
    } catch (Exception e) { 
     try{ 
      HttpServletResponse r = (HttpServletResponse) res; 
      r.setHeader("WWW-Authenticate", "Basic"); 
      r.setStatus(401); 
      } catch(Exception ew){} 
     authentication = Authentication.SEND_FAILURE; 
    } 

リターン401と「WWW認証」を含むHTTPヘッダー:「基本」

Authentication.SEND_FAILUREハンドラチェーンのさらに下の例外を防止します。