Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You extend the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Authenticator.html" rel="nofollow noreferrer">Authenticator</a> class and register it. The javadocs at the link explain how.</p> <p>I don't know if this works with the nio method that got the accepted answer to the question, but it for sure works for the old fashioned way that was the answer under that one.</p> <p>Within the authenticator class implementation, you are probably going to use a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/PasswordAuthentication.html" rel="nofollow noreferrer">PasswordAuthentication</a> and override the getPasswordAuthentication() method of your Authenticator implementation to return it. That will be the class which is passed the user name and password you need.</p> <p>Per your request, here is some sample code:</p> <pre><code>public static final String USERNAME_KEY = "username"; public static final String PASSWORD_KEY = "password"; private final PasswordAuthentication authentication; public MyAuthenticator(Properties properties) { String userName = properties.getProperty(USERNAME_KEY); String password = properties.getProperty(PASSWORD_KEY); if (userName == null || password == null) { authentication = null; } else { authentication = new PasswordAuthentication(userName, password.toCharArray()); } } protected PasswordAuthentication getPasswordAuthentication() { return authentication; } </code></pre> <p>And you register it in the main method (or somewhere along the line before you call the URL):</p> <pre><code>Authenticator.setDefault(new MyAuthenticator(properties)); </code></pre> <p>The usage is simple, but I find the API convoluted and kind of backwards for how you typically think about these things. Pretty typical of singleton design.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload