]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1135]
authorMaria Odea B. Ching <oching@apache.org>
Sat, 14 Mar 2009 06:43:22 +0000 (06:43 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Sat, 14 Mar 2009 06:43:22 +0000 (06:43 +0000)
o escape blacklist and whitelist pattern with '\'

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@753608 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java

index 4b306109bcbe772b558b0567ece180b2e717230f..26a492b65264794c2cd748f1bdea8f1df3c60799 100644 (file)
@@ -109,6 +109,39 @@ public abstract class AbstractProxyConnectorFormAction
      */
     protected ProxyConnectorConfiguration connector;
 
+    protected List<String> escapePatterns( List<String> patterns )
+    {   
+        List<String> escapedPatterns = new ArrayList<String>();
+        if( patterns != null )
+        {
+            for( String pattern : patterns )
+            {
+                escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) );
+            }
+        }
+        
+        return escapedPatterns;
+    }
+    
+    protected List<String> unescapePatterns( List<String> patterns )
+    {
+        List<String> rawPatterns = new ArrayList<String>();
+        if( patterns != null )
+        {
+            for( String pattern : patterns )
+            {
+                rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) );
+            }
+        }
+        
+        return rawPatterns;
+    }
+    
+    private String escapePattern( String pattern )
+    {
+        return StringUtils.replace( pattern, "\\", "\\\\" );
+    }
+        
     public String addBlackListPattern()
     {
         String pattern = getBlackListPattern();
@@ -117,13 +150,13 @@ public abstract class AbstractProxyConnectorFormAction
         {
             addActionError( "Cannot add a blank black list pattern." );
         }
-
+        
         if ( !hasActionErrors() )
         {
-            getConnector().getBlackListPatterns().add( pattern );
+            getConnector().getBlackListPatterns().add( escapePattern( pattern ) );
             setBlackListPattern( null );
         }
-
+        
         return INPUT;
     }
 
@@ -163,10 +196,10 @@ public abstract class AbstractProxyConnectorFormAction
 
         if ( !hasActionErrors() )
         {
-            getConnector().getWhiteListPatterns().add( pattern );
+            getConnector().getWhiteListPatterns().add( escapePattern( pattern ) );
             setWhiteListPattern( null );
         }
-
+        
         return INPUT;
     }
 
@@ -231,20 +264,21 @@ public abstract class AbstractProxyConnectorFormAction
     public String removeBlackListPattern()
     {
         String pattern = getPattern();
-
+        
         if ( StringUtils.isBlank( pattern ) )
         {
             addActionError( "Cannot remove a blank black list pattern." );
         }
 
-        if ( !getConnector().getBlackListPatterns().contains( pattern ) )
+        if ( !getConnector().getBlackListPatterns().contains( pattern ) && 
+            !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
         {
             addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." );
         }
 
         if ( !hasActionErrors() )
         {
-            getConnector().getBlackListPatterns().remove( pattern );
+            getConnector().getBlackListPatterns().remove( escapePattern( pattern ) );
         }
 
         setBlackListPattern( null );
@@ -287,14 +321,15 @@ public abstract class AbstractProxyConnectorFormAction
             addActionError( "Cannot remove a blank white list pattern." );
         }
 
-        if ( !getConnector().getWhiteListPatterns().contains( pattern ) )
+        if ( !getConnector().getWhiteListPatterns().contains( pattern ) &&
+                !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
         {
             addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." );
         }
 
         if ( !hasActionErrors() )
         {
-            getConnector().getWhiteListPatterns().remove( pattern );
+            getConnector().getWhiteListPatterns().remove( escapePattern( pattern ) );
         }
 
         setWhiteListPattern( null );
index 24b903906fc73c239b6ffcaf15a34a96d92a64c1..02511a13e180e64bc619c8a2fe799cd46b83f9b3 100644 (file)
@@ -42,6 +42,13 @@ public class AddProxyConnectorAction
     @Override
     public String input()
     {
+        if( connector != null )
+        {
+         // MRM-1135
+            connector.setBlackListPatterns( escapePatterns( connector.getBlackListPatterns() ) );
+            connector.setWhiteListPatterns( escapePatterns( connector.getWhiteListPatterns() ) );
+        }
+        
         return INPUT;
     }
 
@@ -75,6 +82,10 @@ public class AddProxyConnectorAction
             connector.setProxyId( null );
         }
 
+        // MRM-1135
+        connector.setBlackListPatterns( unescapePatterns( connector.getBlackListPatterns() ) );
+        connector.setWhiteListPatterns( unescapePatterns( connector.getWhiteListPatterns() ) );
+        
         addProxyConnector( connector );
         return saveConfiguration();
     }
index 6245a0fba5a4d48dc492a2e1262b09cdede0ad47..6ea3bd8d97a698e0c109386696390d854d6430db 100644 (file)
@@ -47,7 +47,7 @@ public class EditProxyConnectorAction
     {
         super.prepare();
 
-        connector = findProxyConnector( source, target );
+        connector = findProxyConnector( source, target );        
     }
 
     public String input()
@@ -58,6 +58,13 @@ public class EditProxyConnectorAction
                 + target + "]" );
             return ERROR;
         }
+        
+        if( connector != null )
+        {
+         // MRM-1135
+            connector.setBlackListPatterns( escapePatterns( connector.getBlackListPatterns() ) );
+            connector.setWhiteListPatterns( escapePatterns( connector.getWhiteListPatterns() ) );
+        }
 
         return INPUT;
     }
@@ -86,6 +93,10 @@ public class EditProxyConnectorAction
             return INPUT;
         }
 
+        // MRM-1135
+        connector.setBlackListPatterns( unescapePatterns( connector.getBlackListPatterns() ) );
+        connector.setWhiteListPatterns( unescapePatterns( connector.getWhiteListPatterns() ) );
+        
         addProxyConnector( connector );
         return saveConfiguration();
     }