java Gradle,不在 Windows 上使用 NTLM 代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14434101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:15:28  来源:igfitidea点击:

Gradle, not working behind proxy with NTLM on Windows

javagradle

提问by partha

I am just testing out a gradle (an absolute noob in this field).

我只是在测试一个 gradle(这个领域的绝对菜鸟)。

I am trying this out on Windows box. I used to have Maven do the build and release for me from the same machine. It is behind a proxy with NTLM authentication. And that used to work alright. However, somehow Gradle is not doing that for me.

我正在 Windows 盒子上尝试这个。我曾经让 Maven 在同一台机器上为我做构建和发布。它位于具有 NTLM 身份验证的代理之后。这曾经工作得很好。然而,不知何故,Gradle 并没有为我这样做。

My build.gradle has the following config (apart from other)

我的 build.gradle 有以下配置(除了其他)

// Java plugin to build our JAR artifact.
apply plugin: 'java'  

// Build stuff with jdk 1.7
sourceCompatibility = 1.7
targetCompatibility = 1.7

// Regular name and version for your project. 
group = 'foo.bar.gradle'
version = '1.0-SNAPSHOT'

// The local maven repository
def localMavenRepo = 'file://C:/ProgramFiles/MavenRepository'

repositories {
// Use the maven central repository. 
mavenCentral()
// ... and the local maven repository.
maven { url localMavenRepo }

// maven { url 'http://www.springsource.com/repository/' }
}


dependencies {
compile 'org.databene:contiperf:2.2.0','org.springframework:spring-webmvc:3.2.0.RELEASE'         
testCompile 'junit:junit:4.11' 
/*compile.exclude module: 'commons'*/
/*all*.exclude*/ 
}

My /gradle.properties has the following set up

我的 /gradle.properties 有以下设置

systemProp.proxySet=true
systemProp.http.proxyHost=<proxy name, same as that set in Maven>
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=<domain name>/<user name> 

However, when I run this, I get the following error

但是,当我运行它时,出现以下错误

NEGOTIATE authentication error: No valid credentials provided (Mechanism level:
No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)
)

This is in version 1.3 of Gradle. Please help.

这是 Gradle 的 1.3 版。请帮忙。

Update:I have now updated to gradle-1.4-rc-3 My gradle.properties file look like this now

更新:我现在已经更新到 gradle-1.4-rc-3 我的 gradle.properties 文件现在看起来像这样

systemProp.proxySet="true"
systemProp.http.keepAlive="true"
systemProp.http.proxyHost=<proxy name> 
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=<domain name>/<username> 

But I still continue to see the issue. I have got some more logs. I see this in the STS (IDE)

但我仍然继续看到这个问题。我还有一些日志。我在 STS (IDE) 中看到了这个

Could not GET 'http://repo1.maven.org/maven2/org/spr...'. Received status code 500 from server: Internal Server Error 
Could not execute build using Gradle installation 'C:\ProgramFiles\gradle-1.4-rc-3'.

And no, the credentials are not wrong. In the same setup, with same values Maven is working fine. And no, the gradle.properties is in correct location as well. If I change the value of the proxy, the error changes. So, the tool is definitely reading the gradle.properties file.

不,凭据没有错。在相同的设置中,使用相同的值 Maven 工作正常。不, gradle.properties 也在正确的位置。如果我更改代理的值,错误就会改变。因此,该工具肯定是在读取 gradle.properties 文件。

回答by Rigg802

UPDATE:

更新:

with time, better solution:

随着时间的推移,更好的解决方案:

Add wagon-http-lightweight extension Wagon HTTP lightweight library deals with authentication limitations in Maven 3 when working with NTLM proxies.

添加 wagon-http-lightweight 扩展 Wagon HTTP 轻量级库处理使用 NTLM 代理时 Maven 3 中的身份验证限制。

Download the wagon-http-lightweight-2.2.jar from maven repo. Copy the wagon-http-lightweight-2.2.jar to %M2_HOME%/lib/ext folder.

从 maven repo 下载 wagon-http-lightweight-2.2.jar。将 wagon-http-lightweight-2.2.jar 复制到 %M2_HOME%/lib/ext 文件夹。

Original Answer:

原答案:

I had the exact same problem. It's a common problem with microsoft servers (ISA, etc). The http header used in your application are not supported for NTLM (at least, directly)
To bypass this, I used a "proxy-to-proxy". A local proxy that will change the http header on the fly so that Microsoft servers can understand your request.

我有同样的问题。这是微软服务器(ISA 等)的常见问题。NTLM 不支持您的应用程序中使用的 http 标头(至少,直接)
为了绕过这一点,我使用了“代理到代理”。将动态更改 http 标头的本地代理,以便 Microsoft 服务器可以理解您的请求。

Basically you will send your request locally (127.0.0.1) this proxy server will change the header with NTLM compliant request and forward it to the parent proxy on the 8080 port.

基本上,您将在本地 (127.0.0.1) 发送您的请求,此代理服务器将使用符合 NTLM 的请求更改标头,并将其转发到 8080 端口上的父代理。

Two scenarios: you have Administrators privileged or not.

两种情况:您是否拥有管理员权限。

If you have admin rights, you can install CNTLMIt will be installed as a service. There is a "auto-config" install, you can check on the wiki of CNTLM (default port:3128)

如果您有管理员权限,则可以安装CNTLM它将作为服务安装。有一个“自动配置”安装,您可以在 CNTLM 的 wiki 上查看(默认端口:3128)

If you don't have Admin rights, you can install NTLM APS(even though it's quite old, it works for me)
you need to configure the server.cfg file with your NT Domain, host, parent proxy + port, NTLM_TO_BASIC 1 (you can get your domain and host by pressing on your keyboard 'windows + pause' buttons) the default port is 5865.

如果你没有管理员权限,你可以安装NTLM APS(即使它很旧,它对我
有用)你需要用你的 NT 域、主机、父代理 + 端口、NTLM_TO_BASIC 1(您可以通过按键盘上的“windows + pause”按钮获取域和主机)默认端口为 5865。

For NTLMAPS, you need Python (python portable doesn't require admin rights, and change the value in 'runserver.bat' to match your install) and you also need to patch the version on sourceforge with this patchbecause it has a bug with chunked responses

对于 NTLMAPS,您需要 Python(python可移植不需要管理员权限,并更改“runserver.bat”中的值以匹配您的安装)并且您还需要使用此补丁修补sourceforge 上的版本,因为它有一个错误分块响应

In your application, you need to change your proxy settings as follow:

在您的应用程序中,您需要按如下方式更改代理设置:

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=3128 or 5865 depending on which server you installed

Sometimes the microsoft server still blocks the requests and I need to restart my local proxy or change parent proxy address.

有时微软服务器仍然阻止请求,我需要重新启动本地代理或更改父代理地址。

回答by Manfred Berndtgen

This is a rather old question, but still one of the first hits when googling for 'gradle' and 'ntlm proxy'. There's not much documentation about it, but if gradle complains about something like

这是一个相当古老的问题,但仍然是在谷歌搜索“gradle”和“ntlm proxy”时最先遇到的问题之一。没有太多关于它的文档,但是如果 gradle 抱怨类似的东西

Could not GET 'https://jcenter.bintray.com/org/slf4j/...

无法获取 ' https://jcenter.bintray.com/org/slf4j/...

and you're using cntlm as your proxy then this command line might be helpful:

并且您使用 cntlm 作为代理,那么此命令行可能会有所帮助:

gradle test -DproxySet=true -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3128

(assuming default values for proxy name and port). Note the "https" settings. Missing downloads were working successfully with these settings.

(假设代理名称和端口的默认值)。请注意“https”设置。丢失的下载在这些设置下成功运行。

回答by Siva

This worked for me, am using gradle-6.3. Place the following in gradle.properties

这对我有用,我使用的是 gradle-6.3。将以下内容放在 gradle.properties 中

Note that we usually give domain-name\user-name while logging into Windows machine, but the value to be give would be domain-name/user-name. Also your password need not be hex-encoded, and if your password contains 'equal to' character, gradle picks all value 'after' first '=' (from the left) as your password.

请注意,我们通常在登录 Windows 计算机时提供域名\用户名,但要提供的值将是域名/用户名。此外,您的密码不需要是十六进制编码的,如果您的密码包含“等于”字符,则 gradle 会首先选择“之后”的所有值“=”(从左侧开始)作为您的密码。

systemProp.http.proxyHost=proxy-ip-or-name
systemProp.http.proxyPort=proxy-port 
systemProp.http.proxyUser=domain-name/user-name 
systemProp.http.proxyPassword=your-password-without-any-encoding

systemProp.https.proxyHost=proxy-ip-or-name 
systemProp.https.proxyPort=proxy-port 
systemProp.https.proxyUser=domain-name/user-name 
systemProp.https.proxyPassword=your-password-without-any-encoding

回答by Adam Adamaszek

I was able to patch Gradle core v1.10 to use BASIC instead of NTLM, and it worked in our environment.

我能够修补 Gradle 核心 v1.10 以使用 BASIC 而不是 NTLM,并且它在我们的环境中工作。

In case you wanted to try, the jar file is here

如果您想尝试,jar 文件在这里

Use at your own risk.

使用风险自负。

回答by erdi

I remember working behind an NTLM proxy in the past. As we worked on *nix boxes we couldn't use NTLM proxy as there is no support for it in those OSes. I also don't think that Gradle supports NTLM, but I might be wrong.

我记得过去在 NTLM 代理后面工作。当我们在 *nix 机器上工作时,我们无法使用 NTLM 代理,因为这些操作系统不支持它。我也不认为 Gradle 支持 NTLM,但我可能错了。

Anyway, the thing we used back then was (cntlm)[http://cntlm.sourceforge.net/] proxy and you could do the same thing. Just set it up on your machine and point Gradle's proxy settings at it.

不管怎样,我们当时使用的是 (cntlm)[http://cntlm.sourceforge.net/] 代理,你可以做同样的事情。只需在您的机器上设置它并将 Gradle 的代理设置指向它。

EDIT: Apparently I was wrong - Gradle supports NTLM authentication, see release notes for 1.0-milestone-8

编辑:显然我错了 - Gradle 支持 NTLM 身份验证,请参阅1.0-milestone-8 的发行说明

回答by daz deboer

Gradle depends on Apache HttpClient + jcifs to do NTLM authentication.

Gradle 依赖 Apache HttpClient + jcifs 来做 NTLM 认证。

There is a bug in HttpClient 4.2.1 and 4.2.2 that can cause issues: there are 2 options for you to try.

HttpClient 4.2.1 和 4.2.2 中存在一个可能导致问题的错误:有 2 个选项供您尝试。

  • Upgrade to the Gradle 1.4-rc-3or higher, which contain a bugfixfor this issue.
  • Include systemProp.http.keepAlive="true"in your gradle.propertiesfile.
  • 升级到Gradle 1.4-rc-3或更高版本,其中包含针对此问题的错误修复
  • 包含systemProp.http.keepAlive="true"在您的gradle.properties文件中。

回答by Eddie B

Seeing that you have your maven repo is under C:\ProgramFiles and not in a typical write-able location such as in a user directory

看到您的 Maven 存储库位于 C:\ProgramFiles 下,而不是在典型的可写位置,例如在用户目录中

%USERPROFILE%\.m2\repository || ~/.m2/repository 

Your errors maybe windows permissions errors ... make sure you check your windows logs and/or try moving your repo to a traditional location ...

您的错误可能是 Windows 权限错误...确保您检查 Windows 日志和/或尝试将您的存储库移动到传统位置...