View Javadoc

1   package com.atlassian.sal.core.net;
2   
3   import org.apache.http.HttpHost;
4   import org.apache.http.auth.AuthScheme;
5   import org.apache.http.client.AuthCache;
6   import org.apache.http.impl.client.BasicAuthCache;
7   
8   /**
9    * An AuthCache implementation allowing setting Auth for a host on all ports
10   *
11   * When getting a value for a host, we try first to find exact match and then
12   * a match for all ports
13   *
14   * @since v3.0
15   */
16  class AllPortsAuthCache extends BasicAuthCache implements AuthCache {
17      @Override
18      protected HttpHost getKey(final HttpHost host) {
19          return host;
20      }
21  
22      @Override
23      public AuthScheme get(final HttpHost host) {
24          // looking for exact match
25          AuthScheme authScheme = super.get(host);
26  
27          if (authScheme != null) {
28              return authScheme;
29          }
30  
31          // Exact match not found, looking for all ports match
32          return super.get(new HttpHost(host.getHostName()));
33      }
34  }