Nuñito Calzada
Nuñito Calzada

Reputation: 1948

Maven Not authorized , ReasonPhrase:Unauthorized

I am trying to check out my code from Nexus repository. First of all, I've generate the password with

mvn --encrypt-master-password _mypassword_

This is my c:/Users/joanet/.m2/settings-security.xml :

<settingsSecurity>
<master>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED2ws=}</master>
</settingsSecurity>

and this is my c:/progs/PGM/apache-maven-3.0.5/conf/settings.xml

  <?xml version="1.0" encoding="UTF-8"?>

    <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
    license agreements. See the NOTICE file distributed with this work for additional
    information regarding copyright ownership. The ASF licenses this file to
    you under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of
    the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
    by applicable law or agreed to in writing, software distributed under the
    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
    OF ANY KIND, either express or implied. See the License for the specific
    language governing permissions and limitations under the License. -->

    <!-- http://maven.apache.org/settings.html -->
    <settings xmlns="http://maven.apache.org/settings/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <localRepository>C:/Users/joanet/.m2/repository</localRepository>


    <proxies>
     <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>joanet</username>
      <password>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED5ws=}</password>
      <host>157.129.133.11</host>
      <port>8032</port>
      <nonProxyHosts>localhost</nonProxyHosts>
     </proxy>
    </proxies>

    <servers>
      <server>
       <id>ecPublicRepository</id>
       <username>joanet</username>
       <password>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED5ws=}</password>
      </server>


    </servers>

    <mirrors></mirrors>

    <pluginGroups>
     <!-- pluginGroup Specifies a further group identifier to use for plugin lookup.  -->
     <pluginGroup>com.oracle.weblogic</pluginGroup>
     <pluginGroup>com.github.searls</pluginGroup>
     <pluginGroup>com.cj.jshintmojo</pluginGroup>
     <pluginGroup>com.github.phasebash</pluginGroup>

    </pluginGroups>

    <profiles>
     <profile>
      <id>activeProfile</id>

      <repositories>

       <repository>
          <id>ecPublicRepository</id>
          <url>https://foo.com/nexus/content/groups/public/</url>
       </repository>


      </repositories>

      <pluginRepositories>

       <pluginRepository>
        <id>PublicRepository</id>
        <name>Public Repository</name>
        <url>https://foo.com/nexus/content/groups/public/</url>
       </pluginRepository>
      </pluginRepositories>

     </profile>

    </profiles>

    <!-- activeProfiles | List of profiles that are active for all builds. | -->
    <activeProfiles>
     <activeProfile>activeProfile</activeProfile>
    </activeProfiles>


    </settings>

but this is the error:

Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not
 transfer artifact org.apache.maven.plugins:maven-install-plugin:pom:2.3.1 from/
to ecPublicRepository (https://foo.com/nexus/content/groups/public/): Not authorized , ReasonPhrase:Unauthorized.
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(Def
aultArtifactResolver.java:538)
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArti
facts(DefaultArtifactResolver.java:216)
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArti
fact(DefaultArtifactResolver.java:193)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.
loadPom(DefaultArtifactDescriptorReader.java:281)
        ... 28 more

Upvotes: 5

Views: 37836

Answers (4)

potame
potame

Reputation: 7905

I've had a strange issue when changing my password for Nexus, following the procedure encryption of passwords likewise described in answer above.

It didn't work, ending up each time with the Could not transfer artifact org.apache.maven.plugins:maven-install-plugin:pom:2.3.1 from/to ecPublicRepository (https://mynexusrepo/nexus/content/groups/public/): Not authorized , ReasonPhrase:Unauthorized. error.

I remade the whole again, assuming I made a stupid typo in my password -- still didn't work. Even trying with the password temporarily set in clear text (no encryption) was yielding to the same error.

Finally, it seems that Maven could authenticate with my current password. My new password contained an e acute ("é") in it, and to me it seems Maven is not able use it correctly. It is very likely to be the same with other characters such as à, à, ç, ù, ñ...

I reset my password and with almost the same password but without that kind of character, everything went back correctly. Meanwhile I've always been able to log in to Nexus correctly, with web interface.

Upvotes: 1

rogerdpack
rogerdpack

Reputation: 66891

In my case, my problem was I had copied over my maven ~/.m2/settings.xml file, which itself specifies "username and passwords" without realizing that if you do that, if there is also a file security-settings.xml, you need to copy that over too (it double hashes): https://developer.jboss.org/wiki/Mavensettingsxmlmaskingpassword?_sscc=t

My hunch/assumption is that if the security-settings.xml file is absent, maven happily uses the passwords from settings.xml 'without double hashing' them so they are presented wrong to the server.

Upvotes: 0

Robin Wang
Robin Wang

Reputation: 849

I met the same error, even I set the password correct.

Finally I reinstall the maven, it resolved.

  1. Download and extract the man to /home/$username/apache-maven-3.3.9
  2. Add below to the /etc/profile
    export MAVEN_HOME=/home/$username/apache-maven-3.3.9
    export PATH=$PATH:$MAVEN_HOME
  3. source /etc/profile

Upvotes: 2

Timo
Timo

Reputation: 2242

After you encrypt your master password, you should also encrypt the actual password you need for nexus. So the hashed value in the settings-security.xml should be different then the actual values you use in the server configurations.

You can follow these steps (taken from here):

Use the following command line:

mvn --encrypt-master-password <password>

Note: Since Maven 3.2.1 the password is an optional argument. If not provided, Maven will prompt for the password. Earlier versions of Maven will not prompt for a password, so it must be typed on the command-line in plaintext. See Tips below for more information.

This command will produce an encrypted version of the password, something like

{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}

Store this password in the ~/.m2/settings-security.xml; it should look like

<settingsSecurity>
<master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>

When this is done, you can start encrypting existing server passwords. How to encrypt server passwords

You will have to use the following command line:

mvn --encrypt-password <password>

Note:Just like --encrypt-master-password the password argument is optional since Maven 3.2.1.

This command will produce an encrypted version of it, something like

{COQLCE6DU6GtcS5P=}

Cut-n-paste it into your settings.xml file in the server section. This will look like:

<settings>
...
<servers>
...
<server>
<id>my.server</id>
<username>foo</username>
<password>{COQLCE6DU6GtcS5P=}</password>
</server>
...
</servers>
...
</settings>

Please note that password can contain any information outside of the curly brackets, so that the following will still work:

Upvotes: 12

Related Questions