I have an Java Applet that runs in a browser.
It essentially acts as a SOCKS proxy server and tunnels a single connection through a HTTP proxy server (if one is present) to an external TCP service.
This Applet works fine, except when the proxy server requires authentication.
I have proxy detection code in my applet. If the proxy server requires authentication then the applet will pop-up a username/password dialog for the proxy server credentials. This is ok. I think the code that triggers the dialog is:
ProxyInfo info = ProxyService.getProxyInfo(new URL(host));
The problem is that once the proxy server is determined I connect through it using Non-Blocking Sockets, which doesn't use the proxy credentials that were typed in earlier. I can pass the proxy credentials through in the header of the HTTP request that is used for initialising the tunnel, but these must be typed in again by the user.
I just don't want to have to ask the user for creditials twice.
I have tried using a custom java.net.Authenticator object, but I have been unable to override the default popup, or hard-code the username and password in my own Authenticator.
So essentially I need to know:
Is there a way to suppress the authentication dialog that popups when I detect the proxy server? This way I can prompt the user for the username and password in the HTML page and then pass it to the applets outgoing TCP connection.
Is there away to get the username and password that was typed into the popup dialog so that I can pass the Username and password through to the proxy when i create the outgoing TCP connection?