I am using this to set up my proxy connection:
client.getOptions().setProxyConfig(new ProxyConfig(host, port, true));
DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) client.getCredentialsProvider();
credentialsProvider.addCredentials(username, password);
When I try to connect I get this:
[main] INFO org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {}->http://checkip.amazonaws.com:80: SOCKS : authentication failed
[main] INFO org.apache.http.impl.execchain.RetryExec - Retrying request to {}->http://checkip.amazonaws.com:80
[main] INFO org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {}->http://checkip.amazonaws.com:80: SOCKS : authentication failed
[main] INFO org.apache.http.impl.execchain.RetryExec - Retrying request to {}->http://checkip.amazonaws.com:80
[main] INFO org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {}->http://checkip.amazonaws.com:80: SOCKS : authentication failed
[main] INFO org.apache.http.impl.execchain.RetryExec - Retrying request to {}->http://checkip.amazonaws.com:80
Error getting web client IP address
java.net.SocketException: SOCKS : authentication failed
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:473)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:192)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1401)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1319)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:463)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
I was able to get authenticated SOCKS5 to work by creating my own Authenticator subclass that checks the incoming SOCKS5 authentication request against a list of registered proxies.
In the below code snippet, VProxy.getProxies() is getting a list of all proxies that I have defined - you can of course create your own way of having users specify proxies to use.
As a reminder for myself
https://stackoverflow.com/questions/1540424/java-proxy-client-class-that-supports-authentication
see https://github.com/HtmlUnit/htmlunit/issues/394