在 JVM 中包含“@”的代理密码
我有一些Scala代码,它设法成功协商(NTLM)代理并访问互联网,指定用户名和密码如下:
// Based upon http://rolandtapken.de/blog/2012-04/java-process-httpproxyuser-and-httpproxypassword
Authenticator.setDefault(new Authenticator() {
  override protected def getPasswordAuthentication: PasswordAuthentication = {
    if (getRequestorType eq RequestorType.PROXY) {
      val prot = getRequestingProtocol.toLowerCase
      // This allows us to only return a PasswordAuthentication when we have
      // all four of the host, port, user and password _and_ the host and
      // port match the actual proxy wanting authentication.
      for {
        host <- Option(System.getProperty(prot + ".proxyHost"))
        if getRequestingHost.equalsIgnoreCase(host)
        port <- Try(augmentString(System.getProperty(prot + ".proxyPort")).toInt).toOption
        if port == getRequestingPort
        user <- Option(System.getProperty(prot + ".proxyUser"))
        pass <- Option(System.getProperty(prot + ".proxyPassword"))
      } yield return new PasswordAuthentication(user, pass.toCharArray)
    }
    // One of the if-statements failed.  No authentication for you!
    null
  }
})
但是,我现在已经获得了一个新的系统用户名/密码组合来使用,并且密码中包含一个。我尝试过直接使用密码,转义它(两者兼而有之,如果需要双层转义),url编码它(即替换为)甚至HTML编码(和)无济于事。@\\\@%40@@
我知道密码有效,因为它在其他系统上用于非JVM应用程序通过设置变量来访问互联网,但它在这里不起作用。http_proxy
有什么想法吗?
编辑
为了尝试清除一些事情,我尝试将代码简化为:
Authenticator.setDefault(new Authenticator() {
  def urlEncode(str: String): String = {
    val res = URLEncoder.encode(str, "UTF-8")
    // To confirm it's working
    println(s"${str} -> ${res}")
    res
  }
  override protected def getPasswordAuthentication: PasswordAuthentication = {
    if (getRequestorType eq RequestorType.PROXY) {
      return new PasswordAuthentication(urlEncode("username"), urlEncode("p@ssword").toCharArray);
    }
    null
  }
})
运行此操作的环境位于 Linux 机箱上的 Spark 群集(运行方式 )中。代理是公司NTLM代理。spark-submit
如果我使用不包含的已知用户名和密码组合,那么这有效。如果我将其更改为包含 的一个,那么它将失败。@@
我尝试过在函数内部制作(以防万一它不需要URL编码),尝试(有和没有URL编码)和(有和没有URL编码)。每次我得到一个例外。val res = strurlEncode\\@^@Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authorization Required"
我知道用户名和密码是有效的,因为它们当前是在curl等成功使用的变量中设置的。https_proxy
因此,除非在正在运行的Spark服务器中设置代理的事实以某种方式影响了它所发生的事情,否则在我看来,JVM库不支持在代理的身份验证器中(至少)。@
 
					 
				 
				    		 
				    		 
				    		 
				    		