【问题标题】:Maven Not authorized , ReasonPhrase:UnauthorizedMaven 未授权,原因短语:未授权
【发布时间】:2015-08-20 13:26:08
【问题描述】:

我正在尝试从 Nexus 存储库中查看我的代码。 首先,我已经生成了密码

mvn --encrypt-master-password _mypassword_

这是我的 c:/Users/joanet/.m2/settings-security.xml :

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

这是我的 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>

但这是错误:

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

【问题讨论】:

标签: maven


【解决方案1】:

加密您的主密码后,您还应该加密您需要用于 nexus 的实际密码。因此,settings-security.xml 中的哈希值应该与您在服务器配置中使用的实际值不同。

您可以按照以下步骤操作(取自here):

使用以下命令行:

mvn --encrypt-master-password <password>

注意:从 Maven 3.2.1 开始,密码是可选参数。如果未提供,Maven 将提示输入密码。早期版本的 Maven 不会提示输入密码,因此必须在命令行中以明文形式输入。有关详细信息,请参阅下面的提示。

此命令将生成密码的加密版本,类似于

{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}

将此密码存储在 ~/.m2/settings-security.xml 中;它应该看起来像

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

完成后,您可以开始加密现有的服务器密码。 如何加密服务器密码

您必须使用以下命令行:

mvn --encrypt-password <password>

注意:就像 --encrypt-master-password 一样,自 Maven 3.2.1 起密码参数是可选的。

此命令将生成它的加密版本,类似于

{COQLCE6DU6GtcS5P=}

将其剪切并粘贴到服务器部分的 settings.xml 文件中。这看起来像:

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

请注意,密码可以包含大括号之外的任何信息,因此以下内容仍然有效:

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,即使我设置了正确的密码。

    最后我重新安装了maven,它解决了。

    1. 下载man并解压到/home/$username/apache-maven-3.3.9
    2. 将以下内容添加到 /etc/profile
      导出 MAVEN_HOME=/home/$username/apache-maven-3.3.9
      导出 PATH=$PATH:$MAVEN_HOME
    3. 来源 /etc/profile

    【讨论】:

      【解决方案3】:

      按照answer above 中同样描述的密码程序加密,我在更改 Nexus 密码时遇到了一个奇怪的问题。

      它不起作用,每次都以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. 错误结束。

      假设我在密码中犯了一个愚蠢的拼写错误,我再次重新制作了整个文件 - 仍然没有工作。即使尝试以明文形式临时设置的密码(未加密)也会出现同样的错误。

      最后,Maven 似乎可以使用我当前的密码进行身份验证。我的新密码中包含一个 e 锐音(“é”),对我来说,Maven 似乎无法正确使用它。很可能与其他字符相同,例如 à、à、ç、ù、ñ...

      我重设了密码并使用几乎相同的密码但没有那种字符,一切都恢复正常。同时,我始终能够通过网络界面正确登录 Nexus。

      【讨论】:

        【解决方案4】:

        就我而言,我的问题是我复制了我的 maven ~/.m2/settings.xml 文件,该文件本身指定了“用户名和密码”,但没有意识到如果你这样做,如果还有一个文件安全性- settings.xml,你也需要复制它(它是双哈希):https://developer.jboss.org/wiki/Mavensettingsxmlmaskingpassword?_sscc=t

        我的预感/假设是,如果 security-settings.xml 文件不存在,maven 会愉快地使用 settings.xml 中的密码“没有双重哈希”,因此它们会错误地呈现给服务器。

        【讨论】:

          猜你喜欢
          • 2013-11-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-15
          • 2016-12-17
          • 1970-01-01
          • 2018-06-01
          • 1970-01-01
          相关资源
          最近更新 更多