Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Overriding current java.net.Authenticator for specific requests  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a library that wants me to use java.net.Authenticator.setDefault() if I want it to send its HTTP/HTTPS requests through a proxy that requires a username and a password. However, that library will be used to implement a small feature in a huge application (that I did not write myself) that may use Authenticators for its own needs already. I can ensure that my Authenticator is set last but I do not want the previous Authenticators to cease functionality - they might be needed still. So naturally I try to do the following: set my Auth; when asked for PasswordAuthentication decide whether I should handle the request; if yes, give my credentials; if no, forward the request to whatever the previous authenticator was.
So I hacked this together:

I suppose that the code is terrible but I cannot see why yet. Please explain to me why this is not the way to do it.

Thank you
 
What's gotten into you? Could it be this tiny ad?
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!