mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
76565: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 76177: Merged DEV to V4.2-BUG-FIX (4.2.3) 74967 : MNT-11749 : It is possible to create groups with same name in race conditions - Disallow creation of authorities with equal names 76118 : MNT-11749 : It is possible to create groups with same name in race conditions - Remove throwing AlfrescoRuntimeException for duplicated authorities. Fix related test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77631 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -86,6 +86,7 @@ import org.alfresco.util.ParameterCheck;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.alfresco.util.SearchLanguageConversion;
|
||||
import org.alfresco.util.registry.NamedObjectRegistry;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -367,6 +368,8 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
||||
public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones)
|
||||
{
|
||||
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
/* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */
|
||||
props.put(ContentModel.PROP_NAME, DigestUtils.md5Hex(name));
|
||||
props.put(ContentModel.PROP_AUTHORITY_NAME, name);
|
||||
props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName);
|
||||
NodeRef childRef;
|
||||
|
@@ -596,12 +596,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
||||
checkTypeIsMutable(type);
|
||||
String name = getName(type, shortName);
|
||||
|
||||
//MNT-9794 fix. If authority with 'name' exists it is an error - in line with person creation
|
||||
if (authorityExists(name))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Authority '" + name + "' already exists.");
|
||||
}
|
||||
|
||||
authorityDAO.createAuthority(name, authorityDisplayName, authorityZones);
|
||||
|
||||
return name;
|
||||
|
@@ -50,6 +50,7 @@ import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -566,7 +567,7 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
|
||||
}
|
||||
|
||||
public void testCreateAuth()
|
||||
public void testCreateAuth() throws Exception
|
||||
{
|
||||
String auth1;
|
||||
String auth2;
|
||||
@@ -650,6 +651,9 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size());
|
||||
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
|
||||
|
||||
tx.rollback();
|
||||
startNewTransaction();
|
||||
|
||||
// Testing MNT-9794 fix. Creates authority 'DUPLICATEDGROUP' twice. Only one authority with such name should be created.
|
||||
String dublicatedAuthorityShortName = "DUPLICATEDGROUP";
|
||||
AuthorityType dublicatedAuthorityType = AuthorityType.GROUP;
|
||||
@@ -658,22 +662,49 @@ public class AuthorityServiceTest extends TestCase
|
||||
pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName);
|
||||
try
|
||||
{
|
||||
commitAndStartNewTransaction();
|
||||
pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName);
|
||||
|
||||
tx.commit();
|
||||
|
||||
fail();
|
||||
}
|
||||
catch(AlfrescoRuntimeException are)
|
||||
catch(DuplicateChildNodeNameException dcnne)
|
||||
{
|
||||
|
||||
tx.rollback();
|
||||
}
|
||||
|
||||
List<String> duplicatedGroupAuthorities = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName);
|
||||
startNewTransaction();
|
||||
|
||||
//Only one authority should be created with duplicated name
|
||||
List<String> duplicatedGroupAuthorities = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName);
|
||||
assertEquals(1, duplicatedGroupAuthorities.size());
|
||||
|
||||
// we should be able to create authorities with different charcases
|
||||
String differentCasesAuthorityShofrName = dublicatedAuthorityShortName.toLowerCase();
|
||||
pubAuthorityService.createAuthority(dublicatedAuthorityType, differentCasesAuthorityShofrName);
|
||||
|
||||
// delete created authorities
|
||||
pubAuthorityService.deleteAuthority("GROUP_DUPLICATEDGROUP");
|
||||
pubAuthorityService.deleteAuthority(pubAuthorityService.getName(AuthorityType.GROUP, differentCasesAuthorityShofrName));
|
||||
|
||||
commitAndStartNewTransaction();
|
||||
|
||||
List<String> duplicatedAuthoritiesAfterDelete = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName);
|
||||
assertEquals(0, duplicatedAuthoritiesAfterDelete.size());
|
||||
assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
|
||||
}
|
||||
|
||||
private void commitAndStartNewTransaction() throws Exception
|
||||
{
|
||||
tx.commit();
|
||||
startNewTransaction();
|
||||
}
|
||||
|
||||
private void startNewTransaction() throws Exception
|
||||
{
|
||||
tx = transactionService.getUserTransaction();
|
||||
tx.begin();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user