ETHREEOH-2133 Creating a duplicate 'private' site returns permission denied instead of meaningful error

- The pre-existing test is now run as root.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14794 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2009-06-18 16:59:23 +00:00
parent 31c439521f
commit 7d5dd9faf5
2 changed files with 48 additions and 19 deletions

View File

@@ -26,7 +26,6 @@ package org.alfresco.repo.site;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -104,8 +103,6 @@ public class SiteServiceImpl implements SiteService, SiteModel
private static final int GROUP_PREFIX_LENGTH = PermissionService.GROUP_PREFIX.length(); private static final int GROUP_PREFIX_LENGTH = PermissionService.GROUP_PREFIX.length();
private static final int GROUP_SITE_PREFIX_LENGTH = GROUP_SITE_PREFIX.length(); private static final int GROUP_SITE_PREFIX_LENGTH = GROUP_SITE_PREFIX.length();
private static final Set<String> ZONES;
/** Site home ref cache (Tennant aware) */ /** Site home ref cache (Tennant aware) */
private Map<String, NodeRef> siteHomeRefs = new ConcurrentHashMap<String, NodeRef>(4); private Map<String, NodeRef> siteHomeRefs = new ConcurrentHashMap<String, NodeRef>(4);
@@ -142,13 +139,6 @@ public class SiteServiceImpl implements SiteService, SiteModel
private RetryingTransactionHelper retryingTransactionHelper; private RetryingTransactionHelper retryingTransactionHelper;
private Comparator<String> roleComparator ; private Comparator<String> roleComparator ;
static
{
HashSet<String> zones = new HashSet<String>(2, 1.0f);
zones.add(AuthorityService.ZONE_APP_SHARE);
zones.add(AuthorityService.ZONE_AUTH_ALFRESCO);
ZONES = Collections.unmodifiableSet(zones);
}
/** /**
* Set the path to the location of the sites root folder. For example: * Set the path to the location of the sites root folder. For example:
@@ -328,14 +318,24 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
// Remove spaces from shortName // Remove spaces from shortName
final String shortName = passedShortName.replaceAll(" ", ""); final String shortName = passedShortName.replaceAll(" ", "");
// Check to see if we already have a site of this name /**
NodeRef existingSite = getSiteNodeRef(shortName); * Check that the site does not already exist
if (existingSite != null) */
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{ {
// Throw an exception since we have a duplicate site name public String doWork() throws Exception
throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName}); {
} // Check to see if we already have a site of this name
NodeRef existingSite = getSiteNodeRef(shortName);
if (existingSite != null)
{
// Throw an exception since we have a duplicate site name
throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName});
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
// Get the site parent node reference // Get the site parent node reference
NodeRef siteParent = getSiteParent(shortName); NodeRef siteParent = getSiteParent(shortName);
@@ -371,13 +371,13 @@ public class SiteServiceImpl implements SiteService, SiteModel
{ {
// Create the site's groups // Create the site's groups
String siteGroup = authorityService String siteGroup = authorityService
.createAuthority(AuthorityType.GROUP, getSiteGroup(shortName, false), getSiteGroup(shortName, false), ZONES); .createAuthority(AuthorityType.GROUP, getSiteGroup(shortName, false));
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE); Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
for (String permission : permissions) for (String permission : permissions)
{ {
// Create a group for the permission // Create a group for the permission
String permissionGroup = authorityService.createAuthority(AuthorityType.GROUP, getSiteRoleGroup( String permissionGroup = authorityService.createAuthority(AuthorityType.GROUP, getSiteRoleGroup(
shortName, permission, false), getSiteRoleGroup(shortName, permission, false), ZONES); shortName, permission, false));
authorityService.addAuthority(siteGroup, permissionGroup); authorityService.addAuthority(siteGroup, permissionGroup);
// Assign the group the relevant permission on the site // Assign the group the relevant permission on the site

View File

@@ -177,8 +177,37 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
{ {
// Expected // Expected
} }
} }
/**
* Test for duplicate site exception where the duplicate is a private site.
*
* @throws Exception
*/
public void testETHREEOH_2133() throws Exception
{
// Test for duplicate site error with a private site
this.siteService.createSite(TEST_SITE_PRESET, "wibble", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
authenticationComponent.setCurrentUser(USER_THREE);
try
{
this.siteService.createSite(TEST_SITE_PRESET, "wibble", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
fail("Shouldn't allow duplicate site short names.");
}
catch (AlfrescoRuntimeException exception)
{
// Expected
}
}
public void testETHREEOH_15() throws Exception public void testETHREEOH_15() throws Exception
{ {
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);