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:
Mark Rogers
2014-07-22 15:31:28 +00:00
parent d46b75c752
commit 77222c3023
3 changed files with 42 additions and 14 deletions

View File

@@ -86,6 +86,7 @@ import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.alfresco.util.SearchLanguageConversion; import org.alfresco.util.SearchLanguageConversion;
import org.alfresco.util.registry.NamedObjectRegistry; import org.alfresco.util.registry.NamedObjectRegistry;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean; 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) public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones)
{ {
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); 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_NAME, name);
props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName);
NodeRef childRef; NodeRef childRef;

View File

@@ -596,12 +596,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
checkTypeIsMutable(type); checkTypeIsMutable(type);
String name = getName(type, shortName); 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); authorityDAO.createAuthority(name, authorityDisplayName, authorityZones);
return name; return name;

View File

@@ -50,6 +50,7 @@ import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState; import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef; 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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
@@ -566,7 +567,7 @@ public class AuthorityServiceTest extends TestCase
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size()); assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
} }
public void testCreateAuth() public void testCreateAuth() throws Exception
{ {
String auth1; String auth1;
String auth2; String auth2;
@@ -649,7 +650,10 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.deleteAuthority(auth1); pubAuthorityService.deleteAuthority(auth1);
assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size()); assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size());
assertEquals(0, pubAuthorityService.getAllRootAuthorities(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. // Testing MNT-9794 fix. Creates authority 'DUPLICATEDGROUP' twice. Only one authority with such name should be created.
String dublicatedAuthorityShortName = "DUPLICATEDGROUP"; String dublicatedAuthorityShortName = "DUPLICATEDGROUP";
AuthorityType dublicatedAuthorityType = AuthorityType.GROUP; AuthorityType dublicatedAuthorityType = AuthorityType.GROUP;
@@ -658,22 +662,49 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName); pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName);
try try
{ {
commitAndStartNewTransaction();
pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName); pubAuthorityService.createAuthority(dublicatedAuthorityType, dublicatedAuthorityShortName);
tx.commit();
fail(); 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 //Only one authority should be created with duplicated name
List<String> duplicatedGroupAuthorities = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName);
assertEquals(1, duplicatedGroupAuthorities.size()); 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("GROUP_DUPLICATEDGROUP");
pubAuthorityService.deleteAuthority(pubAuthorityService.getName(AuthorityType.GROUP, differentCasesAuthorityShofrName));
commitAndStartNewTransaction();
List<String> duplicatedAuthoritiesAfterDelete = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName); List<String> duplicatedAuthoritiesAfterDelete = getAuthorityByTypeAndShortName(dublicatedAuthorityType, dublicatedAuthorityShortName);
assertEquals(0, duplicatedAuthoritiesAfterDelete.size()); 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();
} }
/** /**