【问题标题】:Artifactory Maven example fails with 401 error codeArtifactory Maven 示例失败并出现 401 错误代码
【发布时间】:2019-01-17 09:03:04
【问题描述】:

我正在我的本地主机上尝试 Artifactory。即使我关注了他们的tutorial 做他们的 Maven example,我以 401 状态码失败。这是我得到的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project multi: Failed to deploy artifacts: Could not transfer artifact org.jfrog.test:multi:pom:3.7-20190117.083916-1 from/to snapshots (http://localhost:8081/artifactory/libs-snapshot-local): Failed to transfer file http://localhost:8081/artifactory/libs-snapshot-local/org/jfrog/test/multi/3.7-SNAPSHOT/multi-3.7-20190117.083916-1.pom with status code 401 -> [Help 1]

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project multi: Failed to deploy artifacts: Could not transfer artifact org.jfrog.test:multi:pom:3.7-20190117.083916-1 from/to snapshots (http://localhost:8081/artifactory/libs-snapshot-local): Failed to transfer file http://localhost:8081/artifactory/libs-snapshot-local/org/jfrog/test/multi/3.7-SNAPSHOT/multi-3.7-20190117.083916-1.pom with status code 401

这是位于 /Users/my_user_name/.m2 中的 settings.xml 的内容:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP84FzVbdvwcgreF8m9HT77ESkA"}</password>
      <id>central</id>
    </server>
    <server>
      <username>${security.getCurrentUsername()}</username>
      <password>${security.getEscapedEncryptedPassword()!"AP84FzVbdvwcgreF8m9HT77ESkA"}</password>
      <id>snapshots</id>
    </server>
  </servers>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://localhost:8081/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://localhost:8081/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://localhost:8081/artifactory/libs-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://localhost:8081/artifactory/libs-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

我已将其添加到 pom.xml

<distributionManagement>
    <snapshotRepository>
        <id>snapshots</id>
        <name>0e5e20a55438-snapshots</name>
        <url>http://localhost:8081/artifactory/libs-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>

错误代码 401 提示我存在身份验证问题。我想知道 settings.xml 如何解析凭据,例如${security.getCurrentUsername()}?我什至在 settings.xml 中输入了普通的用户名和密码,但仍然失败。

你能告诉我我的设置有什么问题吗?我该如何解决这个问题?

【问题讨论】:

  • 你使用的是哪个版本的artifactory?
  • 我在我的 Mac 上使用基于 Docker 的 Aritfactory。我使用这个 Docker 镜像:docker.bintray.io/jfrog/artifactory-oss:latest
  • 对不起,哪个版本的神器(?);它会在您打开 UI 时告诉您,在左下角
  • Artifactory 版本 6.6.5
  • 您是下载视频中的settings.xml文件,还是复制粘贴?

标签: maven artifactory maven-deploy-plugin


【解决方案1】:

注意:工件 6.5.x 中有 a bug,在 6.5.2 版中已解决,这会阻止正确处理过滤的资源。

${security.getCurrentUsername()}filtered resource 的用法,它在工件中允许将文本文件视为通过 FreeMarker 模板过滤。

当您在工件 UI 中下载 settings.xml 文件时,${security.[]} 字段将被替换为您当前记录的用户名和加密密码(如果该错误不存在)。由于错误,或者 if 您复制/粘贴文本内容而不是下载,settings.xml 将包含那些文字未替换的字符串,并且 maven 不会替换它们,因为它们在 maven 中不存在构建上下文。

如您链接的视频所示,您需要点击download snippet链接,而不是复制文字;否则,您可以复制/粘贴文本,然后您需要在其中输入您的人工用户名和密码。

【讨论】:

  • 谢谢。它解决了这个问题。但是我应该说,即使通过下载 settings.xml,这个问题仍然存在,用户应该手动替换凭据。
  • 以管理员身份下载设置会保留模板而不填充它,因此您可以根据需要将模板用作a filtered resource。像任何其他用户一样下载它会过滤令牌。
  • 在人工 OSS 6.16.0 rev 61600900 上,我仍然填充了“一半”字段(如原始帖子中所示)。用户不是管理员,但使用 LDAP 登录。没有管理员权限,正在下载 sn-p。
【解决方案2】:

对于那些已经登陆这里并在尝试使用 artefactory 云时遇到 401 的人,对我来说,问题是我添加了一个公共镜像部分(这不是由 Generate Maven Settings 链接添加的:

这给了我 settings.xml 中的一个部分:

  <mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>public</name>
      <url>https://{my-domain}.jfrog.io/artifactory/public</url>
      <id>public</id>
    </mirror>
  </mirrors

由于我使用了这个镜像,因此我需要在服务器部分添加进一步的身份验证:

       <server>
          <username>{username}</username>
          <password>{encrypted password}</password>
          <id>public</id>
      </server

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 2018-09-04
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多