mirror of https://github.com/apache/archiva.git
[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
This commit is contained in:
parent
07bb48e79d
commit
9198c4e336
|
@ -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();
|
||||
|
@ -120,7 +153,7 @@ public abstract class AbstractProxyConnectorFormAction
|
|||
|
||||
if ( !hasActionErrors() )
|
||||
{
|
||||
getConnector().getBlackListPatterns().add( pattern );
|
||||
getConnector().getBlackListPatterns().add( escapePattern( pattern ) );
|
||||
setBlackListPattern( null );
|
||||
}
|
||||
|
||||
|
@ -163,7 +196,7 @@ public abstract class AbstractProxyConnectorFormAction
|
|||
|
||||
if ( !hasActionErrors() )
|
||||
{
|
||||
getConnector().getWhiteListPatterns().add( pattern );
|
||||
getConnector().getWhiteListPatterns().add( escapePattern( pattern ) );
|
||||
setWhiteListPattern( null );
|
||||
}
|
||||
|
||||
|
@ -237,14 +270,15 @@ public abstract class AbstractProxyConnectorFormAction
|
|||
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 );
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -59,6 +59,13 @@ public class EditProxyConnectorAction
|
|||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue