private void setProxy()

in src/CsrValidation/java/lib/src/main/java/com/microsoft/intune/scepvalidation/IntuneClient.java [510:550]


    private void setProxy()
    {
        if(proxyHost != null && !proxyHost.isEmpty() &&
           proxyPort != null)
         {
            this.log.info("Setting AuthClient ProxyHost:" + proxyHost + " ProxyPort:" + proxyPort);
            this.msalAuthClient.SetProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
            this.adalAuthClient.SetProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));

            if(this.httpClientBuilder == null)
            {
                this.httpClientBuilder = HttpClients.custom();
            }
            this.log.info("Setting IntuneClient ProxyHost:" + proxyHost + " ProxyPort:" + proxyPort);
            this.httpClientBuilder.setProxy(new HttpHost(proxyHost, proxyPort));
             
            if(proxyUser != null && !proxyUser.isEmpty() &&
               proxyPass != null && !proxyPass.isEmpty())
            {
               this.log.info("Setting Proxy to use Basic Authentication.");
               
               // Setting proxy auth for Intune HttpClient
               Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPass);
               CredentialsProvider credsProvider = new BasicCredentialsProvider();
               credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), credentials);
               httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
                 
               
               // By default Java disables basic authentication, so we are enabling that so Authenticator will work
               System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
               
               // Setting proxy auth for Auth HttpClient
               Authenticator.setDefault(new Authenticator() {
                   @Override
                   protected PasswordAuthentication getPasswordAuthentication() {
                       return new PasswordAuthentication(proxyUser, proxyPass.toCharArray());
                   }
               });
            }
         }
    }