diff --git a/pom.xml b/pom.xml
index fdc151e59..07aa74687 100644
--- a/pom.xml
+++ b/pom.xml
@@ -169,6 +169,13 @@
provided
+
+ org.apache.maven
+ maven-compat
+ ${maven.version}
+ provided
+
+
org.apache.maven
maven-core
@@ -190,6 +197,13 @@
provided
+
+ org.apache.maven
+ maven-settings-builder
+ ${maven.version}
+ provided
+
+
org.apache.maven.plugin-tools
maven-plugin-annotations
@@ -244,7 +258,6 @@
org.codehaus.plexus
plexus-utils
3.0.24
- provided
@@ -295,13 +308,6 @@
test
-
- org.sonatype.plexus
- plexus-sec-dispatcher
- 1.3
- provided
-
-
org.yaml
snakeyaml
diff --git a/src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java b/src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java
index 1b69850dc..be6a0bbc7 100644
--- a/src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java
+++ b/src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java
@@ -6,7 +6,6 @@
import java.io.Reader;
import com.google.gson.JsonObject;
-import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@@ -33,10 +32,12 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import com.google.common.net.UrlEscapers;
import com.google.gson.Gson;
@@ -670,16 +671,15 @@ private Server checkForServer(Server server, String id, String registry, String
private String decrypt(String password) throws MojoExecutionException {
try {
- // Done by reflection since I have classloader issues otherwise
- Object secDispatcher = container.lookup(SecDispatcher.ROLE, "maven");
- Method method = secDispatcher.getClass().getMethod("decrypt",String.class);
- synchronized(secDispatcher) {
- return (String) method.invoke(secDispatcher, password);
- }
+ SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class);
+ Server stub = new Server();
+ stub.setUsername("whatever");
+ stub.setPassword(password);
+
+ SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(stub));
+ return result.getServers().get(0).getPassword();
} catch (ComponentLookupException e) {
throw new MojoExecutionException("Error looking security dispatcher",e);
- } catch (ReflectiveOperationException e) {
- throw new MojoExecutionException("Cannot decrypt password: " + e.getCause(),e);
}
}
diff --git a/src/test/java/io/fabric8/maven/docker/PushMojoBuildXTest.java b/src/test/java/io/fabric8/maven/docker/PushMojoBuildXTest.java
index 3e79ca19a..a7494977c 100644
--- a/src/test/java/io/fabric8/maven/docker/PushMojoBuildXTest.java
+++ b/src/test/java/io/fabric8/maven/docker/PushMojoBuildXTest.java
@@ -14,6 +14,8 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.junit.jupiter.api.AfterEach;
@@ -62,6 +64,7 @@ void setup() throws MojoExecutionException, MojoFailureException, IOException, C
DockerAccess dockerAccess = mock(DockerAccess.class);
PlexusContainer mockedPlexusContainer = mock(PlexusContainer.class);
SecDispatcher mockedSecDispatcher = mock(SecDispatcher.class);
+ when(mockedPlexusContainer.lookup(SettingsDecrypter.class)).thenReturn(new DefaultSettingsDecrypter(mockedSecDispatcher));
ServiceHubFactory serviceHubFactory = new ServiceHubFactory();
when(mockedMavenSettings.getInteractiveMode()).thenReturn(false);
Properties properties = new Properties();
diff --git a/src/test/java/io/fabric8/maven/docker/util/AuthConfigFactoryTest.java b/src/test/java/io/fabric8/maven/docker/util/AuthConfigFactoryTest.java
index 695181067..20858291e 100644
--- a/src/test/java/io/fabric8/maven/docker/util/AuthConfigFactoryTest.java
+++ b/src/test/java/io/fabric8/maven/docker/util/AuthConfigFactoryTest.java
@@ -14,6 +14,8 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.Base64;
@@ -101,7 +103,7 @@ public String decrypt(String password) {
@BeforeEach
void containerSetup() throws ComponentLookupException, SecDispatcherException {
- Mockito.lenient().when(container.lookup(SecDispatcher.ROLE, "maven")).thenReturn(secDispatcher);
+ Mockito.lenient().when(container.lookup(SettingsDecrypter.class)).thenReturn(new DefaultSettingsDecrypter(secDispatcher));
Mockito.lenient().when(secDispatcher.decrypt(Mockito.anyString())).thenAnswer(invocation -> invocation.getArguments()[0]);
factory = new AuthConfigFactory(container);