Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Socks Proxy Authentication

950718Jul 20 2012 — edited Jul 20 2012
I have working socks proxy with Java Mail 1.4.5 without user name/password but wish to support socks proxies that require user names and passwords.

I have tried using an authenticator on the Session.getInstance(Properties, Authenticator) object but I get an error saying incorrect user name/password on my socks proxy.

My sample code is below:

Properties properties = getProperties();
final String socksProxyUserName = "test";
final String socksProxyPassword = "test";

Authenticator authenticator = new Authenticator() {

@Override
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = new PasswordAuthentication(socksProxyUserName, socksProxyPassword);
return passwordAuthentication;
}
};

Session session = Session.getInstance(properties, authenticator);

My socks proxy is FreeProxy.

I am using this method for socks proxy support in java mail.
If your proxy server supports the SOCKS V4 or V5 protocol (http://www.socks.nec.com/aboutsocks.html, RFC1928) and allows anonymous connections, and you're using JDK 1.5 or newer and JavaMail 1.4.5 or newer, you can configure a SOCKS proxy on a per-session, per-protocol basis by setting the "mail.smtp.socks.host" property as described in the javadocs for the com.sun.mail.smtp package. Similar properties exist for the "imap" and "pop3" protocols.


Message in Proxy logfile is:
Fri 20 Jul 2012 09:37:59 : ACCESS : Instance:'socky' Protocol:'SOCKS-5-Proxy' Access:'Forbidden' Client IP:'10.45.16.21' User:'test/FPDOMAIN' Resource Type:'User Authentication' Resource:'Authentication: User/password invalid'

I have confirmed user name and password several times and tried extra ones just in case but no luck.

Does anybody have any ideas. THe fact that it tries to authenticate the login on my proxy server suggests I'm trying the correct method to connect to me but can someone confirm this for me?

This proxy has this user added as I set it up myself.

Edited by: 947715 on 20-Jul-2012 01:15

Edited by: 947715 on 20-Jul-2012 01:16

Edited by: 947715 on 20-Jul-2012 01:40

Edited by: 947715 on 20-Jul-2012 03:10
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2012
Added on Jul 20 2012
3 comments
4,948 views