diff options
author | Maria Odea B. Ching <oching@apache.org> | 2009-03-14 06:43:22 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2009-03-14 06:43:22 +0000 |
commit | 9198c4e3365e9a7eef7cf2d5a2e6f9936504acdb (patch) | |
tree | 2b36e3d9529a98aa226c27f796aa2587e7f63b25 /archiva-modules | |
parent | 07bb48e79d3f03f55bbf72556e63ae192a12c0b1 (diff) | |
download | archiva-9198c4e3365e9a7eef7cf2d5a2e6f9936504acdb.tar.gz archiva-9198c4e3365e9a7eef7cf2d5a2e6f9936504acdb.zip |
[MRM-1135]
o escape blacklist and whitelist pattern with '\'
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@753608 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
3 files changed, 68 insertions, 11 deletions
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<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 ); 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(); } |