Dmytro Titov
Dmytro Titov

Reputation: 3201

Maven not adding "Authorization" header

I'm trying to deploy artifacts to a protected by Basic Auth repository.

I specify

<distributionManagement>
    <repository>
        <id>some.repo</id>
        <name>Some Repository</name>
        <url>https://foo.bar</url>
    </repository>
</distributionManagement>

in pom.xml

And

  <servers>
    <server>
      <id>some.repo</id>
      <username>user</username>
      <password>{encoded password}</password>
    </server>
  </servers>

in settings.xml

But when I run mvn deploy it fails with the error: Not authorized , ReasonPhrase:. -> [Help 1]

If I use

 <server>
  <id>some.repo</id>
    <configuration>
        <httpHeaders>
            <property>
                <name>Authorization</name>
                <value>Basic (hash)</value>
            </property>
        </httpHeaders>
    </configuration>
</server>

instead - it works.

After inspection with Wireshark I discovered that in the first scenario (with login/password) Maven doesn't add Authorization header to the HTTP request.

Is it correct behavior? Am I missing something in the configuration?

Upvotes: 6

Views: 3129

Answers (2)

hasnat
hasnat

Reputation: 3027

maven will only send username/password on requests where server responds with a

status code:401

header: WWW-Authenticate: Basic.

Upvotes: 2

Dmytro Titov
Dmytro Titov

Reputation: 3201

Well, in this case, it was not Maven, but the server-side problem: server was not sending Connection: keep-alive header. With this header, the authorization flow works.

Upvotes: 1

Related Questions