harschware
harschware

Reputation: 13424

Accessing an Artifactory/Maven Repo that requires basic-auth

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?!?

Upvotes: 26

Views: 42984

Answers (4)

SajithP
SajithP

Reputation: 587

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

Upvotes: 0

Pmt
Pmt

Reputation: 1152

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.

Upvotes: 5

Esko Luontola
Esko Luontola

Reputation: 73655

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>

Upvotes: 9

Rich Seller
Rich Seller

Reputation: 84078

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> 

Upvotes: 17

Related Questions