mirror of https://github.com/apache/archiva.git
[MRM-1173] Cannot delete patterns with single and double quotes : fix black list too
simplify too fix for MRM-1135 git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178795 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ebcabb17a3
commit
2de2460457
|
@ -28,6 +28,7 @@ import org.apache.archiva.policies.DownloadErrorPolicy;
|
||||||
import org.apache.archiva.policies.Policy;
|
import org.apache.archiva.policies.Policy;
|
||||||
import org.apache.archiva.policies.PostDownloadPolicy;
|
import org.apache.archiva.policies.PostDownloadPolicy;
|
||||||
import org.apache.archiva.policies.PreDownloadPolicy;
|
import org.apache.archiva.policies.PreDownloadPolicy;
|
||||||
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -110,45 +111,12 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
this.downloadErrorPolicyMap = getBeansOfType( DownloadErrorPolicy.class );
|
this.downloadErrorPolicyMap = getBeansOfType( DownloadErrorPolicy.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> escapePatterns( List<String> patterns )
|
|
||||||
{
|
|
||||||
List<String> escapedPatterns = new ArrayList<String>( );
|
|
||||||
if ( patterns != null )
|
|
||||||
{
|
|
||||||
for ( String pattern : patterns )
|
|
||||||
{
|
|
||||||
String escapedPattern = StringUtils.replace( pattern, "\\", "\\\\" );
|
|
||||||
escapedPatterns.add( escapedPattern );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return escapedPatterns;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<String> unescapePatterns( List<String> patterns )
|
|
||||||
{
|
|
||||||
List<String> rawPatterns = new ArrayList<String>( );
|
|
||||||
if ( patterns != null )
|
|
||||||
{
|
|
||||||
for ( String pattern : patterns )
|
|
||||||
{
|
|
||||||
String unescapedPattern = StringUtils.replace( pattern, "\\\\", "\\" );
|
|
||||||
rawPatterns.add( unescapedPattern );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawPatterns;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String escapePattern( String pattern )
|
|
||||||
{
|
|
||||||
return StringUtils.replace( pattern, "\\", "\\\\" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String addBlackListPattern( )
|
public String addBlackListPattern( )
|
||||||
{
|
{
|
||||||
String pattern = getBlackListPattern( );
|
String pattern = getBlackListPattern( );
|
||||||
|
|
||||||
|
//pattern = StringEscapeUtils.unescapeJavaScript( pattern );
|
||||||
|
|
||||||
if ( StringUtils.isBlank( pattern ) )
|
if ( StringUtils.isBlank( pattern ) )
|
||||||
{
|
{
|
||||||
addActionError( "Cannot add a blank black list pattern." );
|
addActionError( "Cannot add a blank black list pattern." );
|
||||||
|
@ -156,7 +124,7 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
|
|
||||||
if ( !hasActionErrors( ) )
|
if ( !hasActionErrors( ) )
|
||||||
{
|
{
|
||||||
getConnector( ).getBlackListPatterns( ).add( escapePattern( pattern ) );
|
getConnector( ).getBlackListPatterns( ).add( pattern );
|
||||||
setBlackListPattern( null );
|
setBlackListPattern( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +160,7 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
public String addWhiteListPattern( )
|
public String addWhiteListPattern( )
|
||||||
{
|
{
|
||||||
String pattern = getWhiteListPattern( );
|
String pattern = getWhiteListPattern( );
|
||||||
|
//pattern = StringEscapeUtils.unescapeJavaScript( pattern );
|
||||||
if ( StringUtils.isBlank( pattern ) )
|
if ( StringUtils.isBlank( pattern ) )
|
||||||
{
|
{
|
||||||
addActionError( "Cannot add a blank white list pattern." );
|
addActionError( "Cannot add a blank white list pattern." );
|
||||||
|
@ -200,7 +168,7 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
|
|
||||||
if ( !hasActionErrors( ) )
|
if ( !hasActionErrors( ) )
|
||||||
{
|
{
|
||||||
getConnector( ).getWhiteListPatterns( ).add( escapePattern( pattern ) );
|
getConnector( ).getWhiteListPatterns( ).add( pattern );
|
||||||
setWhiteListPattern( null );
|
setWhiteListPattern( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,14 +244,14 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !getConnector( ).getBlackListPatterns( ).contains( pattern )
|
if ( !getConnector( ).getBlackListPatterns( ).contains( pattern )
|
||||||
&& !getConnector( ).getBlackListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
|
&& !getConnector( ).getBlackListPatterns( ).contains( pattern ))
|
||||||
{
|
{
|
||||||
addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." );
|
addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !hasActionErrors( ) )
|
if ( !hasActionErrors( ) )
|
||||||
{
|
{
|
||||||
getConnector( ).getBlackListPatterns( ).remove( escapePattern( pattern ) );
|
getConnector( ).getBlackListPatterns( ).remove( pattern );
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlackListPattern( null );
|
setBlackListPattern( null );
|
||||||
|
@ -327,14 +295,14 @@ public abstract class AbstractProxyConnectorFormAction
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !getConnector( ).getWhiteListPatterns( ).contains( pattern )
|
if ( !getConnector( ).getWhiteListPatterns( ).contains( pattern )
|
||||||
&& !getConnector( ).getWhiteListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
|
&& !getConnector( ).getWhiteListPatterns( ).contains( pattern ))
|
||||||
{
|
{
|
||||||
addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." );
|
addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !hasActionErrors( ) )
|
if ( !hasActionErrors( ) )
|
||||||
{
|
{
|
||||||
getConnector( ).getWhiteListPatterns( ).remove( escapePattern( pattern ) );
|
getConnector( ).getWhiteListPatterns( ).remove( pattern );
|
||||||
}
|
}
|
||||||
|
|
||||||
setWhiteListPattern( null );
|
setWhiteListPattern( null );
|
||||||
|
|
|
@ -62,14 +62,6 @@ public class EditProxyConnectorAction
|
||||||
+ "]" );
|
+ "]" );
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( connector != null )
|
|
||||||
{
|
|
||||||
// MRM-1135
|
|
||||||
connector.setBlackListPatterns( escapePatterns( connector.getBlackListPatterns() ) );
|
|
||||||
connector.setWhiteListPatterns( escapePatterns( connector.getWhiteListPatterns() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return INPUT;
|
return INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,19 +134,19 @@
|
||||||
</c:when>
|
</c:when>
|
||||||
<c:otherwise>
|
<c:otherwise>
|
||||||
<table>
|
<table>
|
||||||
<c:forEach items="${connector.blackListPatterns}" var="pattern" varStatus="i">
|
<s:iterator value="connector.blackListPatterns" var="currentPattern" status="i">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<s:hidden name="connector.blackListPatterns" value="%{#attr.pattern}"/>
|
<input type="hidden" name="connector.blackListPatterns" value="<s:property value="currentPattern" escapeHtml="true"/>"/>
|
||||||
<code>"${pattern}"</code>
|
<code>"${currentPattern}"</code>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="#" title="Remove [${pattern}] Pattern"
|
<a href="#" title="Remove [${currentPattern}] Pattern"
|
||||||
onclick="setAndSubmit('pattern', '${pattern}', 'removeBlackListPattern')">
|
onclick="setAndSubmit('pattern', '<s:property value="currentPattern" escapeJavaScript="true"/>', 'removeBlackListPattern')">
|
||||||
<img src="${iconDeleteUrl}"/></a>
|
<img src="${iconDeleteUrl}"/></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:forEach>
|
</s:iterator>
|
||||||
</table>
|
</table>
|
||||||
</c:otherwise>
|
</c:otherwise>
|
||||||
</c:choose>
|
</c:choose>
|
||||||
|
@ -176,7 +176,7 @@
|
||||||
<s:iterator value="connector.whiteListPatterns" var="currentPattern" status="i">
|
<s:iterator value="connector.whiteListPatterns" var="currentPattern" status="i">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<input type="hidden" name="connector.whiteListPatterns" value="${currentPattern}"/>
|
<input type="hidden" name="connector.whiteListPatterns" value="<s:property value="currentPattern" escapeHtml="true"/>"/>
|
||||||
<code>"${currentPattern}"</code>
|
<code>"${currentPattern}"</code>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
Loading…
Reference in New Issue