简体   繁体   English

访问需要基本身份验证的Artifactory / Maven Repo

[英]Accessing an Artifactory/Maven Repo that requires basic-auth

I have an Artifactory repo that sits behind basic authentication. 我有一个Artifactory仓库,它位于基本身份验证之后。 How would I configure the settings.xml to allow access? 如何配置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>

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. 因此,server tag是artifactory用户的用户凭据,但我还需要提供另一个用户/密码来完成basic-auth。 Where would I put that?!? 我会把它放在哪里?!?

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 ( A rtifactory), rather than its id ( a rtifactory). 我觉得你的问题是,你已经被它的名字(A rtifactory)指定的服务器,而不是它的ID( rtifactory)。

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. 您也可以在Maven 2.1.0+中加密密码,有关详细信息,请参阅迷你指南

Update: What version of Artifactory are you using? 更新:您使用的是什么版本的Artifactory? There is a discussion and corresponding issue that basic-auth fails. 一个讨论和相应的问题 ,基本认证失败。 This has apparently been fixed in 2.0.7 and 2.1.0. 这显然已在2.0.7和2.1.0中修复。

From the discussion, it seems that a workaround is to pass the properties via the command line, eg 从讨论开始,似乎解决方法是通过命令行传递属性,例如

-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. 更新:要让您的Maven安装通过防火墙连接,您需要配置settings.xml的代理部分,请参阅此问题以获取有关此操作的一些指示。


Update2: There are additional properties you can set in the server settings, see this blog for some background. Update2:您可以在服务器设置中设置其他属性,有关背景信息,请参阅此博客 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: 我没有机会测试这个,但是从博客和相关的http旅行车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> 

I was able to use the following configuration to enable HTTP basic authentication - by writing the necessary HTTP headers manually. 我能够使用以下配置来启用HTTP基本身份验证 - 通过手动编写必要的HTTP标头 In my situation I used it to access the build artifacts on my Go server as a poor man's staging repository. 在我的情况下,我用它来访问我的Go服务器上的构建工件作为穷人的临时存储库。

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

Tip to solve the problem with the clear text password: 提示用明文密码解决问题:

  • Access and login into Artifactory. 访问并登录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. 将您的密码然后clique放入em解锁按钮,启用加密密码。
  • Copy the tag that will be showed on the inferior part of the screen and paste it into the settings.xml file. 复制将在屏幕下方显示的标记并将其粘贴到settings.xml文件中。 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 请记住使用POM.xml中定义到标记中的服务器的ID调整标记
  • Click in Update button and ready! 单击“更新”按钮并准备就绪! Check if everything will occur well at the next project's publication. 检查下一个项目的出版是否一切都会顺利进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM