Enable support for use of encryption in Maven's settings.xml
This commit updates the CLI so that it will decrypt any encrypted passwords in a user's Maven settings.xml file. The code that performs the decrytion has a transitive dependency on three types in Plexus' logging API. There are tens of different artifacts containing this API available in Maven Central. Rather than bloating the API with a dependency on a complete Plexus container, which could perhaps be considered the primary source, a dependency on a considerably smaller artifact has been introduced. Closes #574
This commit is contained in:
@@ -20,7 +20,11 @@ import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
import org.apache.maven.settings.building.SettingsBuildingException;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.repository.Authentication;
|
||||
import org.eclipse.aether.repository.AuthenticationContext;
|
||||
import org.eclipse.aether.repository.LocalRepositoryManager;
|
||||
import org.eclipse.aether.repository.Proxy;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -28,6 +32,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
@@ -49,12 +54,60 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void basicSessionCustomization() throws SettingsBuildingException {
|
||||
assertSessionCustomization("src/test/resources/maven-settings/basic");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptedSettingsSessionCustomization() throws SettingsBuildingException {
|
||||
assertSessionCustomization("src/test/resources/maven-settings/encrypted");
|
||||
}
|
||||
|
||||
private void assertSessionCustomization(String userHome) {
|
||||
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
|
||||
|
||||
new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session,
|
||||
new SettingsXmlRepositorySystemSessionAutoConfiguration(userHome).apply(session,
|
||||
this.repositorySystem);
|
||||
|
||||
assertNotNull(session.getMirrorSelector());
|
||||
assertNotNull(session.getProxySelector());
|
||||
RemoteRepository repository = new RemoteRepository.Builder("my-server",
|
||||
"default", "http://maven.example.com").build();
|
||||
|
||||
assertMirrorSelectorConfiguration(session, repository);
|
||||
assertProxySelectorConfiguration(session, repository);
|
||||
assertAuthenticationSelectorConfiguration(session, repository);
|
||||
}
|
||||
|
||||
private void assertProxySelectorConfiguration(DefaultRepositorySystemSession session,
|
||||
RemoteRepository repository) {
|
||||
Proxy proxy = session.getProxySelector().getProxy(repository);
|
||||
repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
|
||||
AuthenticationContext authenticationContext = AuthenticationContext.forProxy(
|
||||
session, repository);
|
||||
assertEquals("proxy.example.com", proxy.getHost());
|
||||
assertEquals("proxyuser",
|
||||
authenticationContext.get(AuthenticationContext.USERNAME));
|
||||
assertEquals("somepassword",
|
||||
authenticationContext.get(AuthenticationContext.PASSWORD));
|
||||
}
|
||||
|
||||
private void assertMirrorSelectorConfiguration(
|
||||
DefaultRepositorySystemSession session, RemoteRepository repository) {
|
||||
RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
|
||||
assertNotNull("No mirror configured for repository " + repository.getId(), mirror);
|
||||
assertEquals("maven.example.com", mirror.getHost());
|
||||
}
|
||||
|
||||
private void assertAuthenticationSelectorConfiguration(
|
||||
DefaultRepositorySystemSession session, RemoteRepository repository) {
|
||||
Authentication authentication = session.getAuthenticationSelector()
|
||||
.getAuthentication(repository);
|
||||
|
||||
repository = new RemoteRepository.Builder(repository).setAuthentication(
|
||||
authentication).build();
|
||||
|
||||
AuthenticationContext authenticationContext = AuthenticationContext
|
||||
.forRepository(session, repository);
|
||||
|
||||
assertEquals("tester", authenticationContext.get(AuthenticationContext.USERNAME));
|
||||
assertEquals("secret", authenticationContext.get(AuthenticationContext.PASSWORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<settings>
|
||||
|
||||
<mirrors>
|
||||
<mirror>
|
||||
<id>my-mirror</id>
|
||||
<url>http://maven.example.com/mirror</url>
|
||||
<mirrorOf>my-server</mirrorOf>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
|
||||
<servers>
|
||||
<server>
|
||||
<id>my-server</id>
|
||||
<username>tester</username>
|
||||
<password>secret</password>
|
||||
</server>
|
||||
</servers>
|
||||
|
||||
<proxies>
|
||||
<proxy>
|
||||
<id>my-proxy</id>
|
||||
<active>true</active>
|
||||
<protocol>http</protocol>
|
||||
<host>proxy.example.com</host>
|
||||
<port>8080</port>
|
||||
<username>proxyuser</username>
|
||||
<password>somepassword</password>
|
||||
</proxy>
|
||||
</proxies>
|
||||
|
||||
</settings>
|
||||
@@ -0,0 +1,3 @@
|
||||
<settingsSecurity>
|
||||
<master>{oAyWuFO63U8HHgiplpqtgXih0/pwcRA0d+uA+Z7TBEk=}</master>
|
||||
</settingsSecurity>
|
||||
@@ -0,0 +1,31 @@
|
||||
<settings>
|
||||
|
||||
<mirrors>
|
||||
<mirror>
|
||||
<id>my-mirror</id>
|
||||
<url>http://maven.example.com/mirror</url>
|
||||
<mirrorOf>my-server</mirrorOf>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
|
||||
<servers>
|
||||
<server>
|
||||
<id>my-server</id>
|
||||
<username>tester</username>
|
||||
<password>{Ur5BpeQGlYUHhXsHahO/HbMBcPSFSUtN5gbWuFFPYGw=}</password>
|
||||
</server>
|
||||
</servers>
|
||||
|
||||
<proxies>
|
||||
<proxy>
|
||||
<id>my-proxy</id>
|
||||
<active>true</active>
|
||||
<protocol>http</protocol>
|
||||
<host>proxy.example.com</host>
|
||||
<port>8080</port>
|
||||
<username>proxyuser</username>
|
||||
<password>{3iRQQyaIUgQHwH8uzTvr9/52pZAjLOTWz/SlWDB7CM4=}</password>
|
||||
</proxy>
|
||||
</proxies>
|
||||
|
||||
</settings>
|
||||
Reference in New Issue
Block a user