@Override
    public void fill(AuthenticationContext context, String key, Map<String, String> data) {
      Proxy proxy = context.getProxy();
      if (proxy == null) {
        return;
      }
      if (!AuthenticationContext.USERNAME.equals(key) && !AuthenticationContext.PASSWORD.equals(key)) {
        return;
      }

      try {
        URL url;
        String protocol = "http";
        try {
          url = new URL(context.getRepository().getUrl());
          protocol = url.getProtocol();
        }
        catch (Exception e) {
          url = null;
        }

        PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
          proxy.getHost(), null, proxy.getPort(), protocol, "Credentials for proxy " + proxy, null, url, Authenticator.RequestorType.PROXY
        );
        if (auth != null) {
          context.put(AuthenticationContext.USERNAME, auth.getUserName());
          context.put(AuthenticationContext.PASSWORD, auth.getPassword());
        }
        else {
          context.put(AuthenticationContext.USERNAME, System.getProperty(protocol + ".proxyUser"));
          context.put(AuthenticationContext.PASSWORD, System.getProperty(protocol + ".proxyPassword"));
        }
      }
      catch (SecurityException e) {
        // oh well, let's hope the proxy can do without auth
      }
    }
@Override
    public void fill(AuthenticationContext context, String key, Map<String, String> data)