访问需要基本身份验证的 Artifactory/Maven 存储库

发布于 2024-08-01 21:17:22 字数 855 浏览 10 评论 0原文

我有一个 Artifactory 存储库,它支持基本身份验证。 我如何配置settings.xml以允许访问?

<mirrors>
    <mirror>
        <id>artifactory</id>
        <mirrorOf>*</mirrorOf>
        <url>https://myserver.example.com/artifactory/repo</url>
        <name>Artifactory</name>
    </mirror>
</mirrors>
<servers>
    <!--
        This server configuration gives your personal username/password for
        artifactory. Note that the server id must match that given in the
        mirrors section.
    -->
    <server>
        <id>Artifactory</id>
        <username>someArtifactoryUser</username>
        <password>someArtifactoryPassword</password>
    </server>

因此,服务器标签是人工用户的用户凭据,但我还需要提供另一个用户/密码来通过基本身份验证。 我会把它放在哪里?

I have an Artifactory repo that sits behind basic authentication. How would I configure the settings.xml to allow access?

<mirrors>
    <mirror>
        <id>artifactory</id>
        <mirrorOf>*</mirrorOf>
        <url>https://myserver.example.com/artifactory/repo</url>
        <name>Artifactory</name>
    </mirror>
</mirrors>
<servers>
    <!--
        This server configuration gives your personal username/password for
        artifactory. Note that the server id must match that given in the
        mirrors section.
    -->
    <server>
        <id>Artifactory</id>
        <username>someArtifactoryUser</username>
        <password>someArtifactoryPassword</password>
    </server>

So server tag is the user credentials for the artifactory user, but I also need to provide another user/password to get through the basic-auth. Where would I put that?!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

非要怀念 2024-08-08 21:17:22

用户名和密码将按照您的情况输入到服务器设置中。 我认为你的问题是你已经通过服务器的名称(Artifactory)而不是它的id(artifactory)指定了服务器。

我建议您将服务器设置放在用户设置中,而不是全局设置中。 您还可以在 Maven 2.1.0+ 中对密码进行加密,请参阅迷你指南< /a> 了解详细信息。

更新:您使用的是哪个版本的 Artifactory? 有 讨论和相应的问题基本-验证失败。 这显然已在 2.0.7 和 2.1.0 中得到修复。

从讨论来看,似乎 解决方法是通过命令行传递属性,例如

-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dproxy.username=... -Dhttp.password=... 

更新:要让您的 Maven 安装通过防火墙进行连接,您需要配置代理settings.xml 部分,请参阅此问题了解一些这样做的指示。


Update2:您可以在服务器设置中设置其他属性,请参阅此博客 了解一些背景信息。 我还没有机会对此进行测试,但是来自博客和相关http wagon javadoc,看来您可以在服务器设置上设置authenticationInfo,如下所示:

<server>  
  <id>Artifactory</id>
  <username>someArtifactoryUser</username>
  <password>someArtifactoryPassword</password>
  <configuration>  
    <authenticationInfo>
      <userName>auth-user</userName>
      <password>auth-pass</password>
    </authenticationInfo>
  </configuration>  
</server> 

The username and password go in the server settings as you have them. I think your problem is that you've specified the server by its name (Artifactory), rather than its id (artifactory).

I'd recommend you put the server settings in your user settings rather than the global settings. You can also encrypt the password in Maven 2.1.0+, see the mini guide for details.

Update: What version of Artifactory are you using? There is a discussion and corresponding issue that basic-auth fails. This has apparently been fixed in 2.0.7 and 2.1.0.

From the discussion, it seems that a workaround is to pass the properties via the command line, e.g.

-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dproxy.username=... -Dhttp.password=... 

Update: To let your Maven installation connect through a firewall, you'll need to configure the proxy section of the settings.xml, see this question for some pointers on doing that.


Update2: There are additional properties you can set in the server settings, see this blog for some background. I've not had an opportunity to test this, but from the blog and related http wagon javadoc, it appears you can set authenticationInfo on the server settings, something like this:

<server>  
  <id>Artifactory</id>
  <username>someArtifactoryUser</username>
  <password>someArtifactoryPassword</password>
  <configuration>  
    <authenticationInfo>
      <userName>auth-user</userName>
      <password>auth-pass</password>
    </authenticationInfo>
  </configuration>  
</server> 
白况 2024-08-08 21:17:22

解决明文密码问题的提示:

  • 访问并登录Artifactory。
  • 登录后,单击屏幕右上角的用户名。
  • 将您的密码输入 em Unlock 按钮,启用加密密码。
  • 复制将在屏幕下方显示的标签并将其粘贴到 settings.xml 文件中。 如果您只想复制密码,请确保它与下面显示的标签完全一致,包括密码开头的“\”。
  • 请记住使用 POM.xml 中定义到标签中的服务器 ID 来调整标签
  • 单击“更新”按钮并准备就绪! 检查下一个项目发布时是否一切顺利。

Tip to solve the problem with the clear text password:

  • Access and login into Artifactory.
  • Once you are logged in, click over your user name, on the superior right corner of the screen.
  • Put your password then clique in the em Unlockbutton, enabling the encrypted password.
  • Copy the tag that will be showed on the inferior part of the screen and paste it into the settings.xml file. If you prefer to just copy the password, be sure about let it exactly equals the tag showed below, including the "\" at the beginning of the password.
  • Remember to adjust the tag with the id of your server, defined into the tag, in your POM.xml
  • Click in Update button and ready! Check if everything will occur well at the next project's publication.
静若繁花 2024-08-08 21:17:22

我能够使用以下配置来启用 HTTP 基本身份验证 - 通过编写 必要的 HTTP 标头 手动。 在我的情况下,我用它来访问 Go 服务器 上的构建工件作为穷人的暂存库。

    <server>
        <id>go</id>
        <configuration>
            <httpHeaders>
                <property>
                    <name>Authorization</name>
                    <!-- Base64-encoded "guest:guest" -->
                    <value>Basic Z3Vlc3Q6Z3Vlc3Q=</value>
                </property>
            </httpHeaders>
        </configuration>
    </server>

I was able to use the following configuration to enable HTTP basic authentication - by writing the necessary HTTP headers manually. In my situation I used it to access the build artifacts on my Go server as a poor man's staging repository.

    <server>
        <id>go</id>
        <configuration>
            <httpHeaders>
                <property>
                    <name>Authorization</name>
                    <!-- Base64-encoded "guest:guest" -->
                    <value>Basic Z3Vlc3Q6Z3Vlc3Q=</value>
                </property>
            </httpHeaders>
        </configuration>
    </server>
梅窗月明清似水 2024-08-08 21:17:22

大多数情况下,发生这种情况是由于以下原因:

  • 在 ~/.m2/conf 或 ~/.m2 目录中找不到 Settings.xml。
  • Settings.xml 不包含正确的凭据用户名 或用于访问 Artifactory 的 API Key
  • 无法使用给定的凭据访问 Settings.xml 中提到的 Artifactory

您可以查看 Maven 在哪些目录中查找内容...使用 -e -X 选项运行将显示这些有时

,Settings.xml 文件可能会放置在不同的目录中,因此当您本地构建时,maven 无法在 ~/.m2 或 ~/.m2/conf 目录中找到它。 例如,如果项目使用 buildkite,它可能位于 buildkite 在构建过程中可以访问的目录内。 在这种情况下,只需将相同的 Settings.xml 文件复制到 ~/.m2 中即可。

输入图片此处描述

要查找 artifactory,请使用您的电子邮件/密码登录网址,然后转到个人资料并找到用户名和 API 密钥,如图所示。

输入图片此处描述

然后检查 Settings.xml 中的存储库是否正确

在此处输入图像描述

Most of the time this happens due to following reasons

  • Settings.xml is not found inside the ~/.m2/conf or ~/.m2 directories
  • Settings.xml doesn't contain the correct credentials Username or the API Key to access the Artifactory
  • Cannot access the Artifactory mentioned in the Settings.xml with the given credentials

You can see what Maven looks for in what directories... Running with -e -X options will show these details

Sometimes the Settings.xml file may be placed inside a different directory, so when you build locally, maven cannot find it inside ~/.m2 or ~/.m2/conf directories. For e.g if the project uses buildkite, it may be inside a directory that buildkite can access during the build process. In that case, just copy the same Settings.xml file into ~/.m2.

enter image description here

To find the aritifactory, logon to the url using your email/password and go to profile and locate the username and the API Key like in the pic.

enter image description here

Then check the repository is correct in Settings.xml

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文