Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the solution I've implemented and it works like a charm!</p> <pre><code>import java.net.*; import java.util.*; import java.util.logging.*; import java.util.regex.*; /** * Authenticator which keeps credentials to be passed to the requester * based on the concatenation of the authority and the URL that requires * authentication. * * If the configured credentials are not found, the Authenticator will * use the embedded credentials if present. * * Embedded credentials are in the form of &lt;pre&gt;&lt;b&gt;user&lt;/b&gt;:&lt;b&gt;password&lt;/b&gt;&lt;i&gt;@host:port/&amp;lt;url-path&amp;gt;&lt;/i&gt;&lt;/pre&gt; * * @author Michael Fortin 2011-09-23 */ public class Authenticator extends java.net.Authenticator { private Logger log = Logger.getLogger(this.getClass().getName()); private Map&lt;String, PasswordAuthentication&gt; authInfos; private Pattern embeddedAuthInfoPattern; @Override protected PasswordAuthentication getPasswordAuthentication() { String requesterInfo = String.format("%s%s", getRequestingURL().getAuthority(), getRequestingURL().getPath()); log.fine(String.format("%s at \"%s\" is requesting %s password authentication for \"%s\"", getRequestorType(), getRequestingPrompt(), getRequestingScheme(), requesterInfo)); PasswordAuthentication pa = null; if ((pa = authInfos.get(requesterInfo)) == null &amp;&amp; (pa = getEmbeddedPA(getRequestingURL().getAuthority())) == null) { log.warning(String.format("No authentication information for \"%s\"", requesterInfo)); } return pa; } public void setAuthInfos(Map&lt;String, PasswordAuthentication&gt; authInfos) { this.authInfos = authInfos; } public void setEmbeddedAuthInfoPattern(String pattern) { this.embeddedAuthInfoPattern = Pattern.compile(pattern); } private PasswordAuthentication getEmbeddedPA(String authInfo) { if (authInfo != null) { Matcher matcher = embeddedAuthInfoPattern.matcher(authInfo); if (matcher.find()) { return new PasswordAuthentication(matcher.group(1), matcher.group(2).toCharArray()); } } return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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