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.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);
@@ -231,6 +235,8 @@ public class SiteServiceImpl implements SiteService, SiteModel
* @return NodeRef node reference * @return NodeRef node reference
*/ */
private NodeRef getSiteRoot() private NodeRef getSiteRoot()
{
if (this.siteRootNodeRef == null)
{ {
// Get the root 'sites' folder // Get the root 'sites' folder
ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\""); ResultSet resultSet = this.searchService.query(SITE_STORE, SearchService.LANGUAGE_LUCENE, "TYPE:\"st:sites\"");
@@ -245,7 +251,10 @@ public class SiteServiceImpl implements SiteService, SiteModel
throw new AlfrescoRuntimeException("More than one root sites folder exists"); throw new AlfrescoRuntimeException("More than one root sites folder exists");
} }
return resultSet.getNodeRef(0); this.siteRootNodeRef = resultSet.getNodeRef(0);
}
return this.siteRootNodeRef;
} }
/** /**
@@ -360,12 +369,14 @@ 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;
} }

View File

@@ -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,