无法从 Maven 部署到 Artifactory:http 错误代码 403
Unable to deploy to Artifactory from Maven: http error code 403
我怀疑这很简单,但我无法从 Maven 命令行或 Eclipse 将任何项目部署到远程 Artifactory 存储库。我可以使用 Artifactory web UI 成功部署,但是当我在我的 Maven settings.xml 文件中指定相同的用户帐户 ('admin') 时,它会失败 "Error code 403, Forbidden"。我使用的是 Artifactory 的开源版本,版本 5.11.0。 "Password Encryption Policy" 设置为 "Required".
这是来自 ~/.m2/settings.xml
文件的服务器片段:
<server>
<id>dmrepo</id>
<username>admin</username>
<password>encrypted password obtained from the Artifactory UI</password>
</server>
这里是项目 pom.xml
文件的部署部分:
<distributionManagement>
<repository>
<id>dmrepo</id>
<name>myrepo-releases</name>
<url>http://server:port/libs-release-local</url>
</repository>
</distributionManagement>
如果我用 -e
参数重新 运行 mvn
,堆栈跟踪中的最后一个错误是:
Caused by: org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://server:port/libs-release-local/path/to/jar/jarFile-version.jar, ReasonPhrase: Forbidden.
当我查看 Artifactory 和 Tomcat 日志文件时,我发现在失败的部署尝试期间没有任何记录,这让我怀疑请求是否到达了该服务器,但错误代码 403是来自 某处 的活跃 "you can't do that" 响应,而不是一般的 "can't reach that URL" 错误。另外,我可以使用同一台机器上的浏览器访问相同的主机和端口组合,所以我认为这不是防火墙问题。
我已经查看了其他类似的问题,但其中 none 似乎解决了这种特定情况。 JFrog 用户指南建议检查存储库中的包含和排除过滤器,但包含设置为 **/*
并且排除为空,这对我来说似乎是正确的。用户指南中的另一个建议是 'permissions' 可能是问题所在,但没有说明哪些权限或如何检查和更改它们。
更新
更新了@Ariel 请求的 curl
命令的(轻微编辑)输出:
curl -i -vvv -u 'admin:<password>' -T <filename.jar> <hostname>:<port>/<repo_name>/<package>/<version>/<filename>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying <IP_address>...
* TCP_NODELAY set
* Connected to <hostname> (<IP_address>) port <port> (#0)
* Server auth using Basic with user 'admin'
> PUT /<repo_name>/<package>/<version>/<filename> HTTP/1.1
> Host: <hostname>:<port>
> Authorization: Basic <Base64_encoded admin:password>
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 14364
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
} [14364 bytes data]
* We are completely uploaded and fine
< HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8
< Content-Language: en
Content-Language: en
< Content-Length: 983
Content-Length: 983
< Date: Wed, 27 Jun 2018 00:26:15 GMT
Date: Wed, 27 Jun 2018 00:26:15 GMT
< Connection: close
Connection: close
<
{ [983 bytes data]
100 15347 100 983 100 14364 6380 93227 --:--:-- --:--:-- --:--:-- 93272
* Closing connection 0
<!doctype html><html lang="en"><head><title>HTTP Status 403 – Forbidden</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 403 – Forbidden</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The server understood the request but refuses to authorize it.</p><hr class="line" /><h3>Apache Tomcat/8.5.23</h3></body></html>
除了尝试使用 HTTPS 代替 HTTP 之外,还要仔细检查 URL。通过 CURL 输出,您似乎没有到达 Artifactory。您的请求在 Tomcat 级别停止,这通常意味着您的 Artifactory URL 不正确。您可以尝试:http://server:port/artifactory/libs-release-local/ 看看是否可行?
我怀疑这很简单,但我无法从 Maven 命令行或 Eclipse 将任何项目部署到远程 Artifactory 存储库。我可以使用 Artifactory web UI 成功部署,但是当我在我的 Maven settings.xml 文件中指定相同的用户帐户 ('admin') 时,它会失败 "Error code 403, Forbidden"。我使用的是 Artifactory 的开源版本,版本 5.11.0。 "Password Encryption Policy" 设置为 "Required".
这是来自 ~/.m2/settings.xml
文件的服务器片段:
<server>
<id>dmrepo</id>
<username>admin</username>
<password>encrypted password obtained from the Artifactory UI</password>
</server>
这里是项目 pom.xml
文件的部署部分:
<distributionManagement>
<repository>
<id>dmrepo</id>
<name>myrepo-releases</name>
<url>http://server:port/libs-release-local</url>
</repository>
</distributionManagement>
如果我用 -e
参数重新 运行 mvn
,堆栈跟踪中的最后一个错误是:
Caused by: org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://server:port/libs-release-local/path/to/jar/jarFile-version.jar, ReasonPhrase: Forbidden.
当我查看 Artifactory 和 Tomcat 日志文件时,我发现在失败的部署尝试期间没有任何记录,这让我怀疑请求是否到达了该服务器,但错误代码 403是来自 某处 的活跃 "you can't do that" 响应,而不是一般的 "can't reach that URL" 错误。另外,我可以使用同一台机器上的浏览器访问相同的主机和端口组合,所以我认为这不是防火墙问题。
我已经查看了其他类似的问题,但其中 none 似乎解决了这种特定情况。 JFrog 用户指南建议检查存储库中的包含和排除过滤器,但包含设置为 **/*
并且排除为空,这对我来说似乎是正确的。用户指南中的另一个建议是 'permissions' 可能是问题所在,但没有说明哪些权限或如何检查和更改它们。
更新
更新了@Ariel 请求的 curl
命令的(轻微编辑)输出:
curl -i -vvv -u 'admin:<password>' -T <filename.jar> <hostname>:<port>/<repo_name>/<package>/<version>/<filename>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying <IP_address>...
* TCP_NODELAY set
* Connected to <hostname> (<IP_address>) port <port> (#0)
* Server auth using Basic with user 'admin'
> PUT /<repo_name>/<package>/<version>/<filename> HTTP/1.1
> Host: <hostname>:<port>
> Authorization: Basic <Base64_encoded admin:password>
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 14364
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
} [14364 bytes data]
* We are completely uploaded and fine
< HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8
< Content-Language: en
Content-Language: en
< Content-Length: 983
Content-Length: 983
< Date: Wed, 27 Jun 2018 00:26:15 GMT
Date: Wed, 27 Jun 2018 00:26:15 GMT
< Connection: close
Connection: close
<
{ [983 bytes data]
100 15347 100 983 100 14364 6380 93227 --:--:-- --:--:-- --:--:-- 93272
* Closing connection 0
<!doctype html><html lang="en"><head><title>HTTP Status 403 – Forbidden</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 403 – Forbidden</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The server understood the request but refuses to authorize it.</p><hr class="line" /><h3>Apache Tomcat/8.5.23</h3></body></html>
除了尝试使用 HTTPS 代替 HTTP 之外,还要仔细检查 URL。通过 CURL 输出,您似乎没有到达 Artifactory。您的请求在 Tomcat 级别停止,这通常意味着您的 Artifactory URL 不正确。您可以尝试:http://server:port/artifactory/libs-release-local/ 看看是否可行?