< prev index next >

src/java.httpclient/share/classes/java/net/http/AuthenticationFilter.java

Print this page




  28 import static java.net.Authenticator.RequestorType.SERVER;
  29 import java.net.PasswordAuthentication;
  30 import java.net.URI;
  31 import java.net.InetSocketAddress;
  32 import java.net.URISyntaxException;
  33 import java.util.Base64;
  34 import java.util.HashMap;
  35 import java.util.LinkedList;
  36 import static java.nio.charset.StandardCharsets.ISO_8859_1;
  37 
  38 /**
  39  * Implementation of Http Basic authentication.
  40  */
  41 class AuthenticationFilter implements HeaderFilter {
  42 
  43     static private final Base64.Encoder encoder = Base64.getEncoder();
  44 
  45     static final int DEFAULT_RETRY_LIMIT = 3;
  46 
  47     static final int retry_limit = Utils.getIntegerNetProperty(
  48             "sun.net.httpclient.auth.retrylimit", DEFAULT_RETRY_LIMIT);
  49 
  50     static final int UNAUTHORIZED = 401;
  51     static final int PROXY_UNAUTHORIZED = 407;
  52 
  53     private PasswordAuthentication getCredentials(String header,
  54                                                   boolean proxy,
  55                                                   HttpRequestImpl req)
  56         throws IOException
  57     {
  58         HttpClientImpl client = req.client();
  59         java.net.Authenticator auth =
  60                 client.authenticator()
  61                       .orElseThrow(() -> new IOException("No authenticator set"));
  62         URI uri = req.uri();
  63         HeaderParser parser = new HeaderParser(header);
  64         String authscheme = parser.findKey(0);
  65 
  66         String realm = parser.findValue("realm");
  67         java.net.Authenticator.RequestorType rtype = proxy ? PROXY : SERVER;
  68 




  28 import static java.net.Authenticator.RequestorType.SERVER;
  29 import java.net.PasswordAuthentication;
  30 import java.net.URI;
  31 import java.net.InetSocketAddress;
  32 import java.net.URISyntaxException;
  33 import java.util.Base64;
  34 import java.util.HashMap;
  35 import java.util.LinkedList;
  36 import static java.nio.charset.StandardCharsets.ISO_8859_1;
  37 
  38 /**
  39  * Implementation of Http Basic authentication.
  40  */
  41 class AuthenticationFilter implements HeaderFilter {
  42 
  43     static private final Base64.Encoder encoder = Base64.getEncoder();
  44 
  45     static final int DEFAULT_RETRY_LIMIT = 3;
  46 
  47     static final int retry_limit = Utils.getIntegerNetProperty(
  48             "java.net.httpclient.auth.retrylimit", DEFAULT_RETRY_LIMIT);
  49 
  50     static final int UNAUTHORIZED = 401;
  51     static final int PROXY_UNAUTHORIZED = 407;
  52 
  53     private PasswordAuthentication getCredentials(String header,
  54                                                   boolean proxy,
  55                                                   HttpRequestImpl req)
  56         throws IOException
  57     {
  58         HttpClientImpl client = req.client();
  59         java.net.Authenticator auth =
  60                 client.authenticator()
  61                       .orElseThrow(() -> new IOException("No authenticator set"));
  62         URI uri = req.uri();
  63         HeaderParser parser = new HeaderParser(header);
  64         String authscheme = parser.findKey(0);
  65 
  66         String realm = parser.findValue("realm");
  67         java.net.Authenticator.RequestorType rtype = proxy ? PROXY : SERVER;
  68 


< prev index next >