From 9737a2f1d9461aabd91f6635390923617e234230 Mon Sep 17 00:00:00 2001 From: Oleg Gusakov Date: Thu, 12 Feb 2009 22:42:53 +0000 Subject: [PATCH] [MNG-4033] migrated password encryption from 2.1.x trunk git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@743912 13f79535-47bb-0310-9956-ffa450edef68 --- .../settings/DefaultMavenSettingsBuilder.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index 63503ab498..cebc73c0bd 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -34,6 +34,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; import java.io.File; import java.io.IOException; @@ -53,6 +54,9 @@ public class DefaultMavenSettingsBuilder @Requirement private SettingsValidator validator; + @Requirement( hint = "maven" ) + private SecDispatcher securityDispatcher; + /** @since 2.1 */ public Settings buildSettings( MavenExecutionRequest request ) throws IOException, XmlPullParserException @@ -100,6 +104,8 @@ public class DefaultMavenSettingsBuilder TrackableBase.GLOBAL_LEVEL ); userSettings = interpolate( userSettings, request ); + + decrypt( userSettings ); // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble String localRepository = userSettings.getLocalRepository(); @@ -114,6 +120,36 @@ public class DefaultMavenSettingsBuilder return userSettings; } + + + /** + * decrypt settings passwords and passphrases + * + * @param settings settings to process + * @throws IOException + */ + @SuppressWarnings("unchecked") + private void decrypt( Settings settings ) + throws IOException + { + List servers = settings.getServers(); + + if( servers != null && !servers.isEmpty() ) + try + { + for( Server server : servers ) + { + if( server.getPassword() != null ) + server.setPassword( securityDispatcher.decrypt( server.getPassword() ) ); + } + } + catch( Exception e ) + { + // 2009-02-12 Oleg: get do this because 2 levels up Exception is + // caught, not exception type does not matter + throw new IOException( e.getMessage() ); + } + } private Settings interpolate( Settings settings, MavenExecutionRequest request ) throws IOException, XmlPullParserException