我最近在 Artifactory 实例上激活了安全性,这导致了几个问题。其中一个仍然存在,看起来有点奇怪:
Maven 使用 HTTP HEAD 检查是否已部署新的 SNAPSHOT。 但是,启用安全性后,第一次调用将在没有身份验证 header 的情况下完成,从而导致 Artifactory 发出 401 响应。
然后 Maven 应该使用身份验证 header 执行相同的调用。 maven-metadata.xml 文件就是这种情况。
但是对于 .pom 和 .jar 文件,不会重新尝试请求,如下面的日志所示:
20150303104244|3|REQUEST|xxx.xxx.xxx.xxx|non_authenticated_user|GET|/libs-snapshot-local/mycompany/common/common-config/1.0.4-SNAPSHOT/maven-metadata.xml|HTTP/1.1|401|0
20150303104244|12|REQUEST|xxx.xxx.xxx.xxx|user|GET|/libs-snapshot-local/mycompany/common/common-config/1.0.4-SNAPSHOT/maven-metadata.xml|HTTP/1.1|200|322
20150303104244|40|REQUEST|xxx.xxx.xxx.xxx|user|GET|/libs-snapshot-local/mycompany/common/common-config/1.0.4-SNAPSHOT/maven-metadata.xml.sha1|HTTP/1.1|200|40
20150303104244|4|REQUEST|xxx.xxx.xxx.xxx|user|GET|/libs-snapshot-local/mycompany/common/common-config/1.0.4-SNAPSHOT/maven-metadata.xml.md5|HTTP/1.1|200|32
20150303104245|2|REQUEST|xxx.xxx.xxx.xxx|non_authenticated_user|HEAD|/libs-snapshot-local/mycompany/myproject/myproject-interface/2.0.0-SNAPSHOT/myproject-interface-2.0.0-SNAPSHOT.jar|HTTP/1.1|401|0
20150303104245|2|REQUEST|xxx.xxx.xxx.xxx|non_authenticated_user|HEAD|/libs-snapshot-local/mycompany/myproject/myproject-interface/2.0.0-SNAPSHOT/myproject-interface-2.0.0-SNAPSHOT.jar|HTTP/1.1|401|0
正如所解释的,使用用户凭据重新尝试下载 maven-metadata.xml 文件,但 myproject-interface-2.0.0-SNAPSHOT.jar 则不会。
我尝试为该服务器启用抢先身份验证,但我找不到 Maven 行为的任何变化:
<server>
<id>snapshot</id>
<username>user</username>
<password>xxx</password>
<configuration>
<httpConfiguration>
<all>
<usePreemptive>true</usePreemptive>
<params>
<property>
<name>http.authentication.preemptive</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
这仅涉及现有快照的更新,因为下载新 Artifact 是通过包含身份验证 header 的 HTTP GET 完成的(至少需要重试)。这仍然会妨碍正确使用 SNAPSHOT Artifact 。
我正在使用 Maven 3.2.1 和 Artifactory 3.4.2。
最佳答案
对于希望默认启用抢先身份验证的其他人:
The documentation因为 Maven 主站点上的此设置是错误的。我花了一段时间追踪它,但最终在 open bug ticket 上找到了答案。我在下面复制了它。这适用于 OS X 上的 Maven 3.1.1。
<servers>
<server>
<id>serverid</id>
<username>myuser</username>
<password>mypassword</password>
<configuration>
<wagonProvider>httpclient</wagonProvider>
<httpConfiguration>
<all>
<usePreemptive>true</usePreemptive>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>
关于maven - 从 Maven 到 Artifactory 的经过身份验证的 HEAD 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28829029/