コード例 #1
0
 public Credentials getCredentials(final AuthScope authscope) {
   Args.notNull(authscope, "Auth scope");
   final Credentials localcreds = internal.getCredentials(authscope);
   if (localcreds != null) {
     return localcreds;
   }
   if (authscope.getHost() != null) {
     PasswordAuthentication systemcreds =
         getSystemCreds(authscope, Authenticator.RequestorType.SERVER);
     if (systemcreds == null) {
       systemcreds = getSystemCreds(authscope, Authenticator.RequestorType.PROXY);
     }
     if (systemcreds != null) {
       final String domain = System.getProperty("http.auth.ntlm.domain");
       if (domain != null) {
         return new NTCredentials(
             systemcreds.getUserName(), new String(systemcreds.getPassword()), null, domain);
       } else {
         if (AuthSchemes.NTLM.equalsIgnoreCase(authscope.getScheme())) {
           // Domian may be specified in a fully qualified user name
           return new NTCredentials(
               systemcreds.getUserName(), new String(systemcreds.getPassword()), null, null);
         } else {
           return new UsernamePasswordCredentials(
               systemcreds.getUserName(), new String(systemcreds.getPassword()));
         }
       }
     }
   }
   return null;
 }
コード例 #2
0
 private static PasswordAuthentication getSystemCreds(
     final AuthScope authscope, final Authenticator.RequestorType requestorType) {
   final String hostname = authscope.getHost();
   final int port = authscope.getPort();
   final String protocol = port == 443 ? "https" : "http";
   return Authenticator.requestPasswordAuthentication(
       hostname,
       null,
       port,
       protocol,
       null,
       translateScheme(authscope.getScheme()),
       null,
       requestorType);
 }