We have an app running on JBoss. In many installations the server is running behind a firewall that denies it access to the internet except through a proxy.
Now my task is to find out how to use this proxy when authentication is necessary.
Configuring JBoss to use a proxy is no problem with -Dhttp.proxyHost=proxy_host -Dhttp.proxyPort=proxy_port, but I see no way to indicate the username and password.
On a non-EJB-app I have had success using Authenticator.setDefault(new ProxyAuthenticator("test", "test")) where ProxyAuthenticator is extending Authenticator. This, however, does not work on JBoss.
A sub-problem I have to this case is that the server and the non-EJB-app needs to have access to local resources without using the proxy.
Finally I got this this to work. With the two links in Richs post and some trial and error it now works as requiered.
At the moment I have only implemented basic authentication and I will have to add other authentication types in the future.
A big obstruction was that I started configuring the JVM with
-Dhttp.proxyHost and -Dhttp.proxyPort. That somehow confused the JVM more than it helped. With that configuration theProxyAuthenticator.getPasswordAuthentication()was never called. So it is necessary also to set a default ProxySelector.The code leads everything through the proxy – also calls to local addresses. Soon I’ll need to work on a solution to this 🙂 (Any ideas?)
This is what I do to set it up:
MyProxySelector:
ProxyAuthenticator: