diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java index 4b306109b..26a492b65 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java @@ -109,6 +109,39 @@ public abstract class AbstractProxyConnectorFormAction */ protected ProxyConnectorConfiguration connector; + protected List escapePatterns( List patterns ) + { + List escapedPatterns = new ArrayList(); + if( patterns != null ) + { + for( String pattern : patterns ) + { + escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) ); + } + } + + return escapedPatterns; + } + + protected List unescapePatterns( List patterns ) + { + List rawPatterns = new ArrayList(); + 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 ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java index 24b903906..02511a13e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java @@ -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(); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java index 6245a0fba..6ea3bd8d9 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java @@ -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(); }