From 428f8ddbbc57b3e1067e75b47349f61b7e7fe48c Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 20 Jun 2012 23:06:09 +0000 Subject: [PATCH] Validate that the site Short Name isn't too long during creation, and throw a helpful exception if it is. (Site Short Names get used in Authority Names, which are limited by the DB model to 100 characters) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@38101 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/site-service.properties | 1 + .../java/org/alfresco/repo/site/SiteServiceImpl.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/config/alfresco/messages/site-service.properties b/config/alfresco/messages/site-service.properties index 89d1a4f697..9836723b3d 100644 --- a/config/alfresco/messages/site-service.properties +++ b/config/alfresco/messages/site-service.properties @@ -1,6 +1,7 @@ # Site service externalised display strings site_service.unable_to_create=Unable to create site because the site short name {0} is already in use. Site short names must be unique. +site_service.short_name_too_long=Unable to create site because the site short name {0} is too long. Site short names can be no longer than {1} characters. site_service.visibility_group_missing=Unable to create site because the visibility group {0} does not exist. site_service.can_not_update=Cannot update site {0} because it does not exist. site_service.can_not_delete=Cannot delete site {0} because it does not exist. diff --git a/source/java/org/alfresco/repo/site/SiteServiceImpl.java b/source/java/org/alfresco/repo/site/SiteServiceImpl.java index c85ef42406..69327127c2 100644 --- a/source/java/org/alfresco/repo/site/SiteServiceImpl.java +++ b/source/java/org/alfresco/repo/site/SiteServiceImpl.java @@ -132,6 +132,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic /** Messages */ private static final String MSG_UNABLE_TO_CREATE = "site_service.unable_to_create"; + private static final String MSG_SITE_SHORT_NAME_TOO_LONG = "site_service.short_name_too_long"; private static final String MSG_VISIBILITY_GROUP_MISSING = "site_service.visibility_group_missing"; private static final String MSG_CAN_NOT_UPDATE = "site_service.can_not_update"; private static final String MSG_CAN_NOT_DELETE = "site_service.can_not_delete"; @@ -453,6 +454,16 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic // Throw an exception since we have a duplicate site name throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName}); } + + // Check that the site name isn't too long + // Authorities are limited to 100 characters by the PermissionService + int maximumPermisionGroupLength = 100; + if (getSiteGroup(shortName, true).length() > maximumPermisionGroupLength) + { + throw new SiteServiceException(MSG_SITE_SHORT_NAME_TOO_LONG, new Object[] { + shortName, maximumPermisionGroupLength - getSiteGroup("", true).length() + }); + } // Get the site parent node reference final NodeRef siteParent = getSiteParent(shortName);