# HG changeset patch # User weijun # Date 1268907997 -28800 # Node ID 07af3c2791663a3a353265b34b6455a8a53254c7 # Parent 8b10c5dccd731fb422905d3311edfa46558d6e22 6829283: HTTP/Negotiate: Autheticator triggered again when user cancels the first one Reviewed-by: chegar diff -r 8b10c5dccd73 -r 07af3c279166 jdk/src/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java --- a/jdk/src/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java Wed Mar 17 09:55:04 2010 +0800 +++ b/jdk/src/share/classes/sun/net/www/protocol/http/spnego/NegotiateCallbackHandler.java Thu Mar 18 18:26:37 2010 +0800 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2010 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,43 +45,50 @@ private String username; private char[] password; + /** + * Authenticator asks for username and password in a single prompt, + * but CallbackHandler checks one by one. So, no matter which callback + * gets handled first, make sure Authenticator is only called once. + */ + private boolean answered; + private final HttpCallerInfo hci; public NegotiateCallbackHandler(HttpCallerInfo hci) { this.hci = hci; } + private void getAnswer() { + if (!answered) { + answered = true; + PasswordAuthentication passAuth = + Authenticator.requestPasswordAuthentication( + hci.host, hci.addr, hci.port, hci.protocol, + hci.prompt, hci.scheme, hci.url, hci.authType); + /** + * To be compatible with existing callback handler implementations, + * when the underlying Authenticator is canceled, username and + * password are assigned null. No exception is thrown. + */ + if (passAuth != null) { + username = passAuth.getUserName(); + password = passAuth.getPassword(); + } + } + } + public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (int i=0; i 1) { + throw new RuntimeException("Authenticator called twice"); + } + } + /** * Creates and starts an HTTP or proxy server that requires * Negotiate authentication.