Repository: GoogleContainerTools/jib
File: jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/ProxyProvider.java (Java)

Code before:
   * @param proxy Maven proxy
   */
  private static void propagateProxyProperties(Proxy proxy) {
    if (proxy.getProtocol().equalsIgnoreCase("http")) {
      propagateProxyProperty("http.proxyHost", proxy.getHost());
      propagateProxyProperty("http.proxyPort", String.valueOf(proxy.getPort()));
      propagateProxyProperty("http.proxyUser", proxy.getUsername());
      propagateProxyProperty("http.proxyPassword", proxy.getPassword());
    } else if (proxy.getProtocol().equalsIgnoreCase("https")) {
      propagateProxyProperty("https.proxyHost", proxy.getHost());
      propagateProxyProperty("https.proxyPort", String.valueOf(proxy.getPort()));
      propagateProxyProperty("https.proxyUser", proxy.getUsername());
      propagateProxyProperty("https.proxyPassword", proxy.getPassword());
    }
    propagateProxyProperty("http.nonProxyHosts", proxy.getNonProxyHosts());
  }

  /**
   * Propagate Maven proxy property into system property to be picked up by Connections. Only set
   * the system property if not already set.
   *
   * @param name proxy system property name
   * @param value proxy system property value
   */
  private static void propagateProxyProperty(String name, String value) {
    if (value != null && System.getProperty(name) == null) {
      System.setProperty(name, value);
    }
  }
}


Review comment (security):
I think the proxy updating should happen all or not. For example, someone can define `https.proxyHost` from the command line but leave `https.proxyPort` undefined, in which case the default port will be chosen. It is also possible to leave `https.proxyUser` if the proxy doesn't require auth. So, I think the logic should basically be

```
if (only when none of http.x properties are defined) {
  Proxy firstActiveHttpProxy = <first active HTTP-targeting proxy from settings.xml>;
  System.setProperty(http.proxyHost, firstActiveHttpProxy.getHost());
  System.setProperty(http.proxyPort, firstActiveHttpProxy.getPort());
  ...
}
if (only when none of https.x properties are defined) {
  Proxy firstActiveHttpsProxy = <first active HTTPS-targeting proxy from settings.xml>;
  System.setProperty(https.proxyHost, firstActiveHttpsProxy.getHost());
  System.setProperty(https.proxyPort, firstActiveHttpsProxy.getPort());
  ...
}
```

Code after:
   * picked up by {@link java.net.ProxySelector} used in {@link
   * com.google.cloud.tools.jib.http.Connection}, while connecting to container image registries.
   *
   * @param proxy Maven proxy
   */
  private static void setProxyProperties(Proxy proxy) {
    String protocol = proxy.getProtocol();
    if (protocol != null && !proxyPropertiesSet(protocol)) {
      setProxyProperty(protocol + ".proxyHost", proxy.getHost());
      setProxyProperty(protocol + ".proxyPort", String.valueOf(proxy.getPort()));
      setProxyProperty(protocol + ".proxyUser", proxy.getUsername());
      setProxyProperty(protocol + ".proxyPassword", proxy.getPassword());
      setProxyProperty("http.nonProxyHosts", proxy.getNonProxyHosts());
    }
  }

  /**
   * Set proxy system property if it has a proper value
   *
   * @param property property name
   * @param value property value
   */
  private static void setProxyProperty(String property, String value) {
    if (property != null && value != null) {
      System.setProperty(property, value);
    }
  }

  /**
   * Check if any proxy system properties are already set for a given protocol. Note, <code>
   * nonProxyHosts</code> is excluded as it can only be set with <code>http</code>.
   *
   * @param protocol protocol
   */
  private static boolean proxyPropertiesSet(String protocol) {
    return PROXY_PROPERTIES.stream().anyMatch(p -> System.getProperty(protocol + "." + p) != null);
  }
}