mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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:
|
||||||
@@ -329,6 +319,13 @@ 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 that the site does not already exist
|
||||||
|
*/
|
||||||
|
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
|
||||||
|
{
|
||||||
|
public String doWork() throws Exception
|
||||||
|
{
|
||||||
// Check to see if we already have a site of this name
|
// Check to see if we already have a site of this name
|
||||||
NodeRef existingSite = getSiteNodeRef(shortName);
|
NodeRef existingSite = getSiteNodeRef(shortName);
|
||||||
if (existingSite != null)
|
if (existingSite != null)
|
||||||
@@ -336,6 +333,9 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
|||||||
// Throw an exception since we have a duplicate site name
|
// Throw an exception since we have a duplicate site name
|
||||||
throw new SiteServiceException(MSG_UNABLE_TO_CREATE, new Object[]{shortName});
|
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
|
||||||
|
@@ -177,6 +177,35 @@ 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
|
||||||
|
Reference in New Issue
Block a user