You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/05/21 20:41:47 UTC

[maven-scm] 06/08: Replace SecDispatcher

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch scm-979-deplexus
in repository https://gitbox.apache.org/repos/asf/maven-scm.git

commit fbe681d89cf8309f1f4f23e5fd3fb6e209441801
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat May 21 20:24:09 2022 +0200

    Replace SecDispatcher
---
 .../apache/maven/scm/plugin/AbstractScmMojo.java   | 34 ++++++++--------
 .../main/resources/META-INF/plexus/components.xml  | 45 ----------------------
 .../java/org/apache/maven/scm/ScmTestCase.java     | 21 ----------
 3 files changed, 16 insertions(+), 84 deletions(-)

diff --git a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
index 7c17086d1..f1ecfeddc 100644
--- a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
+++ b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/AbstractScmMojo.java
@@ -48,11 +48,13 @@ import org.apache.maven.scm.repository.ScmRepository;
 import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.building.SettingsProblem;
+import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecryptionResult;
 import org.apache.maven.shared.model.fileset.FileSet;
 import org.apache.maven.shared.model.fileset.util.FileSetManager;
 import org.codehaus.plexus.util.StringUtils;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
 
 /**
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
@@ -142,12 +144,8 @@ public abstract class AbstractScmMojo
     @Component
     private ScmManager manager;
 
-    /**
-     * When this plugin requires Maven 3.0 as minimum, this component can be removed and o.a.m.s.c.SettingsDecrypter be
-     * used instead.
-     */
-    @Component( hint = "mng-4384" )
-    private SecDispatcher secDispatcher;
+    @Component
+    private SettingsDecrypter settingsDecrypter;
 
     /**
      * The base directory.
@@ -397,6 +395,8 @@ public abstract class AbstractScmMojo
 
             if ( server != null )
             {
+                server = decrypt( server );
+
                 if ( username == null )
                 {
                     username = server.getUsername();
@@ -404,7 +404,7 @@ public abstract class AbstractScmMojo
 
                 if ( password == null )
                 {
-                    password = decrypt( server.getPassword(), host );
+                    password = server.getPassword();
                 }
 
                 if ( privateKey == null )
@@ -414,23 +414,21 @@ public abstract class AbstractScmMojo
 
                 if ( passphrase == null )
                 {
-                    passphrase = decrypt( server.getPassphrase(), host );
+                    passphrase = server.getPassphrase();
                 }
             }
         }
     }
 
-    private String decrypt( String str, String server )
+    private Server decrypt( Server server )
     {
-        try
-        {
-            return secDispatcher.decrypt( str );
-        }
-        catch ( SecDispatcherException e )
+        SettingsDecryptionResult result = settingsDecrypter.decrypt( new DefaultSettingsDecryptionRequest( server ) );
+        for ( SettingsProblem problem : result.getProblems() )
         {
-            getLog().warn( "Failed to decrypt password/passphrase for server " + server + ", using auth token as is" );
-            return str;
+            getLog().error( problem.getMessage(), problem.getException() );
         }
+
+        return result.getServer();
     }
 
     public void checkResult( ScmResult result )
diff --git a/maven-scm-plugin/src/main/resources/META-INF/plexus/components.xml b/maven-scm-plugin/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 6c997dbc6..000000000
--- a/maven-scm-plugin/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?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.
--->
-
-<component-set>
-  <components>
-    <component>
-      <role>org.sonatype.plexus.components.sec.dispatcher.SecDispatcher</role>
-      <role-hint>mng-4384</role-hint>
-      <implementation>org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher</implementation>
-      <requirements>
-        <requirement>
-          <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
-          <role-hint>mng-4384</role-hint>
-          <field-name>_cipher</field-name>
-        </requirement>
-      </requirements>
-      <configuration>
-        <_configuration-file>~/.m2/settings-security.xml</_configuration-file>
-      </configuration>
-    </component>
-    <component>
-      <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
-      <role-hint>mng-4384</role-hint>
-      <implementation>org.sonatype.plexus.components.cipher.DefaultPlexusCipher</implementation>
-    </component>
-  </components>
-</component-set>
diff --git a/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java b/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
index a447dc803..4755b6373 100644
--- a/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
+++ b/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
@@ -30,7 +30,6 @@ import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
 import org.codehaus.plexus.util.cli.Commandline;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -58,8 +57,6 @@ public abstract class ScmTestCase
 
     private ScmManager scmManager;
 
-    private SecDispatcher secDispatcher;
-
     protected void setUp()
         throws Exception
     {
@@ -146,24 +143,6 @@ public abstract class ScmTestCase
         return scmManager;
     }
 
-    /**
-     * If you wish to use this component, make sure to configure your
-     * TCK implementation to include plexus component configuration
-     * as doc at https://issues.apache.org/jira/browse/MNG-4384
-     * @return SecDispatcher
-     * @throws Exception
-     */
-    public SecDispatcher getSecDispatcher()
-        throws Exception
-    {
-        if ( secDispatcher == null )
-        {
-            secDispatcher = (SecDispatcher) lookup( SecDispatcher.class, "mng-4384" );
-        }
-
-        return secDispatcher;
-    }
-
     protected ScmRepository makeScmRepository( String scmUrl )
         throws Exception
     {