continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r689234 - in /continuum/trunk: continuum-commons/src/main/java/org/apache/maven/continuum/configuration/ continuum-commons/src/main/java/org/apache/maven/continuum/utils/ continuum-commons/src/test/java/org/apache/maven/continuum/configurat...
Date Tue, 26 Aug 2008 21:23:44 GMT
Author: olamy
Date: Tue Aug 26 14:23:43 2008
New Revision: 689234

URL: http://svn.apache.org/viewvc?rev=689234&view=rev
Log:
[CONTINUUM-1489] replace use of MungedHttpsURL with commons-httpclient 
remove use of MungedHttpsURL to extract username/password from urls


Added:
    continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
  (with props)
Modified:
    continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
    continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
    continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
    continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java

Modified: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
(original)
+++ continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
Tue Aug 26 14:23:43 2008
@@ -152,6 +152,9 @@
         generalConfiguration.setBaseUrl( url );
     }
 
+    /** 
+     * @see org.apache.maven.continuum.configuration.ConfigurationService#getBuildOutputDirectory()
+     */
     public File getBuildOutputDirectory()
     {
         File buildOutputDirectory = generalConfiguration.getBuildOutputDirectory();

Modified: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
(original)
+++ continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ContinuumUrlValidator.java
Tue Aug 26 14:23:43 2008
@@ -19,17 +19,19 @@
  * under the License.
  */
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.oro.text.perl.Perl5Util;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.PlexusConfigurationException;
 import org.codehaus.plexus.formica.validation.AbstractValidator;
 import org.codehaus.plexus.formica.validation.util.Flags;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author <a href="mailto:olamy@apache.org">olamy</a>
@@ -223,7 +225,7 @@
             return true;
         }
 
-        value = replace( value, " ", "%20" );
+        value = StringUtils.replace( value, " ", "%20" );
 
         Perl5Util matchUrlPat = new Perl5Util();
         Perl5Util matchAsciiPat = new Perl5Util();
@@ -432,7 +434,7 @@
         }
 
         String extra = authorityMatcher.group( PARSE_AUTHORITY_EXTRA );
-        if ( !isBlankOrNull( extra ) )
+        if ( !StringUtils.isBlank( extra ) )
         {
             return false;
         }
@@ -521,31 +523,48 @@
         }
         return count;
     }
-
-    private static boolean isBlankOrNull( String value )
-    {
-        return ( ( value == null ) || ( value.trim().length() == 0 ) );
-    }
-
-    public static String replace( String text, String repl, String with )
+    
+    /**
+     * @param url
+     * @return URLUserInfo cannot be null
+     * @throws URISyntaxException
+     */
+    public URLUserInfo extractURLUserInfo( String url )
+        throws URISyntaxException
     {
-        if ( text == null || repl == null || with == null || repl.length() == 0 )
-        {
-            return text;
-        }
+        URI uri = new URI( url );
+        // can contains user:password
+        String userInfoRaw = uri.getUserInfo();
+        URLUserInfo urlUserInfo = new URLUserInfo();
 
-        StringBuffer buf = new StringBuffer( text.length() );
-        int start = 0, end = 0;
-        while ( ( end = text.indexOf( repl, start ) ) != -1 )
+        if ( !StringUtils.isEmpty( userInfoRaw ) )
         {
-            buf.append( text.substring( start, end ) ).append( with );
-            start = end + repl.length();
+            int index = userInfoRaw.indexOf( ':' );
+            if ( index >= 0 )
+            {
+                urlUserInfo.setUsername( userInfoRaw.substring( 0, index ) );
+                urlUserInfo.setPassword( userInfoRaw.substring( index + 1, userInfoRaw.length()
) );
+            }
+            else
+            {
+                urlUserInfo.setUsername( userInfoRaw );
+            }
         }
-
-        buf.append( text.substring( start ) );
-        return buf.toString();
+        return urlUserInfo;
     }
 
+    
+    /**
+     * remove auth from an url
+     * @param url
+     * @return https://username:password@svn.apache.org/repos -> https://svn.apache.org/repos
+     */
+    /*
+    public String removeURLUserInfo(String url)
+    {
+        
+    }*/
+    
     public void configure( PlexusConfiguration plexusConfiguration )
         throws PlexusConfigurationException
     {

Added: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java?rev=689234&view=auto
==============================================================================
--- continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
(added)
+++ continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
Tue Aug 26 14:23:43 2008
@@ -0,0 +1,62 @@
+package org.apache.maven.continuum.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @version $Id$
+ * @since 1.2
+ */
+public class URLUserInfo
+{
+
+    private String username;
+    
+    private String password;
+    
+    /**
+     * 
+     */
+    public URLUserInfo()
+    {
+        //
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+}

Propchange: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/utils/URLUserInfo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Modified: continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
(original)
+++ continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
Tue Aug 26 14:23:43 2008
@@ -60,10 +60,11 @@
 
         assertNotNull( service.getUrl() );
         assertEquals( "http://test", service.getUrl() );
-        log.info( service.getFile( "myBuildOutputDir" ).getAbsolutePath() );
-        log.info( service.getBuildOutputDirectory().getAbsolutePath() );
-        assertEquals( service.getFile( "myBuildOutputDir" ).getAbsolutePath(),
-                      service.getBuildOutputDirectory().getAbsolutePath() );
+        log.info( "myBuildOutputDir " + new File( getBasedir(), "target/myBuildOutputDir"
).getAbsolutePath() );
+
+        log.info( "getBuildOutputDirectory " + service.getBuildOutputDirectory().getAbsolutePath()
);
+        assertEquals( new File( getBasedir(), "target/myBuildOutputDir" ).getAbsolutePath(),
service
+            .getBuildOutputDirectory().getAbsolutePath() );
     }
 
     public void testConfigurationService()

Modified: continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
(original)
+++ continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/utils/ContinuumUrlValidatorTest.java
Tue Aug 26 14:23:43 2008
@@ -141,4 +141,34 @@
         assertTrue( getContinuumUrlValidator().validate( rootPom.toURL().toExternalForm()
) );
     }
    
+    
+    public void testExtractUserNamePwd()
+        throws Exception
+    {
+        ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
+        URLUserInfo usrInfo = continuumUrlValidator
+            .extractURLUserInfo( "https://username:password@svn.apache.org/repos/asf/continuum/trunk/pom.xml"
);
+        assertEquals( "username", usrInfo.getUsername() );
+        assertEquals( "password", usrInfo.getPassword() );
+    }
+    
+    public void testExtractUserNameEmptyPwd()
+        throws Exception
+    {
+        ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
+        URLUserInfo usrInfo = continuumUrlValidator
+            .extractURLUserInfo( "https://username@svn.apache.org/repos/asf/continuum/trunk/pom.xml"
);
+        assertEquals( "username", usrInfo.getUsername() );
+        assertNull( usrInfo.getPassword() );
+    }
+    
+    public void testExtractEmptyUserNameEmptyPwd()
+        throws Exception
+    {
+        ContinuumUrlValidator continuumUrlValidator = new ContinuumUrlValidator();
+        URLUserInfo usrInfo = continuumUrlValidator
+            .extractURLUserInfo( "https://svn.apache.org/repos/asf/continuum/trunk/pom.xml"
);
+        assertNull( usrInfo.getUsername() );
+        assertNull( usrInfo.getPassword() );
+    }     
 }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
Tue Aug 26 14:23:43 2008
@@ -19,6 +19,12 @@
  * under the License.
  */
 
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
 import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
@@ -27,17 +33,13 @@
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManager;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManagerException;
+import org.apache.maven.continuum.utils.ContinuumUrlValidator;
+import org.apache.maven.continuum.utils.URLUserInfo;
 import org.apache.maven.settings.MavenSettingsBuilder;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
-import org.codehaus.plexus.formica.util.MungedHttpsURL;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-
 /**
  * Resolve the project url being passed in and gather authentication information
  * if the url is so configured, then create the projects
@@ -65,6 +67,11 @@
      * @plexus.requirement
      */
     private MavenSettingsBuilder mavenSettingsBuilder;
+    
+    /**
+     * @plexus.requirement role-hint="continuumUrl"
+     */
+    private ContinuumUrlValidator urlValidator;    
 
     public static final String KEY_URL = "url";
 
@@ -122,25 +129,15 @@
                     getLogger().warn( "problem with settings file, disabling scm resolution
of username and password" );
                 }
 
-                MungedHttpsURL mungedURL;
-
                 if ( username == null )
                 {
-                    mungedURL = new MungedHttpsURL( curl );
-                    username = mungedURL.getUsername();
-                    password = mungedURL.getPassword();
+                    URLUserInfo urlUserInfo = urlValidator.extractURLUserInfo( curl );
+                    username = urlUserInfo.getUsername();
+                    password = urlUserInfo.getPassword();
                 }
-                else
-                {
-                    mungedURL = new MungedHttpsURL( curl, username, password );
-                }
-
-                mungedURL.setLogger( getLogger() );
 
-                if ( mungedURL.isValid() )
+                if ( urlValidator.isValid( curl ) )
                 {
-                    url = mungedURL.getURL();
-
                     BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate(
context );
                     if ( buildDefinitionTemplate == null )
                     {
@@ -165,6 +162,12 @@
             result = new ContinuumProjectBuildingResult();
             result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
         }
+        catch ( URISyntaxException e )
+        {
+            getLogger().info( "Malformed URL: " + hidePasswordInUrl( curl ), e );
+            result = new ContinuumProjectBuildingResult();
+            result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
+        }
 
         context.put( KEY_PROJECT_BUILDING_RESULT, result );
     }
@@ -223,4 +226,14 @@
     {
         this.mavenSettingsBuilder = mavenSettingsBuilder;
     }
+
+    public ContinuumUrlValidator getUrlValidator()
+    {
+        return urlValidator;
+    }
+
+    public void setUrlValidator( ContinuumUrlValidator urlValidator )
+    {
+        this.urlValidator = urlValidator;
+    }
 }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
Tue Aug 26 14:23:43 2008
@@ -29,11 +29,6 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.UnknownHostException;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.http.HttpException;
@@ -49,7 +44,6 @@
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
 import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.conn.ssl.X509HostnameVerifier;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
 import org.apache.http.params.BasicHttpParams;
@@ -86,30 +80,9 @@
         schemeRegistry.register( new Scheme( "http",  PlainSocketFactory.getSocketFactory(),
80 ) );
         // https scheme
         SSLSocketFactory sslSocketFactory =  SSLSocketFactory.getSocketFactory();
+        
         // ignore cert
-        sslSocketFactory.setHostnameVerifier( new X509HostnameVerifier(){
-
-            public boolean verify( String arg0, SSLSession arg1 )
-            {
-                return true;
-            }
-
-            public void verify( String arg0, SSLSocket arg1 )
-                throws IOException
-            {
-            }
-
-            public void verify( String arg0, String[] arg1, String[] arg2 )
-                throws SSLException
-            {
-            }
-
-            public void verify( String arg0, X509Certificate arg1 )
-                throws SSLException
-            {
-            }
-            
-        });
+        sslSocketFactory.setHostnameVerifier( SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
);
         schemeRegistry.register( new Scheme( "https", sslSocketFactory, 443 ) );
         
         HttpParams params = new BasicHttpParams();

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java?rev=689234&r1=689233&r2=689234&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
Tue Aug 26 14:23:43 2008
@@ -28,6 +28,7 @@
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManager;
+import org.apache.maven.continuum.utils.ContinuumUrlValidator;
 import org.apache.maven.settings.MavenSettingsBuilder;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.logging.Logger;
@@ -52,7 +53,7 @@
         mavenSettingsBuilderMock = mock( MavenSettingsBuilder.class );
         action.setProjectBuilderManager( (ContinuumProjectBuilderManager) projectBuilderManagerMock.proxy()
);
         action.setMavenSettingsBuilder( (MavenSettingsBuilder) mavenSettingsBuilderMock.proxy()
);
-
+        action.setUrlValidator( new ContinuumUrlValidator() );
         projectBuilder = mock( ContinuumProjectBuilder.class );
 
         projectBuilderManagerMock.expects( once() ).method( "getProjectBuilder" )
@@ -68,7 +69,7 @@
     }
 
     private BuildDefinitionTemplate getDefaultBuildDefinitionTemplate()
-    throws Exception
+        throws Exception
     {
         BuildDefinition bd = new BuildDefinition();
 
@@ -81,7 +82,7 @@
         bd.setBuildFile( "pom.xml" );
 
         bd.setType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
-        
+
         BuildDefinitionTemplate bdt = new BuildDefinitionTemplate();
         bdt.addBuildDefinition( bd );
         return bdt;



Mime
View raw message