Authentication Java Proxy Client Class

I'm looking for Java socks. A proxy client class that supports authentication, any suggestions? Java.net.Proxy does not support authentication.

Edit: It seems I cannot find a way to connect the authentication data to a specific proxy host through a socket. Authenticator.setDefault () allows you to use only one set of credentials.

Authenticator.setDefault(new Authenticator(){ protected PasswordAuthentication getPasswordAuthentication(){ PasswordAuthentication p=new PasswordAuthentication("xxx", "xxx".toCharArray()); return p; } }); Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("xxx.xx.xxx.xxx", xxx)); Socket sock = new Socket(proxy); sock.connect(new InetSocketAddress(server,xx)); 
+4
source share
2 answers

Java supports Socks proxy configuration through registered java.net.Authenticator or through settings, as described in Network Properties :

SOCKS protocol support settings

SOCKS username and password: purchased as follows. First, if the application registered a java.net.Authenticator default instance, it will be requested with the protocol installed on the string "SOCKS5" and the prompt set for the string "Authentication SOCKS". If the authenticator does not return a username / password, or if the authenticator is not registered then the system checks the user settings " java.net.socks.username " and " java.net.socks.password ". If these preferences do not exist, then the System property " user.name " is checked for the username. In this case, no password is provided.

SocksProxyHost
socksProxyPort (default: 1080)
Specifies the name of the SOCKS proxy server and the port number that will be used by the SOCKS protocol level. If socksProxyHost is specified, then all TCP sockets will use the SOCKS proxy server to establish or accept a connection. A SOCKS proxy server can be a SOCKS v4 or v5 server, and it must allow unauthenticated connections.

In the client code examples, you can check this response for stack overflow.

EDIT: update response as per comment

A side effect of SOCKS support in the JDK is that your entire JVM will go through the same SOCKS proxy. So this may not work for you.

Authenticator affects all authentication in your JVM (HTTP auth, Proxy Auth). So again, this may not work for you.

In your case, a possible solution would be to use the HttpClient from HttpComponents (the successor to the deprecated Commons HTTP Client 3.x ). Browse through the samples, and especially Proxy Request and Authentication Examples .

+4
source

Use this HttpClient (not Apache)

http://www.innovation.ch/java/HTTPClient/

This is just a URL handler, so you can use a regular HTTPUrlConnection. It supports SOCKS and another proxy.

0
source

All Articles