• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Authenticator and re-authentication

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that's making HTTP requests to websites by means of a HttpURLConnection object. Occasionally, I need to authenticate to a website, so I've subclassed Authenticator to do this, and made my class active by calling Authenticator.setDefault(). My class overrides getPasswordAuthentication and returns the proper information in a PasswordAuthentication object.

Things work until I need to re-authenticate to the same website. This is important, since the password to the website may have changed since the first connection, or there is some reason to login with different authentication credentials. I find that I can't do this since getPasswordAuthentication never gets called again, but rather the same PasswordAuthentication object (with the now incorrect information) is used.

So my question is: How does the system cache the PasswordAuthentication? Is it based on:
the URL you go to?
the realm you connect to?
it is always the same on regardless of where you connect?

Is there something I can do to force the system to re-authenticate?

Sander Smith
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a direct answer, but you can use authentication with [Http]UrlConnection in a more direct way, which is outlined here (applets and other Java code are equal in this regard). That should also handle changing credentials, since no caching takes place.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic