[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
This commit is contained in:
Oleg Gusakov 2009-02-12 22:42:53 +00:00
parent 84e363c313
commit 9737a2f1d9
1 changed files with 36 additions and 0 deletions

View File

@ -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
@ -101,6 +105,8 @@ public class DefaultMavenSettingsBuilder
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();
if ( localRepository != null && localRepository.length() > 0 )
@ -115,6 +121,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<Server> 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
{