res = null;
- StringTokenizer st = new StringTokenizer(attrs, ", ");
-
- while (st.hasMoreTokens()) {
- if (res == null) {
- res = new HashMap<>(st.countTokens());
- }
-
- String pair = st.nextToken();
-
- int pos = pair.indexOf('=');
-
- if (pos == -1) {
- continue;
- }
-
- String key = pair.substring(0, pos).trim();
-
- if (pos == pair.length()) {
- res.put(key, null);
- continue;
- }
-
- String val = pair.substring(pos + 1);
-
- res.put(key, val.trim());
- }
-
- return res;
- }
-
- return null;
- }
-
- private boolean isEncryptedString(String str) {
- if (str == null) {
- return false;
- }
-
- return cipher.isEncryptedString(str);
- }
-
- private String getMaster() throws SecDispatcherException, InvalidConfigurationFileException {
-
- if (securitySettings == null) {
- throw new InvalidConfigurationFileException(
- "Unable to get security configuration from " + securitySettingsPath.getPath()
- + ". Please define path to the settings-security.xml file via -D" +
- MavenSettingsBuilder.ALT_SECURITY_SETTINGS_XML_LOCATION
- + ", or put it the the default location defined by Maven.");
- }
- String master = securitySettings.getMaster();
-
- if (master == null) {
- throw new InvalidConfigurationFileException("Security configuration from " + securitySettingsPath.getPath()
- + " does not contain master password");
- }
-
- try {
- return cipher.decryptDecorated(master, DEFAULT_PASSPHRASE);
- } catch (PlexusCipherException e) {
- throw new SecDispatcherException(e);
- }
- }
-}
diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java
deleted file mode 100644
index 6210346b..00000000
--- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2013, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.resolver.impl.maven.internal.decrypt;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.apache.maven.settings.building.DefaultSettingsProblem;
-import org.apache.maven.settings.building.SettingsProblem;
-import org.apache.maven.settings.building.SettingsProblem.Severity;
-import org.apache.maven.settings.crypto.SettingsDecrypter;
-import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
-import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
-import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
-
-/**
- * Default settings decrypter configured to decrypt Maven encrypted passwords.
- *
- * Inspired by DefaultSettingsDecrypter from Sonatype
- *
- * @author Karel Piwko
- * @author Benjamin Bentmann
- */
-public class MavenSettingsDecrypter implements SettingsDecrypter {
-
- private final SecDispatcher securityDispatcher;
-
- public MavenSettingsDecrypter(File securitySettings) {
- this.securityDispatcher = new MavenSecurityDispatcher(securitySettings);
- }
-
- public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) {
- List problems = new ArrayList<>();
-
- List servers = new ArrayList<>();
-
- for (Server server : request.getServers()) {
- server = server.clone();
- servers.add(server);
-
- try {
- server.setPassword(decrypt(server.getPassword()));
- } catch (SecDispatcherException e) {
- problems.add(new DefaultSettingsProblem("Failed to decrypt password for server " + server.getId()
- + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
- }
-
- try {
- server.setPassphrase(decrypt(server.getPassphrase()));
- } catch (SecDispatcherException e) {
- problems.add(new DefaultSettingsProblem("Failed to decrypt passphrase for server " + server.getId()
- + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
- }
- }
-
- List proxies = new ArrayList<>();
-
- for (Proxy proxy : request.getProxies()) {
- proxy = proxy.clone();
- proxies.add(proxy);
-
- try {
- proxy.setPassword(decrypt(proxy.getPassword()));
- } catch (SecDispatcherException e) {
- problems.add(new DefaultSettingsProblem("Failed to decrypt password for proxy " + proxy.getId()
- + ": " + e.getMessage(), Severity.ERROR, "proxy: " + proxy.getId(), -1, -1, e));
- }
- }
-
- return new MavenSettingsDecryptionResult(servers, proxies, problems);
- }
-
- private String decrypt(String str) throws SecDispatcherException {
- return (str == null) ? null : securityDispatcher.decrypt(str);
- }
-
-}
diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecryptionResult.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecryptionResult.java
deleted file mode 100644
index d06f3af6..00000000
--- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecryptionResult.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2013, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- */
-package org.jboss.shrinkwrap.resolver.impl.maven.internal.decrypt;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.apache.maven.settings.building.SettingsProblem;
-import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-
-/**
- * Basic envelope for MavenSettingsDecryption result
- *
- * @author Karel Piwko
- *
- */
-class MavenSettingsDecryptionResult implements SettingsDecryptionResult {
-
- private final List servers;
-
- private final List proxies;
-
- private final List problems;
-
- MavenSettingsDecryptionResult(List servers, List proxies, List problems) {
- this.servers = servers == null ? Collections.emptyList() : servers;
- this.proxies = proxies == null ? Collections.emptyList() : proxies;
- this.problems = problems == null ? Collections.emptyList() : problems;
- }
-
- @Override
- public Server getServer() {
- return servers.isEmpty() ? null : servers.get(0);
- }
-
- @Override
- public List getServers() {
- return servers;
- }
-
- @Override
- public Proxy getProxy() {
- return proxies.isEmpty() ? null : proxies.get(0);
- }
-
- @Override
- public List getProxies() {
- return proxies;
- }
-
- @Override
- public List getProblems() {
- return problems;
- }
-
-}
diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java
index 9ecd107b..004f00ef 100644
--- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java
+++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java
@@ -20,7 +20,12 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import eu.maveniverse.maven.mima.context.Context;
+import eu.maveniverse.maven.mima.context.ContextOverrides;
+import eu.maveniverse.maven.mima.context.Runtime;
+import eu.maveniverse.maven.mima.context.Runtimes;
import org.apache.maven.settings.building.SettingsBuildingRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
@@ -75,7 +80,7 @@ private String removeDoubledSeparator(String path){
// this is calling internal private method that handles logic of settings.xml setup
private SettingsBuildingRequest createBuildingRequest() {
try {
- MavenSettingsBuilder builder = new MavenSettingsBuilder();
+ MavenSettingsBuilder builder = new MavenSettingsBuilder(getSettingsDecrypter());
Class extends MavenSettingsBuilder> clazz = builder.getClass();
Method m = clazz.getDeclaredMethod("getDefaultSettingsBuildingRequest");
m.setAccessible(true);
@@ -89,4 +94,10 @@ private SettingsBuildingRequest createBuildingRequest() {
return null;
}
+ static SettingsDecrypter getSettingsDecrypter() {
+ Runtime runtime = Runtimes.INSTANCE.getRuntime();
+ Context context = runtime.create(ContextOverrides.create().build());
+ return context.lookup().lookup(SettingsDecrypter.class).get();
+ }
+
}
diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilderUnitTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilderUnitTestCase.java
index 5e536282..73f75a57 100644
--- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilderUnitTestCase.java
+++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilderUnitTestCase.java
@@ -16,8 +16,13 @@
*/
package org.jboss.shrinkwrap.resolver.impl.maven.bootstrap;
+import eu.maveniverse.maven.mima.context.Context;
+import eu.maveniverse.maven.mima.context.ContextOverrides;
+import eu.maveniverse.maven.mima.context.Runtime;
+import eu.maveniverse.maven.mima.context.Runtimes;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -47,15 +52,21 @@ void afterMethod() {
}
+ static SettingsDecrypter getSettingsDecrypter() {
+ Runtime runtime = Runtimes.INSTANCE.getRuntime();
+ Context context = runtime.create(ContextOverrides.create().build());
+ return context.lookup().lookup(SettingsDecrypter.class).get();
+ }
+
@Test
void findUserProfile() {
- Settings mavenSettings = new MavenSettingsBuilder().buildDefaultSettings();
+ Settings mavenSettings = new MavenSettingsBuilder(getSettingsDecrypter()).buildDefaultSettings();
Assertions.assertTrue(mavenSettings.getProfilesAsMap().containsKey("user-profile"), "Profile in user settings not found");
}
@Test
void findGlobalProfile() {
- Settings mavenSettings = new MavenSettingsBuilder().buildDefaultSettings();
+ Settings mavenSettings = new MavenSettingsBuilder(getSettingsDecrypter()).buildDefaultSettings();
Assertions.assertTrue(mavenSettings.getProfilesAsMap().containsKey("global-profile"), "Profile in global settings not found");
}
@@ -66,7 +77,7 @@ void decryptEncryptedPassword() {
System.setProperty(MavenSettingsBuilder.ALT_SECURITY_SETTINGS_XML_LOCATION,
"target/settings/profiles/settings-security.xml");
- Settings mavenSettings = new MavenSettingsBuilder().buildDefaultSettings();
+ Settings mavenSettings = new MavenSettingsBuilder(getSettingsDecrypter()).buildDefaultSettings();
Server server = mavenSettings.getServer("auth-repository");
Assertions.assertNotNull(server, "Server auth-repository is not null");
@@ -80,7 +91,7 @@ void missingSecuritySettingsNotNeeded() {
System.setProperty(MavenSettingsBuilder.ALT_SECURITY_SETTINGS_XML_LOCATION,
"target/settings/profiles/non-existing-settings-security.xml");
- Settings mavenSettings = new MavenSettingsBuilder().buildDefaultSettings();
+ Settings mavenSettings = new MavenSettingsBuilder(getSettingsDecrypter()).buildDefaultSettings();
Server server = mavenSettings.getServer("auth-repository");
Assertions.assertNotNull(server, "Server auth-repository is not null");
diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java
deleted file mode 100644
index 783490e8..00000000
--- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2015, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.
- *
- */
-package org.jboss.shrinkwrap.resolver.impl.maven.integration;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Stream;
-
-import org.jboss.shrinkwrap.resolver.impl.maven.internal.decrypt.MavenPlexusCipher;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
-
-/**
- * Tests the {@link MavenPlexusCipher} whether it correctly evaluates and undecorates the right strings containing a cipher.
- *
- * @author Matous Jobanek
- */
-class MavenPlexusCipherTestCase {
-
- private static final String UNDECORATED_CIPHER = "70+YZM/w7f8HQrEZUGZABCHAW62qMo+Y8okw7xzLwOM=";
-
- private static final String ONLY_CIPHER = "{" + UNDECORATED_CIPHER + "}";
-
- // Possible strings that could be before/after the cipher
- private static final String[] DECORATION_VARIANTS =
- {
- "",
- " ",
- "\n",
- " \n \n",
- " blah \n blah \n",
- " \n ${variable} \n",
- "\t",
- // "{",
- "}"
- };
-
- // Possible strings that doesn't contain a valid cipher, but could be confusing
- private static final String[] WITHOUT_CIPHER_VARIANTS =
- {
- "\\" + ONLY_CIPHER,
- "$" + ONLY_CIPHER,
- "\\\\" + ONLY_CIPHER,
- "{" + UNDECORATED_CIPHER,
- "{" + UNDECORATED_CIPHER + "\\}",
- "{" + UNDECORATED_CIPHER + "\\\\}",
- UNDECORATED_CIPHER + "}",
- UNDECORATED_CIPHER
- };
-
- @MethodSource("getParameters")
- @ParameterizedTest
- void testIsEncryptedString(String str, boolean isStringEncrypted) {
- MavenPlexusCipher mavenPlexusCipher = new MavenPlexusCipher();
- Assertions.assertEquals(
- isStringEncrypted, mavenPlexusCipher.isEncryptedString(str),
- "The evaluation of the string " + str + " whether it represents a cipher has failed");
- }
-
- @MethodSource("getParameters")
- @ParameterizedTest
- void testUnDecorate(String str, boolean isStringEncrypted) {
- MavenPlexusCipher mavenPlexusCipher = new MavenPlexusCipher();
- try {
- String undecorated = mavenPlexusCipher.unDecorate(str);
-
- if (isStringEncrypted) {
- Assertions.assertEquals(UNDECORATED_CIPHER, undecorated,
- "The comparison of the undecorated string and expected cipher has failed");
- } else {
- Assertions.fail("The IllegalStateException should have been thrown here - the string: " + str
- + " doesn't represent an encrypted string. The method \"unDecorate\" returned: " + undecorated);
- }
-
- } catch (IllegalStateException ise) {
- if (isStringEncrypted) {
- Assertions.fail("The evaluation or undecoration of the string: " + str
- + " has failed, although it should have passed - it represents an encrypted string");
- }
- }
- }
-
- private static Stream