mirror of
https://github.com/apache/archiva.git
synced 2025-02-08 02:59:43 +00:00
[MRM-819]
added validation to allow only alphanumeric, '.', '-' and '_' characters for repo group id git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@660472 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9afc627e10
commit
67de1cbc3b
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.opensymphony.webwork.interceptor.ServletRequestAware;
|
import com.opensymphony.webwork.interceptor.ServletRequestAware;
|
||||||
@ -60,6 +63,8 @@ public class RepositoryGroupsAction
|
|||||||
*/
|
*/
|
||||||
private String baseUrl;
|
private String baseUrl;
|
||||||
|
|
||||||
|
private static final Pattern REPO_GROUP_ID_PATTERN = Pattern.compile( "[A-Za-z0-9\\._\\-]+" );
|
||||||
|
|
||||||
public void setServletRequest( HttpServletRequest request )
|
public void setServletRequest( HttpServletRequest request )
|
||||||
{
|
{
|
||||||
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
|
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
|
||||||
@ -81,6 +86,25 @@ public String addRepositoryGroup()
|
|||||||
|
|
||||||
String repoGroupId = repositoryGroup.getId();
|
String repoGroupId = repositoryGroup.getId();
|
||||||
|
|
||||||
|
if( repoGroupId == null || "".equals( repoGroupId.trim() ) )
|
||||||
|
{
|
||||||
|
addActionError( "Identifier field is required." );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( repoGroupId.length() > 100 )
|
||||||
|
{
|
||||||
|
addActionError( "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher matcher = REPO_GROUP_ID_PATTERN.matcher( repoGroupId );
|
||||||
|
if( !matcher.matches() )
|
||||||
|
{
|
||||||
|
addActionError( "Invalid character(s) found in identifier. Only the following characters are allowed: alphanumeric, '.', '-' and '_'" );
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if ( StringUtils.isBlank( repoGroupId ) )
|
if ( StringUtils.isBlank( repoGroupId ) )
|
||||||
{
|
{
|
||||||
addActionError( "You must enter a repository group id." );
|
addActionError( "You must enter a repository group id." );
|
||||||
@ -105,12 +129,6 @@ else if ( configuration.getRemoteRepositoriesAsMap().containsKey( repoGroupId )
|
|||||||
+ "], that id already exists as a remote repository." );
|
+ "], that id already exists as a remote repository." );
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( repoGroupId.length() > 100 )
|
|
||||||
{
|
|
||||||
addActionError( "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" );
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
configuration.addRepositoryGroup( repositoryGroup );
|
configuration.addRepositoryGroup( repositoryGroup );
|
||||||
return saveConfiguration( configuration );
|
return saveConfiguration( configuration );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user