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:
Roy Wetherall
2008-07-30 12:33:18 +00:00
parent 37c19eab01
commit a26cd025bf
2 changed files with 43 additions and 22 deletions

View File

@@ -60,8 +60,6 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.json.JSONObject;
import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
/**
* 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 TaggingService taggingService;
/** The site root node reference */
private NodeRef siteRootNodeRef;
/**
* Set node service
*
@@ -175,6 +176,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
{
/// TODO check for shortname duplicates
// Remove spaces from shortName
shortName = shortName.replaceAll(" ", "");
// Get the site parent node reference
NodeRef siteParent = getSiteParent(shortName);
@@ -232,20 +236,25 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/
private NodeRef getSiteRoot()
{
// Get the root 'sites' folder
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
if (resultSet.length() == 0)
if (this.siteRootNodeRef == null)
{
// No root site folder exists
throw new AlfrescoRuntimeException("No root sites folder exists");
// Get the root 'sites' folder
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)
{
// More than one root site folder exits
throw new AlfrescoRuntimeException("More than one root sites folder exists");
}
return resultSet.getNodeRef(0);
return this.siteRootNodeRef;
}
/**
@@ -359,13 +368,15 @@ public class SiteServiceImpl implements SiteService, SiteModel
*/
private NodeRef getSiteNodeRef(String shortName)
{
NodeRef result = null;
String query = "+TYPE:\"st:site\" +@cm\\:name:\"" + shortName + "\"";
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, query);
if (resultSet.length() == 1)
NodeRef result = null;
NodeRef siteRoot = getSiteParent(shortName);
List<ChildAssociationRef> assoc = this.nodeService.getChildAssocs(
siteRoot,
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;
}

View File

@@ -85,9 +85,19 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
{
// Create a public site
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);
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,