mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Site Service: make site service more robust in it's handling of special characters, only allow alphanumeric site short names for the preview release
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10119 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -60,8 +60,6 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site Service Implementation. Also bootstraps the site AVM and DM stores.
|
* Site Service Implementation. Also bootstraps the site AVM and DM stores.
|
||||||
*
|
*
|
||||||
@@ -88,6 +86,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
|||||||
private AuthenticationComponent authenticationComponent;
|
private AuthenticationComponent authenticationComponent;
|
||||||
private TaggingService taggingService;
|
private TaggingService taggingService;
|
||||||
|
|
||||||
|
/** The site root node reference */
|
||||||
|
private NodeRef siteRootNodeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set node service
|
* Set node service
|
||||||
*
|
*
|
||||||
@@ -175,6 +176,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
|||||||
{
|
{
|
||||||
/// TODO check for shortname duplicates
|
/// TODO check for shortname duplicates
|
||||||
|
|
||||||
|
// Remove spaces from shortName
|
||||||
|
shortName = shortName.replaceAll(" ", "");
|
||||||
|
|
||||||
// Get the site parent node reference
|
// Get the site parent node reference
|
||||||
NodeRef siteParent = getSiteParent(shortName);
|
NodeRef siteParent = getSiteParent(shortName);
|
||||||
|
|
||||||
@@ -232,20 +236,25 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
|||||||
*/
|
*/
|
||||||
private NodeRef getSiteRoot()
|
private NodeRef getSiteRoot()
|
||||||
{
|
{
|
||||||
// Get the root 'sites' folder
|
if (this.siteRootNodeRef == null)
|
||||||
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
|
|
||||||
if (resultSet.length() == 0)
|
|
||||||
{
|
{
|
||||||
// No root site folder exists
|
// Get the root 'sites' folder
|
||||||
throw new AlfrescoRuntimeException("No root sites folder exists");
|
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
|
||||||
|
if (resultSet.length() == 0)
|
||||||
|
{
|
||||||
|
// No root site folder exists
|
||||||
|
throw new AlfrescoRuntimeException("No root sites folder exists");
|
||||||
|
}
|
||||||
|
else if (resultSet.length() != 1)
|
||||||
|
{
|
||||||
|
// More than one root site folder exits
|
||||||
|
throw new AlfrescoRuntimeException("More than one root sites folder exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.siteRootNodeRef = resultSet.getNodeRef(0);
|
||||||
}
|
}
|
||||||
else if (resultSet.length() != 1)
|
|
||||||
{
|
return this.siteRootNodeRef;
|
||||||
// More than one root site folder exits
|
|
||||||
throw new AlfrescoRuntimeException("More than one root sites folder exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultSet.getNodeRef(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -359,13 +368,15 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
|||||||
*/
|
*/
|
||||||
private NodeRef getSiteNodeRef(String shortName)
|
private NodeRef getSiteNodeRef(String shortName)
|
||||||
{
|
{
|
||||||
NodeRef result = null;
|
NodeRef result = null;
|
||||||
|
NodeRef siteRoot = getSiteParent(shortName);
|
||||||
String query = "+TYPE:\"st:site\" +@cm\\:name:\"" + shortName + "\"";
|
List<ChildAssociationRef> assoc = this.nodeService.getChildAssocs(
|
||||||
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, query);
|
siteRoot,
|
||||||
if (resultSet.length() == 1)
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, shortName));
|
||||||
|
if (assoc.size() == 1)
|
||||||
{
|
{
|
||||||
result = resultSet.getNodeRef(0);
|
result = assoc.get(0).getChildRef();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -85,9 +85,19 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
{
|
{
|
||||||
// Create a public site
|
// Create a public site
|
||||||
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, true);
|
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
|
||||||
// Check the site
|
|
||||||
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, true);
|
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
|
||||||
|
String name = "!\"<EFBFBD>$%^&*()_+=-[]{}";
|
||||||
|
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
siteInfo = this.siteService.getSite(name);
|
||||||
|
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
|
||||||
|
name = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||||
|
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
|
siteInfo = this.siteService.getSite(name);
|
||||||
|
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSiteInfo( SiteInfo siteInfo, String expectedSitePreset, String expectedShortName, String expectedTitle,
|
private void checkSiteInfo( SiteInfo siteInfo, String expectedSitePreset, String expectedShortName, String expectedTitle,
|
||||||
|
Reference in New Issue
Block a user