tag:blogger.com,1999:blog-12168038.post7848872410397761759..comments2024-03-05T21:55:02.687+05:30Comments on Vinod Singh: Proxy authentication in JavaVinod Singhhttp://www.blogger.com/profile/05770985867453681608noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-12168038.post-6760976337465626612013-07-30T16:31:12.521+05:302013-07-30T16:31:12.521+05:30What if the site you are connecting to also requir...What if the site you are connecting to also requires a username/password to allow you. Setting a Default Authenticator(Authenticator.setDefault) will fail I guess when the external site will look for authenticated user. <br />Used this code earlier and was getting the error (407) Proxy Authentication Required. <br /><br /><br> I believe that was because the authentication was requested by different hosts. and when you set a default authenticator with one user/pass for one host, then the authentication will fail for other requesting host. I made the following change yesterday to SimpleAuthenticator class and now it works like a charm. <br /><br />Can't paste complete class here ,so documented here: http://blog.ashwani.co.in/blog/2013-07-29/access-sharepoint-webservices-from-java-behind-proxy/aryan.ashwanihttps://www.blogger.com/profile/05078325459930969940noreply@blogger.comtag:blogger.com,1999:blog-12168038.post-4499048420315117912013-06-24T11:58:34.403+05:302013-06-24T11:58:34.403+05:30Vinod thanks a lot for the example . I tried the s...Vinod thanks a lot for the example . I tried the sample but it says Exception in thread "main" java.net.ProtocolException: Server redirected too many times (20) , I am unable to find out what is the issue . Kindly guide me <br /><br />Regards<br />ArvindAravindhttps://www.blogger.com/profile/07773553198519254982noreply@blogger.comtag:blogger.com,1999:blog-12168038.post-85722297987498106822013-04-08T19:14:50.806+05:302013-04-08T19:14:50.806+05:30Vinod - I was interested in a script which will au...Vinod - I was interested in a script which will authenticate once for me the proxy so that I don't need to enter them manually everytime I connect via IE. This has been a headache and a routine job that I keep doing all the time. Please suggest an alternative. Krishnanoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-45111257198084164822013-03-20T22:23:14.179+05:302013-03-20T22:23:14.179+05:30I received an error that PasswordAuthenticator can...I received an error that PasswordAuthenticator cannot be resolved to a type.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-71672359862839795972012-12-13T12:50:22.839+05:302012-12-13T12:50:22.839+05:30Worked perfectly. Thanks!!Worked perfectly. Thanks!!Neetshttps://www.blogger.com/profile/03910887967698132613noreply@blogger.comtag:blogger.com,1999:blog-12168038.post-37272824558956412082012-08-08T19:51:12.605+05:302012-08-08T19:51:12.605+05:30In addition to my post earlier this day:
! don...In addition to my post earlier this day:<br /><br />! don't include the proxy URL in the wildcard for "nonProxyHosts" !Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-89030433180429145632012-08-08T13:51:58.956+05:302012-08-08T13:51:58.956+05:30was spending half a day to realize that you MUST p...was spending half a day to realize that you MUST provide an authenticator if you get a 407 error<br /><br />here's my code working now<br /><br /><br /> private void setProxy()<br /> {<br /> class ProxyAuthenticator extends Authenticator <br /> {<br /> private String user, password;<br /> public ProxyAuthenticator(String user, String password) <br /> {<br /> this.user = user;<br /> this.password = password;<br /> }<br /> protected PasswordAuthentication getPasswordAuthentication() <br /> {<br /> return new PasswordAuthentication(user, password.toCharArray());<br /> }<br /> }<br /><br /> // if there are no credentials you MUST use empty user / password<br /> Authenticator.setDefault(new ProxyAuthenticator("", "")); <br /> <br /> System.setProperty("java.net.useSystemProxies", "true");<br /> System.setProperty("http.nonProxyHosts", "*.localdomain.com|localhost");<br /><br /> // or use explicit proxy url and port <br /> //System.setProperty("http.proxyHost", "proxyurl"); <br /> //System.setProperty("http.proxyPort", "port");<br /><br /><br /> System.setProperty( "http.proxyUser", "" );<br /> System.setProperty( "http.proxyPassword", "" );<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-8183075057623649612012-04-25T17:52:55.505+05:302012-04-25T17:52:55.505+05:30Hi, Authenticator is invoked in unix platform but ...Hi, Authenticator is invoked in unix platform but when comes to windows platform authenticator is not invoked instead system credentials are getting passed.<br /><br />This document says<br /><br />On Microsoft Windows platforms, NTLM authentication attempts to acquire the user credentials from the system without prompting the user's authenticator object. If these credentials are not accepted by the server then the user's authenticator will be called."<br /><br />http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-auth.html<br /><br />I have set the proxy host and port in the client but still issue persists.<br /><br />Can any one suggest me how to override this windows behaviour.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-22106794034738344542012-03-19T10:05:21.779+05:302012-03-19T10:05:21.779+05:30Thanks a lot sir, Your solution worked gr8.
But i...Thanks a lot sir, Your solution worked gr8.<br /><br />But i m struck at a point where i need to give the domain name as well ! where to set the same ?<br /><br />Any help would be gr8.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-46040688540229165682011-10-11T14:08:43.938+05:302011-10-11T14:08:43.938+05:30i am trying to acces SSRS 2008 web services using ...i am trying to acces SSRS 2008 web services using JAX-WS , tomcat 6, jdk1.6 form sun, on windows vista machine. but getPasswordAuthentication() is never called & client proxy pick up the loged in user credentials from the machine itself.. please helpPoonam Kambojnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-82209339565838113152011-09-08T12:34:12.054+05:302011-09-08T12:34:12.054+05:30Hi,
Thanks a lot for the post.
Regards
AdityaHi,<br /><br />Thanks a lot for the post.<br /><br />Regards<br />AdityaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-25067165587537801222011-05-27T16:06:47.513+05:302011-05-27T16:06:47.513+05:301. import java.net.Authenticator;
2.
3. class...1. import java.net.Authenticator; <br />2. <br />3. class ProxyAuthenticator extends Authenticator { <br />4. <br />5. private String user, password; <br />6. <br />7. public ProxyAuthenticator(String user, String password) { <br />8. this.user = user; <br />9. this.password = password; <br />10. } <br />11. <br />12. protected PasswordAuthentication getPasswordAuthentication() { <br />13. return new PasswordAuthentication(user, password.toCharArray()); <br />14. } <br />15. } <br /><br />I have implemented above.<br /><br />I want to verify that the provided username and password are correct for that proxy,<br />When password authorization is not needed means getPasswordAuthentication() will not call at this time.<br />I need this to ensure the username and password are correct when they needed means when getPasswordAuthentication() will call.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-55974592384484603462011-02-08T16:35:18.412+05:302011-02-08T16:35:18.412+05:30Thank you alot. Your solution worked perfectly wel...Thank you alot. Your solution worked perfectly well. It is accepted by the proxy without any hitches.TheDonGeorgeMhttps://www.blogger.com/profile/10476071165228459808noreply@blogger.comtag:blogger.com,1999:blog-12168038.post-10476851178765717452011-01-13T12:23:16.404+05:302011-01-13T12:23:16.404+05:30Thank you very much!
It worked!Thank you very much!<br />It worked!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-84327972774692454562010-10-15T16:37:00.131+05:302010-10-15T16:37:00.131+05:30Yes it worked for me.
But the problem is that its...Yes it worked for me.<br /><br />But the problem is that its caching the credentials which are provided for the first call and is not picking up the new credentials.<br /><br />Please suggest how we can reset the JVM cache for java.net.Authenticator object reference.<br /><br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-67261685420656255152010-08-24T14:39:02.517+05:302010-08-24T14:39:02.517+05:30Is there any way to setting proxy config to partic...Is there any way to setting proxy config to particular class? Or else, is there any way to setting proxy config to jax-ws? I don't want to touch global jvm config(<br />System.setProperty("http.proxyHost", "proxy host");).<br />Because I concern it will effect to all other classes which are connecting to network things(various host and ip which are actually local). I don't want to exclude em by "http.nonProxyHosts" also. Is there any way? Thanks in adv for help.j0k3rnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-59379549660700040642010-08-23T15:09:28.640+05:302010-08-23T15:09:28.640+05:30yeah...it worked for me....
- Anurag Vermayeah...it worked for me....<br /><br /> - Anurag VermaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-81599829530532771432010-03-17T21:21:46.790+05:302010-03-17T21:21:46.790+05:30NO, it works without that.NO, it works without that.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-64511424534945077692010-03-17T21:19:40.998+05:302010-03-17T21:19:40.998+05:30Do you need to set any SecurityManager in order fo...Do you need to set any SecurityManager in order for<br />Authenticator.setDefault(new ProxyAuthenticator("user", "password")); <br />to work?Maciejnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-35141784510739970302010-02-16T23:42:02.072+05:302010-02-16T23:42:02.072+05:30is there a way , where you can set proxyUser, and ...is there a way , where you can set proxyUser, and proxyPassword, without setting property in System class.<br />Because i have this issue on Weblogic, not able to set property in system class(i mean the system.setProperty has no effect)<br />I tried apach HttpClient as well, it doesnot support NTLM.<br /><br />TejasAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-22940036382324484672009-08-24T18:03:41.754+05:302009-08-24T18:03:41.754+05:30I think it should, though I never tried it for ftp...I think it should, though I never tried it for ftp protocol hence no definitive answer ;-)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-45288805162957338262009-08-24T17:59:14.582+05:302009-08-24T17:59:14.582+05:30Would this work for ftp.proxy* as well?Would this work for ftp.proxy* as well?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-67963795121193527732009-03-23T18:51:00.000+05:302009-03-23T18:51:00.000+05:30thanks Mr.vinod,i tried this and it worked properl...<I>thanks Mr.vinod,i tried this and it worked properly.......</I>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-28058963641280671422008-12-30T10:28:00.000+05:302008-12-30T10:28:00.000+05:30subWiz,Thanks, for the update.subWiz,<BR/><BR/>Thanks, for the update.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12168038.post-78136355690908955712008-12-30T10:13:00.000+05:302008-12-30T10:13:00.000+05:30This example uses System properties. This is not i...This example uses System properties. This is not ideal for web applications--as this system property will affect the complete JVM running the web application.<BR/><BR/>We ran into issues when we deployed two web-applications, one of which connected to a local HTTP server, and the other using proxy connected to a internet site. When we set the system properties, the one requiring local connection was also trying to go through the proxy.<BR/><BR/>Finally we used Apache HTTP Client:<BR/><BR/>http://hc.apache.org/httpcomponents-client/index.html<BR/><BR/>This has a neat proxy authentication implementation.Anonymoushttps://www.blogger.com/profile/05854955140158998481noreply@blogger.com