From be1414ecde5eb7cc5655bf12787ba55fa1f8f146 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Fri, 25 Sep 2015 13:42:39 +0000 Subject: [PATCH] Merged 5.0.N (5.0.3) to 5.1.N (5.1.1) 112930: Merged V4.2-BUG-FIX (4.2.6) to 5.0.N (5.0.3) 112707 adavis: Merged V4.2.5 (4.2.5) to V4.2-BUG-FIX (4.2.6) 112677 dvaserin: MNT-14780 (MNT-13871): Licence Error message when in overage - Place overage buffer information into License MBean and use it in admin license ftl. 112634 adavis: MNT-13871: Merged DEV (V4.2.5-MNT-13871-LATEST) to V4.2.5 (4.2.5) 111550: Merged DEV (4.1.11) to DEV (4.2.5) MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - Merged all made changes in core alfresco projects as single commit to fresh dev branch forked from V4.1-BUG-FIX. MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - added try/finally approach to reset show delete users flag to default value., 111574: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Added V4.2.5 specific changes., 111582: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Updated the jar to correspond with the latest changes in authorised-users/4.2, 111751: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Removed unnecessary configuration., 111752: Merged DEV (V4.1.11) to DEV (V4.2.5) 111632: MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - Fixed unit tests for build plan: https://bamboo.alfresco.com/bamboo/browse/DEV-ENT414-1, 111753: Merged DEV (4.1.11) to DEV (V4.2.5) 111719: MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - Updated authorization related icons with ones provided by Mark Howarth. - Information message in Deauthorize Dialog was changed to the on provided by Mark Howarth., 111754: MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - Updated to the latest authorised-users lib., 111761: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Fix for the SchemaReferenceFileTest., 111800: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Modified the test to create a tenant in a retrying transaction to solve the DataIntegrityViolationException., 111801: Megred DEV (4.1.11) to DEV (4.2.5) 111795: MNT-13871 : Count authorised users as those who've logged in, not total # of person objects - Updated Deleted column to display text instead of tick icon. - Added name for actions column., 111813: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Updated to the latest authorisation jar to fix the Scema Reference test., 112020: MNT-14775: De-authorisation pop-up has similar title to first line of text - Remove the duplicated text from the pop-up body - Updated link to point the 4.2 documentation, 112134: MNT-14763: [UserAuth] New entries are added in the authorization table for each different username case - Update authorization jar, 112144: MNT-13871: Optimized strings in users.get.properties, 112184: MNT-14762 : [UserAuth]Users from the ALFRESCO_ADMINISTRATORS LDAP group are not pre-authorized - Updated authorized-users jar with fix for ldap administrators pre-authorization., 112196: MNT-14729 : [UserAuth] The column header for the Deauthorize and Reauthorize button should have a name - Updated name for re/de-authorize actions column., 112202: MNT-14763: [UserAuth] New entries are added in the authorization table for each different username case - Add new authorization jar to fix null errors, 112203: MNT-14779: System behaviour when system set read only due to licence exception - Force read-write transaction for LoginPost script., 112225: MNT-14763: [UserAuth] New entries are added in the authorization table for each different username case - Add new authorization jar after unit test fixing., 112226: MNT-14740 : [UserAuth] The message for the failed re authorization is not displayed onIE - Code for reloading page was wrapped with YAHOO.lang.later() function., 112247: MNT-14747 : [UserAuth]The Autorization State isn't change when the user logs via FTP. - Updated authorization jar with fix for kerberos unit test., 112259: MNT-14776: Heading banner text when using all allowed authorised users. - Changed the message. - Updated the authorised-users jar., 112269: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Wrap methods that uses 'authenticationComponent.setCurrentUser' into RetryingTransaction for retrying on DataIntegrityViolationException., 112285: MNT-14747 : [UserAuth]The Autorization State isn't change when the user logs via FTP. - Updated version for authorized-users jar., 112388: MNT-14809: [UserAuth] On a cluster setup after running the hourly job only one node goes into R/O mode - Updated the authorised-users.jar, 112439: MNT-14815 : Wrong documentation link used in the deauthorize message window - Corrected link to documentation., 112445: MNT-14818 : [UserAuth] Missing quotation mark in the user reauthorization window message - Corrected message for reauthorization dialog., 112450: MNT-14802: [UserAuth] License warning message displayed for all the users - Updated the authorised-users jar., 112454: MNT-14780: Licence Error message when in overage - Make license warn messages on admin console the same as banner warn messages., 112471: MNT-14773 : Sort state not persisted after authorisation action - Sorting/paging state is now persists in sessionStorage., 112478: MNT-14773 : Sort state not persisted after authorisation action - Corrected previous fix., 112483: MNT-14814: [UserAuth] System goes into R/O mode after running the hourly job - Updated the authorised-users jar to the latest version., 112512: MNT-14833: [UserAuth] User cannot login on both nodes (cluster env.) - Update authorization jar., 112556: MNT-14787: [UserAuth] Login via NFS works when the license limit exceed - Modified the exception handling of setCurrentUser method. Now all the exceptions are rethrown., 112570: MNT-14838: Correct the Max Users string in the Admin Console License Screen - Corrected the string, remove the incorrect translations from the bundle., 112572: REVERSE MERGED <> 112471 : MNT-14773 : Sort state not persisted after authorisation action - Sorting/paging state is now persists in sessionStorage. 112478 : MNT-14773 : Sort state not persisted after authorisation action - Corrected previous fix. , 112610: MNT-14837 : Report license overage to the log files on authorization/deauthorization of users - Updated users authorization jar file., 112627: MNT-14839: [UserAuth]Alfresco goes in read -only after reauthorize a user from LDAP ALFESCO_ADMINISTRATORS group - Updated the authorised-users jar to the latest version. Merged DEV (V5.0.2-MNT-13871) to 5.0.N (5.0.3) 111954: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Removed context reference to authorization., 112003: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Added copying of sources and configuration from authorised-users to the output directory during build., 112014: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Modified the build configuration to unpack the resources to the test folders., 112027: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Added unpacking of authorisation resources to repoitory-crypto project., 112067: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Removed unpacking of resources, changed the context imports to point to authorization., 112952: Merged DEV (V5.0.2-MNT-13871) to 5.0.N (5.0.3) 111887: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Corrected the authorised-users version to correspond to 5.0., 113060: Merged V4.2-BUG-FIX (4.2.6) to 5.0.N (5.0.3) 113059 adavis: Merged V4.2.5 (4.2.5) to V4.2-BUG-FIX (4.2.6) 113058 adavis: MNT-13871: Count authorised users as those who've logged in, not total # of person objects - Version dependency for alfresco-authorised-users moved to top level pom git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@113101 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/application-context-core.xml | 3 + .../messages/system-messages.properties | 1 + config/alfresco/minimal-context.xml | 2 +- config/alfresco/model/systemModel.xml | 4 + .../auth/nfs/AlfrescoRpcAuthenticator.java | 1 + .../org/alfresco/repo/jscript/People.java | 52 +- .../security/person/PersonServiceImpl.java | 2 +- .../repo/site/SiteServiceImplTest.java | 1247 ++++++++++------- .../repo/tenant/MultiTServiceImplTest.java | 320 +++-- .../repo/usage/RepoUsageComponentTest.java | 16 +- 10 files changed, 1021 insertions(+), 627 deletions(-) diff --git a/config/alfresco/application-context-core.xml b/config/alfresco/application-context-core.xml index ec272e3af7..fc0670ff70 100644 --- a/config/alfresco/application-context-core.xml +++ b/config/alfresco/application-context-core.xml @@ -49,4 +49,7 @@ + + + diff --git a/config/alfresco/messages/system-messages.properties b/config/alfresco/messages/system-messages.properties index a7bf645277..dd3ccedee9 100644 --- a/config/alfresco/messages/system-messages.properties +++ b/config/alfresco/messages/system-messages.properties @@ -84,6 +84,7 @@ system.usage.warn.limit_documents_approached=The allowable content limit of {0} system.usage.warn.limit_documents_reached=The allowable content limit of {0} has been reached. There are {1} content objects in the system. system.usage.err.limit_users_exceeded=The allowable user limit of {0} as per your license agreement has been exceeded. There are currently {1} users in the system. Please contact your Alfresco sales representative to purchase additional user licenses. system.usage.err.limit_users_exceeded_verbose=The allowable user limit of {0} as per your license agreement has been exceeded. Users added: {1}. Please contact your Alfresco sales representative to purchase additional user licenses. +system.usage.warn.limit_users_overage=The allowable user limit of {0} for your license agreement has been reached. There are {1} users in the system, {2} are allowed. Please contact your Alfresco sales representative to purchase additional user licenses. system.usage.err.limit_documents_exceeded=The allowable content limit of {0} has been exceeded. There are currently {1} content objects in the system. system.usage.err.limit_license_expiring=The Alfresco license will expire in {0} days. diff --git a/config/alfresco/minimal-context.xml b/config/alfresco/minimal-context.xml index 8c9e619da8..0736acd42c 100644 --- a/config/alfresco/minimal-context.xml +++ b/config/alfresco/minimal-context.xml @@ -26,7 +26,7 @@ Import all modules and related components. --> - + diff --git a/config/alfresco/model/systemModel.xml b/config/alfresco/model/systemModel.xml index 2bceb3bbd1..569fb29665 100644 --- a/config/alfresco/model/systemModel.xml +++ b/config/alfresco/model/systemModel.xml @@ -77,6 +77,10 @@ d:content false + + d:content + false + diff --git a/source/java/org/alfresco/filesys/auth/nfs/AlfrescoRpcAuthenticator.java b/source/java/org/alfresco/filesys/auth/nfs/AlfrescoRpcAuthenticator.java index 1e5901a487..f7e3517b96 100644 --- a/source/java/org/alfresco/filesys/auth/nfs/AlfrescoRpcAuthenticator.java +++ b/source/java/org/alfresco/filesys/auth/nfs/AlfrescoRpcAuthenticator.java @@ -372,6 +372,7 @@ public class AlfrescoRpcAuthenticator implements RpcAuthenticator, InitializingB { if ( logger.isErrorEnabled()) logger.error( "Error in RPC authenticator setting current user", ex); + throw ex; } } diff --git a/source/java/org/alfresco/repo/jscript/People.java b/source/java/org/alfresco/repo/jscript/People.java index 27c4eba40e..c1f667da9a 100644 --- a/source/java/org/alfresco/repo/jscript/People.java +++ b/source/java/org/alfresco/repo/jscript/People.java @@ -165,11 +165,11 @@ public class People extends BaseScopableProcessorExtension implements Initializi /** * Set the service registry * - * @param serviceRegistry the service registry + * @param serviceRegistry the service registry */ public void setServiceRegistry(ServiceRegistry serviceRegistry) { - this.services = serviceRegistry; + this.services = serviceRegistry; } /** @@ -311,8 +311,8 @@ public class People extends BaseScopableProcessorExtension implements Initializi public ScriptNode createPerson(String userName, String firstName, String lastName, String emailAddress, String password, boolean setAccountEnabled, boolean notifyByEmail) { - ParameterCheck.mandatory("firstName", firstName); - ParameterCheck.mandatory("emailAddress", emailAddress); + ParameterCheck.mandatory("firstName", firstName); + ParameterCheck.mandatory("emailAddress", emailAddress); ScriptNode person = null; @@ -321,13 +321,13 @@ public class People extends BaseScopableProcessorExtension implements Initializi { for (int i=0; i < numRetries; i++) { - userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i); - - // create person if user name does not already exist - if (!personService.personExists(userName)) - { - break; - } + userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i); + + // create person if user name does not already exist + if (!personService.personExists(userName)) + { + break; + } } } @@ -344,19 +344,19 @@ public class People extends BaseScopableProcessorExtension implements Initializi person = createPerson(userName, firstName, lastName, emailAddress); - if (person != null && password != null) - { - // create account for person with the userName and password - authenticationService.createAuthentication(userName, password.toCharArray()); - authenticationService.setAuthenticationEnabled(userName, setAccountEnabled); - - person.save(); - - if(notifyByEmail) - { - personService.notifyPerson(userName, password); - } - } + if (person != null && password != null) + { + // create account for person with the userName and password + authenticationService.createAuthentication(userName, password.toCharArray()); + authenticationService.setAuthenticationEnabled(userName, setAccountEnabled); + + person.save(); + + if(notifyByEmail) + { + personService.notifyPerson(userName, password); + } + } } return person; @@ -914,8 +914,8 @@ public class People extends BaseScopableProcessorExtension implements Initializi if ("fullName".equalsIgnoreCase(sortBy)) { - String firstName = nodeService.getProperty(nodeRef, ContentModel.PROP_FIRSTNAME).toString(); - String lastName = nodeService.getProperty(nodeRef, ContentModel.PROP_LASTNAME).toString(); + String firstName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_FIRSTNAME); + String lastName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_LASTNAME); String fullName = firstName; if (lastName != null && lastName.length() > 0) { diff --git a/source/java/org/alfresco/repo/security/person/PersonServiceImpl.java b/source/java/org/alfresco/repo/security/person/PersonServiceImpl.java index 61fc43f30f..416d6e7f73 100644 --- a/source/java/org/alfresco/repo/security/person/PersonServiceImpl.java +++ b/source/java/org/alfresco/repo/security/person/PersonServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2015 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/test-java/org/alfresco/repo/site/SiteServiceImplTest.java b/source/test-java/org/alfresco/repo/site/SiteServiceImplTest.java index e5c29e20eb..c1da2796b6 100644 --- a/source/test-java/org/alfresco/repo/site/SiteServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/site/SiteServiceImplTest.java @@ -50,21 +50,26 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authority.UnknownAuthorityException; import org.alfresco.repo.security.person.UserNameMatcherImpl; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.TypeDefinition; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.CopyService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.ScriptLocation; import org.alfresco.service.cmr.repository.ScriptService; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.site.SiteInfo; @@ -74,6 +79,7 @@ import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.BaseAlfrescoSpringTest; @@ -93,6 +99,8 @@ import static org.mockito.Mockito.when; @Category(BaseSpringTestsCategory.class) public class SiteServiceImplTest extends BaseAlfrescoSpringTest { + public static final StoreRef SITE_STORE = new StoreRef("workspace://SpacesStore"); + private static final String TEST_SITE_PRESET = "testSitePreset"; private static final String TEST_SITE_PRESET_2 = "testSitePreset2"; private static final String TEST_TITLE = "TitleTest This is my title"; @@ -109,6 +117,8 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest private static final String GROUP_ONE_DISPLAY = "DisplayOfGrpOne-SiteServiceImplTest"; private static final String GROUP_TWO_DISPLAY = "DisplayOfGrpTwo-SiteServiceImplTest"; + private static boolean IS_FIRST_SETUP = true; + private CopyService copyService; private ScriptService scriptService; private NodeService nodeService; @@ -141,50 +151,90 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest @SuppressWarnings("deprecation") protected void onSetUpInTransaction() throws Exception { - super.onSetUpInTransaction(); - - // Get the required services - this.copyService = (CopyService)this.applicationContext.getBean("CopyService"); - this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService"); - this.nodeService = (NodeService)this.applicationContext.getBean("NodeService"); - this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); - this.taggingService = (TaggingService)this.applicationContext.getBean("TaggingService"); - this.personService = (PersonService)this.applicationContext.getBean("PersonService"); - this.authorityService = (AuthorityService)this.applicationContext.getBean("AuthorityService"); - this.fileFolderService = (FileFolderService)this.applicationContext.getBean("FileFolderService"); - this.nodeArchiveService = (NodeArchiveService)this.applicationContext.getBean("nodeArchiveService"); - this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService"); - this.dictionaryService = (DictionaryService)this.applicationContext.getBean("DictionaryService"); - this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService"); - this.siteService = (SiteService)this.applicationContext.getBean("SiteService"); // Big 'S' - this.siteServiceImpl = (SiteServiceImpl) applicationContext.getBean("siteService"); // Small 's' - this.sysAdminParams = (SysAdminParams)this.applicationContext.getBean("sysAdminParams"); - this.userNameMatcherImpl = (UserNameMatcherImpl)this.applicationContext.getBean("userNameMatcher"); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { - // Create the test users - createUser(USER_ONE, "UserOne"); - createUser(USER_TWO, "UserTwo"); - createUser(USER_THREE, "UsRthree"); - createUser(USER_FOUR, "UsRFoUr"); - - // Create the test groups - this.groupOne = this.authorityService.createAuthority(AuthorityType.GROUP, GROUP_ONE, GROUP_ONE_DISPLAY, null); - this.authorityService.addAuthority(this.groupOne, USER_TWO); - - this.groupTwo = this.authorityService.createAuthority(AuthorityType.GROUP, GROUP_TWO, GROUP_TWO_DISPLAY, null); - this.authorityService.addAuthority(this.groupTwo, USER_TWO); - this.authorityService.addAuthority(this.groupTwo, USER_THREE); - - this.groupThree = this.authorityService.createAuthority(AuthorityType.GROUP, GROUP_THREE); - this.authorityService.addAuthority(this.groupThree, USER_TWO); - this.authorityService.addAuthority(this.groupThree, USER_THREE); - - this.groupFour = this.authorityService.createAuthority(AuthorityType.GROUP, GROUP_FOUR); - this.authorityService.addAuthority(this.groupThree, this.groupFour); - this.authorityService.addAuthority(this.groupFour, USER_FOUR); + @Override + public Object execute() throws Throwable + { + // from super.onSetUpInTransaction(); - // Set the current authentication - this.authenticationComponent.setCurrentUser(USER_ONE); + // Get a reference to the node service + nodeService = (NodeService) applicationContext.getBean("nodeService"); + contentService = (ContentService) applicationContext.getBean("contentService"); + authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService"); + actionService = (ActionService) applicationContext.getBean("actionService"); + transactionService = (TransactionService) applicationContext.getBean("transactionComponent"); + + // Authenticate as the system user + authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); + authenticationComponent.setSystemUserAsCurrentUser(); + + // Create the store and get the root node + storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); + rootNodeRef = nodeService.getRootNode(storeRef); + + // Get the required services + copyService = (CopyService) applicationContext.getBean("CopyService"); + scriptService = (ScriptService) applicationContext.getBean("ScriptService"); + nodeService = (NodeService) applicationContext.getBean("NodeService"); + authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); + taggingService = (TaggingService) applicationContext.getBean("TaggingService"); + personService = (PersonService) applicationContext.getBean("PersonService"); + authorityService = (AuthorityService) applicationContext.getBean("AuthorityService"); + fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService"); + nodeArchiveService = (NodeArchiveService) applicationContext.getBean("nodeArchiveService"); + permissionService = (PermissionService) applicationContext.getBean("PermissionService"); + dictionaryService = (DictionaryService) applicationContext.getBean("DictionaryService"); + namespaceService = (NamespaceService) applicationContext.getBean("namespaceService"); + siteService = (SiteService) applicationContext.getBean("SiteService"); // Big 'S' + siteServiceImpl = (SiteServiceImpl) applicationContext.getBean("siteService"); // Small 's' + sysAdminParams = (SysAdminParams) applicationContext.getBean("sysAdminParams"); + userNameMatcherImpl = (UserNameMatcherImpl) applicationContext.getBean("userNameMatcher"); + + if (IS_FIRST_SETUP) + { + // Create the test users + createUser(USER_ONE, "UserOne"); + createUser(USER_TWO, "UserTwo"); + createUser(USER_THREE, "UsRthree"); + createUser(USER_FOUR, "UsRFoUr"); + + // Create the test groups + groupOne = authorityService.createAuthority(AuthorityType.GROUP, GROUP_ONE, GROUP_ONE_DISPLAY, null); + authorityService.addAuthority(groupOne, USER_TWO); + + groupTwo = authorityService.createAuthority(AuthorityType.GROUP, GROUP_TWO, GROUP_TWO_DISPLAY, null); + authorityService.addAuthority(groupTwo, USER_TWO); + authorityService.addAuthority(groupTwo, USER_THREE); + + groupThree = authorityService.createAuthority(AuthorityType.GROUP, GROUP_THREE); + authorityService.addAuthority(groupThree, USER_TWO); + authorityService.addAuthority(groupThree, USER_THREE); + + groupFour = authorityService.createAuthority(AuthorityType.GROUP, GROUP_FOUR); + authorityService.addAuthority(groupThree, groupFour); + authorityService.addAuthority(groupFour, USER_FOUR); + + IS_FIRST_SETUP = false; + } + else + { + groupOne = authorityService.getName(AuthorityType.GROUP, GROUP_ONE); + groupTwo = authorityService.getName(AuthorityType.GROUP, GROUP_TWO); + groupThree = authorityService.getName(AuthorityType.GROUP, GROUP_THREE); + groupFour = authorityService.getName(AuthorityType.GROUP, GROUP_FOUR); + } + // Set the current authentication + authenticationComponent.setCurrentUser(USER_ONE); + + return null; + } + }; + endTransaction(); + transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent"); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } @Override @@ -281,18 +331,36 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest public void testHasSite() throws Exception { - this.authenticationComponent.setCurrentUser(USER_ONE); - // Create a Public site - createSite("publicsite1", "doclib", SiteVisibility.PUBLIC); - // Create a Private site - createSite("privatesite1", "doclib", SiteVisibility.PRIVATE); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + authenticationComponent.setCurrentUser(USER_ONE); + // Create a Public site + createSite("publicsite1", "doclib", SiteVisibility.PUBLIC); + // Create a Private site + createSite("privatesite1", "doclib", SiteVisibility.PRIVATE); + + // ensure USER_TWO has correct visibility - can "get" public site but not a private one, can "has" exist check both + authenticationComponent.setCurrentUser(USER_TWO); + assertTrue(siteService.getSite("publicsite1") != null); + assertTrue(siteService.getSite("privatesite1") == null); // should not be visible to get() + assertTrue(siteService.hasSite("publicsite1")); + assertTrue(siteService.hasSite("privatesite1")); // should be visible to has() exist check + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("publicsite1"); + siteService.deleteSite("privatesite1"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); - // ensure USER_TWO has correct visibility - can "get" public site but not a private one, can "has" exist check both - this.authenticationComponent.setCurrentUser(USER_TWO); - assertTrue(this.siteService.getSite("publicsite1") != null); - assertTrue(this.siteService.getSite("privatesite1") == null); // should not be visible to get() - assertTrue(this.siteService.hasSite("publicsite1")); - assertTrue(this.siteService.hasSite("privatesite1")); // should be visible to has() exist check } /** @@ -302,21 +370,38 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest */ 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 + RetryingTransactionCallback work = new RetryingTransactionCallback() { - 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 - } + + @Override + public Object execute() throws Throwable + { + // Test for duplicate site error with a private site + + siteService.createSite(TEST_SITE_PRESET, "wibble", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + authenticationComponent.setCurrentUser(USER_THREE); + + try + { + siteService.createSite(TEST_SITE_PRESET, "wibble", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + fail("Shouldn't allow duplicate site short names."); + } + catch (AlfrescoRuntimeException exception) + { + // Expected + } + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("wibble"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); + } /** @@ -421,36 +506,56 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest */ public void testETHREEOH_15() throws Exception { - SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - - authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - this.siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_MANAGER); - - authenticationComponent.setCurrentUser(USER_TWO); - this.siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR); - this.siteService.removeMembership(siteInfo.getShortName(), USER_THREE); - - authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - this.siteService.removeMembership(siteInfo.getShortName(), USER_TWO); - - authenticationComponent.setSystemUserAsCurrentUser(); - this.siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR); - - authenticationComponent.setCurrentUser(USER_THREE); - try + RetryingTransactionCallback work = new RetryingTransactionCallback() { - this.siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_CONTRIBUTOR); - fail("Shouldn't be able to do this cos you don't have permissions"); - } - catch (Exception exception) {} - try - { - this.siteService.removeMembership(siteInfo.getShortName(), USER_ONE); - fail("Shouldn't be able to do this cos you don't have permissions"); - } - catch (Exception exception) {} - this.siteService.removeMembership(siteInfo.getShortName(), USER_THREE); + + @Override + public Object execute() throws Throwable + { + SiteInfo siteInfo = siteService.createSite(TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "mySiteTest", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + + authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_MANAGER); + + authenticationComponent.setCurrentUser(USER_TWO); + siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR); + siteService.removeMembership(siteInfo.getShortName(), USER_THREE); + + authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + siteService.removeMembership(siteInfo.getShortName(), USER_TWO); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR); + + authenticationComponent.setCurrentUser(USER_THREE); + try + { + siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_CONTRIBUTOR); + fail("Shouldn't be able to do this cos you don't have permissions"); + } + catch (Exception exception) + { + } + try + { + siteService.removeMembership(siteInfo.getShortName(), USER_ONE); + fail("Shouldn't be able to do this cos you don't have permissions"); + } + catch (Exception exception) + { + } + siteService.removeMembership(siteInfo.getShortName(), USER_THREE); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("mySiteTest"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } private void checkSiteInfo(SiteInfo siteInfo, @@ -714,34 +819,47 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest public void testMNT_13710() throws Exception { - String siteName = "test" + System.currentTimeMillis(); - - List roleList = new ArrayList(); - roleList.add("test_customrole"); - roleList.add("testCustomrole"); - - try + RetryingTransactionCallback work = new RetryingTransactionCallback() { - authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - - SiteInfo siteInfo = this.siteService.createSite(siteName, siteName, siteName, siteName, SiteVisibility.PUBLIC); - for(String role : roleList) + @Override + public Object execute() throws Throwable { - this.siteService.setMembership(siteInfo.getShortName(), USER_ONE, role); - - List list = this.siteServiceImpl.getMembersRoles(siteName, USER_ONE); - - assertTrue(list.contains(role)); + String siteName = "test" + System.currentTimeMillis(); + + List roleList = new ArrayList(); + roleList.add("test_customrole"); + roleList.add("testCustomrole"); + + try + { + authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + + SiteInfo siteInfo = siteService.createSite(siteName, siteName, siteName, siteName, SiteVisibility.PUBLIC); + + for (String role : roleList) + { + siteService.setMembership(siteInfo.getShortName(), USER_ONE, role); + + List list = siteServiceImpl.getMembersRoles(siteName, USER_ONE); + + assertTrue(list.contains(role)); + } + } + finally + { + if (siteService.getSite(siteName) != null) + { + siteService.deleteSite(siteName); + } + } + + return null; } - } - finally - { - if (siteService.getSite(siteName) != null) - { - siteService.deleteSite(siteName); - } - } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } /** @@ -1108,96 +1226,119 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest public void testIsPublic() { - List sites = this.siteService.listSites(null, null); - assertNotNull("initial sites list was null.", sites); - final int preexistingSiteCount = sites.size(); - - // Create a couple of sites as user one - this.siteService.createSite(TEST_SITE_PRESET, "isPublicTrue", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - this.siteService.createSite(TEST_SITE_PRESET, "isPublicFalse", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - - // Get the sites as user one - sites = this.siteService.listSites(null, null); - assertNotNull(sites); - assertEquals(preexistingSiteCount + 2, sites.size()); - - // Now get the sites as user two - this.authenticationComponent.setCurrentUser(USER_TWO); - sites = this.siteService.listSites(null, null); - assertNotNull(sites); - assertEquals(preexistingSiteCount + 1, sites.size()); - SiteInfo userTwoSite = siteService.getSite("isPublicTrue"); - checkSiteInfo(userTwoSite, TEST_SITE_PRESET, "isPublicTrue", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - - // Make user 2 a member of the site - //TestWithUserUtils.authenticateUser(USER_ONE, "PWD", this.authenticationService, this.authenticationComponent); - this.authenticationComponent.setCurrentUser(USER_ONE); - this.siteService.setMembership("isPublicFalse", USER_TWO, SiteModel.SITE_CONSUMER); - - // Now get the sites as user two - this.authenticationComponent.setCurrentUser(USER_TWO); - sites = this.siteService.listSites(null, null); - assertNotNull(sites); - assertEquals(preexistingSiteCount + 2, sites.size()); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + List sites = siteService.listSites(null, null); + assertNotNull("initial sites list was null.", sites); + final int preexistingSiteCount = sites.size(); + + // Create a couple of sites as user one + siteService.createSite(TEST_SITE_PRESET, "isPublicTrue", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + siteService.createSite(TEST_SITE_PRESET, "isPublicFalse", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + // Get the sites as user one + sites = siteService.listSites(null, null); + assertNotNull(sites); + assertEquals(preexistingSiteCount + 2, sites.size()); + + // Now get the sites as user two + authenticationComponent.setCurrentUser(USER_TWO); + sites = siteService.listSites(null, null); + assertNotNull(sites); + assertEquals(preexistingSiteCount + 1, sites.size()); + SiteInfo userTwoSite = siteService.getSite("isPublicTrue"); + checkSiteInfo(userTwoSite, TEST_SITE_PRESET, "isPublicTrue", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + + // Make user 2 a member of the site + // TestWithUserUtils.authenticateUser(USER_ONE, "PWD", this.authenticationService, this.authenticationComponent); + authenticationComponent.setCurrentUser(USER_ONE); + siteService.setMembership("isPublicFalse", USER_TWO, SiteModel.SITE_CONSUMER); + + // Now get the sites as user two + authenticationComponent.setCurrentUser(USER_TWO); + sites = siteService.listSites(null, null); + assertNotNull(sites); + assertEquals(preexistingSiteCount + 2, sites.size()); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("isPublicTrue"); + siteService.deleteSite("isPublicFalse"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } public void testMembership() { - // Create a site as user one - this.siteService.createSite(TEST_SITE_PRESET, "testMembership", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - - // Get the members of the site and check that user one is a manager - Map members = this.siteService.listMembers("testMembership", null, null, 0); - assertNotNull(members); - assertEquals(1, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - - // Add user two as a consumer and user three as a collaborator - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_CONSUMER); - this.siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_COLLABORATOR); - - // Get the members of the site - members = this.siteService.listMembers("testMembership", null, null, 0); - assertNotNull(members); - assertEquals(3, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - assertTrue(members.containsKey(USER_TWO)); - assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_TWO)); - assertTrue(members.containsKey(USER_THREE)); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); - - // Get only the site managers - members = this.siteService.listMembers("testMembership", null, SiteModel.SITE_MANAGER, 0); - assertNotNull(members); - assertEquals(1, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - - // Get only user two - members = this.siteService.listMembers("testMembership", USER_TWO, null, 0); - assertNotNull(members); - assertEquals(1, members.size()); - assertTrue(members.containsKey(USER_TWO)); - assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_TWO)); - - // Change the membership of user two - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); - - // Check the members of the site - members = this.siteService.listMembers("testMembership", null, null, 0); - assertNotNull(members); - assertEquals(3, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - assertTrue(members.containsKey(USER_TWO)); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_TWO)); - assertTrue(members.containsKey(USER_THREE)); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + // Create a site as user one + siteService.createSite(TEST_SITE_PRESET, "testMembership", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + // Get the members of the site and check that user one is a manager + Map members = siteService.listMembers("testMembership", null, null, 0); + assertNotNull(members); + assertEquals(1, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + + // Add user two as a consumer and user three as a collaborator + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_CONSUMER); + siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_COLLABORATOR); + + // Get the members of the site + members = siteService.listMembers("testMembership", null, null, 0); + assertNotNull(members); + assertEquals(3, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + assertTrue(members.containsKey(USER_TWO)); + assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_TWO)); + assertTrue(members.containsKey(USER_THREE)); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); + + // Get only the site managers + members = siteService.listMembers("testMembership", null, SiteModel.SITE_MANAGER, 0); + assertNotNull(members); + assertEquals(1, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + + // Get only user two + members = siteService.listMembers("testMembership", USER_TWO, null, 0); + assertNotNull(members); + assertEquals(1, members.size()); + assertTrue(members.containsKey(USER_TWO)); + assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_TWO)); + + // Change the membership of user two + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); + + // Check the members of the site + members = siteService.listMembers("testMembership", null, null, 0); + assertNotNull(members); + assertEquals(3, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + assertTrue(members.containsKey(USER_TWO)); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_TWO)); + assertTrue(members.containsKey(USER_THREE)); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); //Check other listMember calls - this.siteService.listMembers("testMembership", null, null, false, new SiteService.SiteMembersCallback(){ + siteService.listMembers("testMembership", null, null, false, new SiteService.SiteMembersCallback(){ List USERS = Arrays.asList(USER_ONE, USER_TWO, USER_THREE); int userCount = 0; @@ -1217,92 +1358,102 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest }); - - // Remove user two's membership - this.siteService.removeMembership("testMembership", USER_TWO); - - // Check the members of the site - members = this.siteService.listMembers("testMembership", null, null, 0); - assertNotNull(members); - assertEquals(2, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - assertTrue(members.containsKey(USER_THREE)); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); - - // Ensure that size limiting works correctly - members = this.siteService.listMembers("testMembership", null, null, 1); - assertNotNull(members); - assertEquals(1, members.size()); - - members = this.siteService.listMembers("testMembership", null, null, 2); - assertNotNull(members); - assertEquals(2, members.size()); - assertTrue(members.containsKey(USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - assertTrue(members.containsKey(USER_THREE)); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); - - // Check that a non-manager and non-member cannot edit the memberships - this.authenticationComponent.setCurrentUser(USER_TWO); - try - { - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); - fail("A non member shouldnt be able to set memberships"); - } - catch (AlfrescoRuntimeException e) - { - // As expected - } - try - { - this.siteService.removeMembership("testMembership", USER_THREE); - fail("A non member shouldnt be able to remove a membership"); - } - catch (AlfrescoRuntimeException e) - { - // As expected - } - this.authenticationComponent.setCurrentUser(USER_THREE); - try - { - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); - fail("A member who isn't a manager shouldnt be able to set memberships"); - } - catch (AlfrescoRuntimeException e) - { - // As expected - } - this.siteService.removeMembership("testMembership", USER_THREE); - - this.authenticationComponent.setCurrentUser(USER_ONE); - // Try and change the permissions of the only site manager - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_MANAGER); - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); - try - { - this.siteService.setMembership("testMembership", USER_ONE, SiteModel.SITE_COLLABORATOR); - fail("You can not change the role of the last site memnager"); - } - catch (AlfrescoRuntimeException exception) - { - // Expected - //exception.printStackTrace(); - } - - // Try and remove the only site manager and should get a failure - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_MANAGER); - this.siteService.removeMembership("testMembership", USER_ONE); - try - { - this.siteService.removeMembership("testMembership", USER_TWO); - fail("You can not remove the last site memnager from a site"); - } - catch (AlfrescoRuntimeException exception) - { - // Expected - //exception.printStackTrace(); - } + + // Remove user two's membership + siteService.removeMembership("testMembership", USER_TWO); + + // Check the members of the site + members = siteService.listMembers("testMembership", null, null, 0); + assertNotNull(members); + assertEquals(2, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + assertTrue(members.containsKey(USER_THREE)); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); + + // Ensure that size limiting works correctly + members = siteService.listMembers("testMembership", null, null, 1); + assertNotNull(members); + assertEquals(1, members.size()); + + members = siteService.listMembers("testMembership", null, null, 2); + assertNotNull(members); + assertEquals(2, members.size()); + assertTrue(members.containsKey(USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); + assertTrue(members.containsKey(USER_THREE)); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); + + // Check that a non-manager and non-member cannot edit the memberships + authenticationComponent.setCurrentUser(USER_TWO); + try + { + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); + fail("A non member shouldnt be able to set memberships"); + } + catch (AlfrescoRuntimeException e) + { + // As expected + } + try + { + siteService.removeMembership("testMembership", USER_THREE); + fail("A non member shouldnt be able to remove a membership"); + } + catch (AlfrescoRuntimeException e) + { + // As expected + } + authenticationComponent.setCurrentUser(USER_THREE); + try + { + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); + fail("A member who isn't a manager shouldnt be able to set memberships"); + } + catch (AlfrescoRuntimeException e) + { + // As expected + } + siteService.removeMembership("testMembership", USER_THREE); + + authenticationComponent.setCurrentUser(USER_ONE); + // Try and change the permissions of the only site manager + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_MANAGER); + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); + try + { + siteService.setMembership("testMembership", USER_ONE, SiteModel.SITE_COLLABORATOR); + fail("You can not change the role of the last site memnager"); + } + catch (AlfrescoRuntimeException exception) + { + // Expected + // exception.printStackTrace(); + } + + // Try and remove the only site manager and should get a failure + siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_MANAGER); + siteService.removeMembership("testMembership", USER_ONE); + try + { + siteService.removeMembership("testMembership", USER_TWO); + fail("You can not remove the last site memnager from a site"); + } + catch (AlfrescoRuntimeException exception) + { + // Expected + // exception.printStackTrace(); + } + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("testMembership"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } public void testDefaults() @@ -1315,114 +1466,148 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest public void testListSiteMemberships() { - String siteName1 = "testMembership1"; - String siteName2 = "testMembership2"; - String siteName3 = "testMembership3"; - // Create a site as user one - this.siteService.createSite(TEST_SITE_PRESET, siteName1, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - - // Get the members of the site and check that user one is a manager - List members = this.siteService.listSiteMemberships(USER_ONE, 0); - assertNotNull(members); - assertEquals(1, members.size()); - assertEquals(USER_ONE, members.get(0).getPersonId()); - assertEquals(SiteModel.SITE_MANAGER, members.get(0).getRole()); - - PagingResults siteM = this.siteService.listSitesPaged(USER_ONE, null, new PagingRequest(1000)); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + String siteName1 = "testMembership1"; + String siteName2 = "testMembership2"; + String siteName3 = "testMembership3"; + // Create a site as user one + siteService.createSite(TEST_SITE_PRESET, siteName1, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + // Get the members of the site and check that user one is a manager + List members = siteService.listSiteMemberships(USER_ONE, 0); + assertNotNull(members); + assertEquals(1, members.size()); + assertEquals(USER_ONE, members.get(0).getPersonId()); + assertEquals(SiteModel.SITE_MANAGER, members.get(0).getRole()); + + PagingResults siteM = siteService.listSitesPaged(USER_ONE, null, new PagingRequest(1000)); assertNotNull(siteM); assertFalse(siteM.hasMoreItems()); - // Create a site as user two and add user one - this.authenticationComponent.setCurrentUser(USER_TWO); - this.siteService.createSite(TEST_SITE_PRESET, siteName2, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - this.siteService.setMembership("testMembership2", USER_ONE, SiteModel.SITE_CONSUMER); - - // Create a site as user three and add user one - this.authenticationComponent.setCurrentUser(USER_THREE); - this.siteService.createSite(TEST_SITE_PRESET, siteName3, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - this.siteService.setMembership("testMembership3", USER_ONE, SiteModel.SITE_COLLABORATOR); - - this.authenticationComponent.setCurrentUser(USER_ONE); - members = this.siteService.listSiteMemberships(USER_ONE, 0); - assertNotNull(members); - assertEquals(3, members.size()); - assertEquals(USER_ONE, members.get(0).getPersonId()); - assertEquals(SiteModel.SITE_MANAGER, members.get(0).getRole()); - assertEquals(siteName1, members.get(0).getSiteInfo().getShortName()); - assertEquals(USER_ONE, members.get(1).getPersonId()); - assertEquals(SiteModel.SITE_CONSUMER, members.get(1).getRole()); - assertEquals(siteName2, members.get(1).getSiteInfo().getShortName()); - assertEquals(USER_ONE, members.get(2).getPersonId()); - assertEquals(SiteModel.SITE_COLLABORATOR, members.get(2).getRole()); - assertEquals(siteName3, members.get(2).getSiteInfo().getShortName()); + // Create a site as user two and add user one + authenticationComponent.setCurrentUser(USER_TWO); + siteService.createSite(TEST_SITE_PRESET, siteName2, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + siteService.setMembership("testMembership2", USER_ONE, SiteModel.SITE_CONSUMER); + + // Create a site as user three and add user one + authenticationComponent.setCurrentUser(USER_THREE); + siteService.createSite(TEST_SITE_PRESET, siteName3, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + siteService.setMembership("testMembership3", USER_ONE, SiteModel.SITE_COLLABORATOR); + + authenticationComponent.setCurrentUser(USER_ONE); + members = siteService.listSiteMemberships(USER_ONE, 0); + assertNotNull(members); + assertEquals(3, members.size()); + assertEquals(USER_ONE, members.get(0).getPersonId()); + assertEquals(SiteModel.SITE_MANAGER, members.get(0).getRole()); + assertEquals(siteName1, members.get(0).getSiteInfo().getShortName()); + assertEquals(USER_ONE, members.get(1).getPersonId()); + assertEquals(SiteModel.SITE_CONSUMER, members.get(1).getRole()); + assertEquals(siteName2, members.get(1).getSiteInfo().getShortName()); + assertEquals(USER_ONE, members.get(2).getPersonId()); + assertEquals(SiteModel.SITE_COLLABORATOR, members.get(2).getRole()); + assertEquals(siteName3, members.get(2).getSiteInfo().getShortName()); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite(siteName1); + siteService.deleteSite(siteName2); + siteService.deleteSite(siteName3); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } public void testJoinLeave() { - // Create a site as user one - this.siteService.createSite(TEST_SITE_PRESET, "testMembership", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - this.siteService.createSite(TEST_SITE_PRESET, "testMembershipPrivate", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - - // Become user two - //TestWithUserUtils.authenticateUser(USER_TWO, "PWD", this.authenticationService, this.authenticationComponent); - this.authenticationComponent.setCurrentUser(USER_TWO); - - // As user two try and add self as contributor - try + RetryingTransactionCallback work = new RetryingTransactionCallback() { - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_COLLABORATOR); - fail("This should have failed because you don't have permissions"); - } - catch (AlfrescoRuntimeException exception) - { - // Ignore because as expected - } - - // As user two try and add self as consumer to public site - this.siteService.setMembership("testMembership", USER_TWO, SiteModel.SITE_CONSUMER); - - // As user two try and add self as consumer to private site - try - { - this.siteService.setMembership("testMembershipPrivate", USER_TWO, SiteModel.SITE_CONSUMER); - fail("This should have failed because you can't do this to a private site unless you are site manager"); - } - catch (AlfrescoRuntimeException exception) - { - // Ignore because as expected - } - - // As user two try and add user three as a consumer to a public site - try - { - this.siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_CONSUMER); - fail("This should have failed because you can't add another user as a consumer of a public site"); - } - catch (AlfrescoRuntimeException exception) - { - // Ignore because as expected - } - - - // add some members use in remove tests - this.authenticationComponent.setCurrentUser(USER_ONE); - this.siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_COLLABORATOR); - this.siteService.setMembership("testMembershipPrivate", USER_TWO, SiteModel.SITE_CONSUMER); - this.authenticationComponent.setCurrentUser(USER_TWO); - - // Try and remove user threes membership from public site - try - { - this.siteService.removeMembership("testMembership", USER_THREE); - fail("Cannot remove membership"); - } - catch (Exception exception) - { - // Ignore because as expected - } - - // Try and remove own membership - this.siteService.removeMembership("testMembership", USER_TWO); + + @Override + public Object execute() throws Throwable + { + // Create a site as user one + siteService.createSite(TEST_SITE_PRESET, "testMembershipPublic", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + siteService.createSite(TEST_SITE_PRESET, "testMembershipPrivate", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + // Become user two + // TestWithUserUtils.authenticateUser(USER_TWO, "PWD", this.authenticationService, this.authenticationComponent); + authenticationComponent.setCurrentUser(USER_TWO); + + // As user two try and add self as contributor + try + { + siteService.setMembership("testMembershipPublic", USER_TWO, SiteModel.SITE_COLLABORATOR); + fail("This should have failed because you don't have permissions"); + } + catch (AlfrescoRuntimeException exception) + { + // Ignore because as expected + } + + // As user two try and add self as consumer to public site + siteService.setMembership("testMembershipPublic", USER_TWO, SiteModel.SITE_CONSUMER); + + // As user two try and add self as consumer to private site + try + { + siteService.setMembership("testMembershipPrivate", USER_TWO, SiteModel.SITE_CONSUMER); + fail("This should have failed because you can't do this to a private site unless you are site manager"); + } + catch (AlfrescoRuntimeException exception) + { + // Ignore because as expected + } + + // As user two try and add user three as a consumer to a public site + try + { + siteService.setMembership("testMembershipPublic", USER_THREE, SiteModel.SITE_CONSUMER); + fail("This should have failed because you can't add another user as a consumer of a public site"); + } + catch (AlfrescoRuntimeException exception) + { + // Ignore because as expected + } + + // add some members use in remove tests + authenticationComponent.setCurrentUser(USER_ONE); + siteService.setMembership("testMembershipPublic", USER_THREE, SiteModel.SITE_COLLABORATOR); + siteService.setMembership("testMembershipPrivate", USER_TWO, SiteModel.SITE_CONSUMER); + authenticationComponent.setCurrentUser(USER_TWO); + + // Try and remove user threes membership from public site + try + { + siteService.removeMembership("testMembershipPublic", USER_THREE); + fail("Cannot remove membership"); + } + catch (Exception exception) + { + // Ignore because as expected + } + + // Try and remove own membership + siteService.removeMembership("testMembershipPublic", USER_TWO); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("testMembershipPublic"); + siteService.deleteSite("testMembershipPrivate"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } public void testContainer() @@ -1672,10 +1857,10 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest // GROUP_TWO - USER_TWO, USER_THREE // Create a site as user one - this.siteService.createSite(TEST_SITE_PRESET, "testMembership", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + this.siteService.createSite(TEST_SITE_PRESET, "testGroupMembership", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); // Get the members of the site and check that user one is a manager - Map members = this.siteService.listMembers("testMembership", null, null, 0); + Map members = this.siteService.listMembers("testGroupMembership", null, null, 0); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(USER_ONE)); @@ -1684,16 +1869,16 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest /** * Test of isMember - ONE is member, TWO and THREE are not */ - assertTrue(this.siteService.isMember("testMembership", USER_ONE)); - assertTrue(!this.siteService.isMember("testMembership", USER_TWO)); - assertTrue(!this.siteService.isMember("testMembership", USER_THREE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_ONE)); + assertTrue(!this.siteService.isMember("testGroupMembership", USER_TWO)); + assertTrue(!this.siteService.isMember("testGroupMembership", USER_THREE)); /** * Add a group (GROUP_TWO) with role consumer */ - this.siteService.setMembership("testMembership", this.groupTwo, SiteModel.SITE_CONSUMER); + this.siteService.setMembership("testGroupMembership", this.groupTwo, SiteModel.SITE_CONSUMER); // - is the group in the list of all members? - members = this.siteService.listMembers("testMembership", null, null, 0); + members = this.siteService.listMembers("testGroupMembership", null, null, 0); assertNotNull(members); assertEquals(2, members.size()); @@ -1703,7 +1888,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest assertEquals(SiteModel.SITE_CONSUMER, members.get(this.groupTwo)); // - is the user in the expanded list? - members = this.siteService.listMembers("testMembership", null, null, 0, true); + members = this.siteService.listMembers("testGroupMembership", null, null, 0, true); assertNotNull(members); assertEquals(3, members.size()); assertTrue(members.containsKey(USER_ONE)); @@ -1714,18 +1899,18 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_THREE)); // - is the user a member? - assertTrue(this.siteService.isMember("testMembership", USER_ONE)); - assertTrue(this.siteService.isMember("testMembership", USER_TWO)); - assertTrue(this.siteService.isMember("testMembership", USER_THREE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_ONE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_TWO)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_THREE)); // - is the group a member? - assertTrue(this.siteService.isMember("testMembership", this.groupTwo)); + assertTrue(this.siteService.isMember("testGroupMembership", this.groupTwo)); // - can we get the roles for the various members directly - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", USER_ONE)); - assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testMembership", USER_TWO)); - assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testMembership", USER_THREE)); - assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testMembership", this.groupTwo)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", USER_ONE)); + assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testGroupMembership", USER_TWO)); + assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testGroupMembership", USER_THREE)); + assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testGroupMembership", this.groupTwo)); //Uses Members role info assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRoleInfo("testMembership", USER_ONE).getMemberRole()); @@ -1734,13 +1919,13 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest */ // - filter by authority - members = this.siteService.listMembers("testMembership", null, SiteModel.SITE_MANAGER, 0, true); + members = this.siteService.listMembers("testGroupMembership", null, SiteModel.SITE_MANAGER, 0, true); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(USER_ONE)); assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); - members = this.siteService.listMembers("testMembership", null, SiteModel.SITE_CONSUMER, 0, true); + members = this.siteService.listMembers("testGroupMembership", null, SiteModel.SITE_CONSUMER, 0, true); assertNotNull(members); assertEquals(2, members.size()); assertTrue(members.containsKey(USER_TWO)); @@ -1749,14 +1934,14 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest assertEquals(SiteModel.SITE_CONSUMER, members.get(USER_THREE)); // - filter by name - person name - members = this.siteService.listMembers("testMembership", "UserOne*", null, 0, true); + members = this.siteService.listMembers("testGroupMembership", "UserOne*", null, 0, true); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(USER_ONE)); assertEquals(SiteModel.SITE_MANAGER, members.get(USER_ONE)); // - filter by name - person name as part of group - members = this.siteService.listMembers("testMembership", "UserTwo*", null, 0, true); + members = this.siteService.listMembers("testGroupMembership", "UserTwo*", null, 0, true); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(USER_TWO)); @@ -1764,20 +1949,20 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest // - filter by name - person name without group expansion // (won't match as the group name doesn't contain the user's name) - members = this.siteService.listMembers("testMembership", "UserTwo*", null, 0, false); + members = this.siteService.listMembers("testGroupMembership", "UserTwo*", null, 0, false); assertNotNull(members); assertEquals(0, members.size()); // - filter by name - group name - members = this.siteService.listMembers("testMembership", GROUP_TWO, null, 0, false); + members = this.siteService.listMembers("testGroupMembership", GROUP_TWO, null, 0, false); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(this.groupTwo)); assertEquals(SiteModel.SITE_CONSUMER, members.get(this.groupTwo)); // - filter by name - group display name - members = this.siteService.listMembers("testMembership", GROUP_TWO_DISPLAY, null, 0, false); + members = this.siteService.listMembers("testGroupMembership", GROUP_TWO_DISPLAY, null, 0, false); assertNotNull(members); assertEquals(1, members.size()); assertTrue(members.containsKey(this.groupTwo)); @@ -1785,7 +1970,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest // - filter by name - group name with expansion // (won't match anyone as the group name won't hit people too) - members = this.siteService.listMembers("testMembership", GROUP_TWO, null, 0, true); + members = this.siteService.listMembers("testGroupMembership", GROUP_TWO, null, 0, true); assertNotNull(members); assertEquals(0, members.size()); @@ -1793,9 +1978,9 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest /** * Add a group member (USER_THREE) as an explicit member */ - this.siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_COLLABORATOR); + this.siteService.setMembership("testGroupMembership", USER_THREE, SiteModel.SITE_COLLABORATOR); // - check the explicit members list - members = this.siteService.listMembers("testMembership", null, null, 0); + members = this.siteService.listMembers("testGroupMembership", null, null, 0); assertNotNull(members); assertEquals(3, members.size()); assertTrue(members.containsKey(USER_ONE)); @@ -1805,7 +1990,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest assertTrue(members.containsKey(this.groupTwo)); assertEquals(SiteModel.SITE_CONSUMER, members.get(this.groupTwo)); // - check the expanded members list - members = this.siteService.listMembers("testMembership", null, null, 0, true); + members = this.siteService.listMembers("testGroupMembership", null, null, 0, true); assertNotNull(members); assertEquals(3, members.size()); assertTrue(members.containsKey(USER_ONE)); @@ -1816,23 +2001,23 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest assertEquals(SiteModel.SITE_COLLABORATOR, members.get(USER_THREE)); // - check is member - assertTrue(this.siteService.isMember("testMembership", USER_ONE)); - assertTrue(this.siteService.isMember("testMembership", USER_TWO)); - assertTrue(this.siteService.isMember("testMembership", USER_THREE)); - assertTrue(!this.siteService.isMember("testMembership", USER_FOUR)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_ONE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_TWO)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_THREE)); + assertTrue(!this.siteService.isMember("testGroupMembership", USER_FOUR)); // - is the group a member? - assertTrue(this.siteService.isMember("testMembership", this.groupTwo)); + assertTrue(this.siteService.isMember("testGroupMembership", this.groupTwo)); // - check get role directly - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", USER_ONE)); - assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testMembership", USER_TWO)); - assertEquals(SiteModel.SITE_COLLABORATOR, this.siteService.getMembersRole("testMembership", USER_THREE)); - assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testMembership", this.groupTwo)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", USER_ONE)); + assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testGroupMembership", USER_TWO)); + assertEquals(SiteModel.SITE_COLLABORATOR, this.siteService.getMembersRole("testGroupMembership", USER_THREE)); + assertEquals(SiteModel.SITE_CONSUMER, this.siteService.getMembersRole("testGroupMembership", this.groupTwo)); // Check permissions of added group // Update the permissions of the group - this.siteService.setMembership("testMembership", USER_THREE, SiteModel.SITE_CONTRIBUTOR); + this.siteService.setMembership("testGroupMembership", USER_THREE, SiteModel.SITE_CONTRIBUTOR); /** * Add other group (GROUP_3) with higher (MANAGER) role @@ -1844,26 +2029,26 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest * USER_THREE should still be Contributor from explicit membership. * USER_FOUR should be Manager - from group 4 sub-group */ - this.siteService.setMembership("testMembership", this.groupThree, SiteModel.SITE_MANAGER); + this.siteService.setMembership("testGroupMembership", this.groupThree, SiteModel.SITE_MANAGER); - assertTrue(this.siteService.isMember("testMembership", USER_ONE)); - assertTrue(this.siteService.isMember("testMembership", USER_TWO)); - assertTrue(this.siteService.isMember("testMembership", USER_THREE)); - assertTrue(this.siteService.isMember("testMembership", USER_FOUR)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_ONE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_TWO)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_THREE)); + assertTrue(this.siteService.isMember("testGroupMembership", USER_FOUR)); - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", USER_ONE)); - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", USER_TWO)); - assertEquals(SiteModel.SITE_CONTRIBUTOR, this.siteService.getMembersRole("testMembership", USER_THREE)); - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", this.groupThree)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", USER_ONE)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", USER_TWO)); + assertEquals(SiteModel.SITE_CONTRIBUTOR, this.siteService.getMembersRole("testGroupMembership", USER_THREE)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", this.groupThree)); // From sub group four - assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testMembership", USER_FOUR)); + assertEquals(SiteModel.SITE_MANAGER, this.siteService.getMembersRole("testGroupMembership", USER_FOUR)); // Set a membership with an illegal role. See ALF-619. // I'm checking that the exception type thrown is what it should be. try { - this.siteService.setMembership("testMembership", this.groupThree, "rubbish"); + this.siteService.setMembership("testGroupMembership", this.groupThree, "rubbish"); } catch (UnknownAuthorityException expected) { @@ -1904,63 +2089,82 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest */ public void testSiteVisibility() { - // Create a public site - SiteInfo siteInfo = createTestSiteWithContent("testSiteVisibilityPublicSite", "testComp", SiteVisibility.PUBLIC); - // - is the value on the site nodeRef correct? - assertEquals(SiteVisibility.PUBLIC.toString(), this.nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); - // - is the site info correct? - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - siteInfo = this.siteService.getSite("testSiteVisibilityPublicSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - // - are the permissions correct for non-members? - testVisibilityPermissions("Testing visibility of public site", USER_TWO, siteInfo, true, true); - - // Create a moderated site - siteInfo = createTestSiteWithContent("testSiteVisibilityModeratedSite", "testComp", SiteVisibility.MODERATED); - // - is the value on the site nodeRef correct? - assertEquals(SiteVisibility.MODERATED.toString(), this.nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); - // - is the site info correct? - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); - siteInfo = this.siteService.getSite("testSiteVisibilityModeratedSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); - // - are the permissions correct for non-members? - testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false); - - // Create a private site - siteInfo = createTestSiteWithContent("testSiteVisibilityPrivateSite", "testComp", SiteVisibility.PRIVATE); - // - is the value on the site nodeRef correct? - assertEquals(SiteVisibility.PRIVATE.toString(), this.nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); - // - is the site info correct? - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - siteInfo = this.siteService.getSite("testSiteVisibilityPrivateSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - // - are the permissions correct for non-members? - testVisibilityPermissions("Testing visibility of private site", USER_TWO, siteInfo, false, false); - - SiteInfo changeSite = createTestSiteWithContent("testSiteVisibilityChangeSite", "testComp", SiteVisibility.PUBLIC); - // Switch from public -> moderated - changeSite.setVisibility(SiteVisibility.MODERATED); - this.siteService.updateSite(changeSite); - // - check the updated sites visibility - siteInfo = this.siteService.getSite("testSiteVisibilityChangeSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); - testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false); - - // Switch from moderated -> private - changeSite.setVisibility(SiteVisibility.PRIVATE); - this.siteService.updateSite(changeSite); - // - check the updated sites visibility - siteInfo = this.siteService.getSite("testSiteVisibilityChangeSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, false, false); - - // Switch from private -> public - changeSite.setVisibility(SiteVisibility.PUBLIC); - this.siteService.updateSite(changeSite); - // - check the updated sites visibility - siteInfo = this.siteService.getSite("testSiteVisibilityChangeSite"); - checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); - testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, true); + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + // Create a public site + SiteInfo siteInfo = createTestSiteWithContent("testSiteVisibilityPublicSite", "testComp", SiteVisibility.PUBLIC); + // - is the value on the site nodeRef correct? + assertEquals(SiteVisibility.PUBLIC.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); + // - is the site info correct? + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + siteInfo = siteService.getSite("testSiteVisibilityPublicSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + // - are the permissions correct for non-members? + testVisibilityPermissions("Testing visibility of public site", USER_TWO, siteInfo, true, true); + + // Create a moderated site + siteInfo = createTestSiteWithContent("testSiteVisibilityModeratedSite", "testComp", SiteVisibility.MODERATED); + // - is the value on the site nodeRef correct? + assertEquals(SiteVisibility.MODERATED.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); + // - is the site info correct? + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); + siteInfo = siteService.getSite("testSiteVisibilityModeratedSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); + // - are the permissions correct for non-members? + testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false); + + // Create a private site + siteInfo = createTestSiteWithContent("testSiteVisibilityPrivateSite", "testComp", SiteVisibility.PRIVATE); + // - is the value on the site nodeRef correct? + assertEquals(SiteVisibility.PRIVATE.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY)); + // - is the site info correct? + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + siteInfo = siteService.getSite("testSiteVisibilityPrivateSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + // - are the permissions correct for non-members? + testVisibilityPermissions("Testing visibility of private site", USER_TWO, siteInfo, false, false); + + SiteInfo changeSite = createTestSiteWithContent("testSiteVisibilityChangeSite", "testComp", SiteVisibility.PUBLIC); + // Switch from public -> moderated + changeSite.setVisibility(SiteVisibility.MODERATED); + siteService.updateSite(changeSite); + // - check the updated sites visibility + siteInfo = siteService.getSite("testSiteVisibilityChangeSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED); + testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false); + + // Switch from moderated -> private + changeSite.setVisibility(SiteVisibility.PRIVATE); + siteService.updateSite(changeSite); + // - check the updated sites visibility + siteInfo = siteService.getSite("testSiteVisibilityChangeSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, false, false); + + // Switch from private -> public + changeSite.setVisibility(SiteVisibility.PUBLIC); + siteService.updateSite(changeSite); + // - check the updated sites visibility + siteInfo = siteService.getSite("testSiteVisibilityChangeSite"); + checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC); + testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, true); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite("testSiteVisibilityPublicSite"); + siteService.deleteSite("testSiteVisibilityModeratedSite"); + siteService.deleteSite("testSiteVisibilityPrivateSite"); + siteService.deleteSite("testSiteVisibilityChangeSite"); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } /** @@ -2326,26 +2530,39 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest */ public void testETHREEOH_1268() { - // USER_ONE - SiteManager - // GROUP_TWO - Manager - - String siteName = "testALFCOM_XXXX"; - - // Create a site as user one - this.siteService.createSite(TEST_SITE_PRESET, siteName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); - - SiteInfo si = this.siteService.getSite(siteName); - - assertNotNull("site info is null", si); - - authenticationComponent.setCurrentUser(USER_TWO); - - si = this.siteService.getSite(siteName); - - assertNull("site info is not null", si); - - - + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + + @Override + public Object execute() throws Throwable + { + // USER_ONE - SiteManager + // GROUP_TWO - Manager + + String siteName = "testALFCOM_XXXX"; + + // Create a site as user one + siteService.createSite(TEST_SITE_PRESET, siteName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE); + + SiteInfo si = siteService.getSite(siteName); + + assertNotNull("site info is null", si); + + authenticationComponent.setCurrentUser(USER_TWO); + + si = siteService.getSite(siteName); + + assertNull("site info is not null", si); + + authenticationComponent.setSystemUserAsCurrentUser(); + siteService.deleteSite(siteName); + + return null; + } + }; + endTransaction(); + transactionService.getRetryingTransactionHelper().doInTransaction(work); + startNewTransaction(); } /** diff --git a/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java b/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java index 118d713c72..7804577e00 100644 --- a/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/tenant/MultiTServiceImplTest.java @@ -24,12 +24,12 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import javax.transaction.UserTransaction; - import org.alfresco.model.ContentModel; +import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; +import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; @@ -42,6 +42,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.GUID; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -66,41 +67,40 @@ public class MultiTServiceImplTest private SearchService searchService; private NamespaceService namespaceService; - private UserTransaction txn; - private boolean mtEnabled; // Test variables private static final String DEFAULT_ADMIN_PW = "admin"; private static final String PASS = "password"; - private static final String DOMAIN = MultiTServiceImplTest.class.getName().toLowerCase(); - private static final String USER1 = "USER1"; - private static final String USER2 = "USER2"; - private static final String USER3 = "USER3"; - private static final String USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN; - private static final String STRING = "stringwithouttenant"; - private static final String TENANT_STRING = addDomainToId(STRING, DOMAIN); - private static final String STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR; - private static final String STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR; private static final String PROTOCOL = "testprotocol"; private static final String IDENTIFIER = "testidentifier"; private static final String ID = "id"; private static final String ROOT_PATH = "/"; private static final StoreRef DEFAULT_STORE = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; - private static final StoreRef TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN)); private static final NodeRef NODE_REF = new NodeRef(PROTOCOL, IDENTIFIER, ID); - private static final NodeRef TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID); private static final StoreRef STORE_REF = new StoreRef(PROTOCOL, IDENTIFIER); - private static final StoreRef TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN)); private static final String NAMESPACE_URI = "testassoctypenamespace"; private static final String LOCAL_NAME = "testassoctypelocalname"; private static final QName QNAME = QName.createQName(NAMESPACE_URI, LOCAL_NAME); - private static final QName TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME); private static final AssociationRef assocRef = new AssociationRef(NODE_REF, QNAME, NODE_REF); - private static final AssociationRef tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF); - private static final ChildAssociationRef childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF); - private static final ChildAssociationRef tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF); - + + private static String DOMAIN = null; + private static String USER1 = null; + private static String USER2 = null; + private static String USER3 = null; + private static String USER2_WITH_DOMAIN = null; + private static String STRING = null; + private static String TENANT_STRING = null; + private static String STRING_WITH_EXISTENT_DOMAIN = null; + private static String STRING_WITH_NONEXITENT_DOMAIN = null; + private static StoreRef TENANT_STORE = null; + private static NodeRef TENANT_NODE_REF = null; + private static StoreRef TENANT_STORE_REF = null; + private static QName TENANT_QNAME = null; + private static AssociationRef tenantAssocRef = null; + private static ChildAssociationRef childAssocRef = null; + private static ChildAssociationRef tenantChildAssocRef = null; + @Before public void setUp() throws Exception { @@ -113,19 +113,34 @@ public class MultiTServiceImplTest nodeService = ctx.getBean("NodeService", NodeService.class); searchService = ctx.getBean("SearchService", SearchService.class); namespaceService = ctx.getBean("NamespaceService", NamespaceService.class); - + + DOMAIN = GUID.generate(); + USER1 = GUID.generate(); + USER2 = GUID.generate(); + USER3 = GUID.generate(); + USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN; + STRING = GUID.generate(); + TENANT_STRING = addDomainToId(STRING, DOMAIN); + STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR; + STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR; + TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN)); + TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID); + TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN)); + TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME); + tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF); + childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF); + tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); mtEnabled = AuthenticationUtil.isMtEnabled(); - txn = transactionService.getUserTransaction(); - txn.begin(); AuthenticationUtil.setMtEnabled(false); } @After public void tearDown() throws Exception { - txn.rollback(); + deleteTenant(DOMAIN); AuthenticationUtil.setMtEnabled(mtEnabled); AuthenticationUtil.clearCurrentSecurityContext(); } @@ -133,6 +148,13 @@ public class MultiTServiceImplTest @Test public void testIsTenantUser() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + + // Create a user with a plain user name without a domain NodeRef userNodeRef = createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); assertNotNull("The user was not created.", userNodeRef); @@ -148,11 +170,21 @@ public class MultiTServiceImplTest userNodeRef = createUser(USER3, DOMAIN, PASS); assertNotNull("The user was not created.", userNodeRef); assertTrue("The user is from a tenant, but was reported otherwise.", multiTServiceImpl.isTenantUser(USER3 + MultiTServiceImpl.SEPARATOR + DOMAIN)); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetCurrentUserDomain() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + // Test a tenant user createTenant(DOMAIN); NodeRef userNodeRef = createUser(USER1, DOMAIN, PASS); @@ -185,11 +217,21 @@ public class MultiTServiceImplTest result = TenantUtil.runAsUserTenant(work, USER2, TenantService.DEFAULT_DOMAIN); assertEquals("The domains do not match.", TenantService.DEFAULT_DOMAIN, result); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetName() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + NodeRef userNodeRef = createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); assertNotNull("The user was not created.", userNodeRef); TenantRunAsWork work1 = new TenantRunAsWork() @@ -288,7 +330,7 @@ public class MultiTServiceImplTest @Override public QName doWork() throws Exception { - return tenantService.getName(TENANT_NODE_REF ,QNAME); + return tenantService.getName(TENANT_NODE_REF, QNAME); } }; QName result7 = TenantUtil.runAsUserTenant(work7, USER2, DOMAIN); @@ -304,11 +346,21 @@ public class MultiTServiceImplTest }; String result8 = TenantUtil.runAsUserTenant(work8, USER2, DOMAIN); assertEquals("The String should contain domain.", TENANT_STRING, result8); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetBaseName() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + NodeRef userNodeRef = createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); assertNotNull("The user was not created.", userNodeRef); TenantRunAsWork work1 = new TenantRunAsWork() @@ -412,11 +464,21 @@ public class MultiTServiceImplTest }; String result6 = TenantUtil.runAsUserTenant(work6, USER2, DOMAIN); assertEquals("The String should not contain domain.", STRING, result6); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testCheckDomainUser() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + String nonExistentDomain = "nonExistentDomain"; createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); createTenant(DOMAIN); @@ -458,56 +520,75 @@ public class MultiTServiceImplTest { // Expected } + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testCheckDomain() { - createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); - createTenant(DOMAIN); - createUser(USER2, DOMAIN, PASS); + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); + createTenant(DOMAIN); + createUser(USER2, DOMAIN, PASS); try { - createUser(USER3, STRING, PASS); + createUser(USER3, STRING, PASS); fail("The string has a domain, but there is no such tenant"); } catch (Exception e) { // Expected } - try - { - checkDomainWork(STRING_WITH_EXISTENT_DOMAIN, TenantService.DEFAULT_DOMAIN, USER1); - fail("The string has a domain, which should not match the default one."); - } - catch (Exception e) - { - // Expected - } + try + { + checkDomainWork(STRING_WITH_EXISTENT_DOMAIN, TenantService.DEFAULT_DOMAIN, USER1); + fail("The string has a domain, which should not match the default one."); + } + catch (Exception e) + { + // Expected + } - try - { - checkDomainWork(STRING_WITH_EXISTENT_DOMAIN, DOMAIN, USER2); - } - catch (Exception e) - { - fail("The string has a tenant domain and should match the execution context tenant."); - } - - try - { - checkDomainWork(STRING_WITH_NONEXITENT_DOMAIN, DOMAIN, USER2); - fail("The string has a domain, which should not match the execution context tenant."); - } - catch (Exception e) - { - // Expected - } + try + { + checkDomainWork(STRING_WITH_EXISTENT_DOMAIN, DOMAIN, USER2); + } + catch (Exception e) + { + fail("The string has a tenant domain and should match the execution context tenant."); + } + + try + { + checkDomainWork(STRING_WITH_NONEXITENT_DOMAIN, DOMAIN, USER2); + fail("The string has a domain, which should not match the execution context tenant."); + } + catch (Exception e) + { + // Expected + } + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetRootNode() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + NodeRef rootNodeRefDefault = nodeService.getRootNode(DEFAULT_STORE); NodeRef rootNodeRef = new NodeRef(DEFAULT_STORE, IDENTIFIER); NodeRef nodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, ROOT_PATH, rootNodeRef); @@ -518,6 +599,10 @@ public class MultiTServiceImplTest rootNodeRef = new NodeRef(TENANT_STORE, IDENTIFIER); nodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, ROOT_PATH, rootNodeRef); assertEquals("The reported rootNodeRef for the tenant domain is not correct.", rootNodeRefDefault, nodeRef); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } /** @@ -526,33 +611,58 @@ public class MultiTServiceImplTest @Test public void testIsTenantName() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + boolean result = tenantService.isTenantName(STRING); assertFalse("The string was reported as domain, but it is not", result); result = tenantService.isTenantName(STRING_WITH_EXISTENT_DOMAIN); assertTrue("The string was not reported as domain.", result); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetPrimaryDomain() { - String result = tenantService.getPrimaryDomain(USER1); - assertNull("The primary domain should be null for a non tenant user without a tenant in name.", result); - - result = tenantService.getPrimaryDomain(USER2_WITH_DOMAIN); - assertNull("The primary domain should be null for a tenant user if multi tenancy is not enabled.", result); - - createTenant(DOMAIN); - result = tenantService.getPrimaryDomain(USER2_WITH_DOMAIN); - assertEquals("The primary domain should be of the USER2 is " + DOMAIN + ", but was reported as " + result, DOMAIN, result); - - result = tenantService.getPrimaryDomain(USER1); - assertTrue("The primary domain should be the default one (empty string) for a non tenant user without a tenant in name.", result.equals(TenantService.DEFAULT_DOMAIN)); + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + String result = tenantService.getPrimaryDomain(USER1); + assertNull("The primary domain should be null for a non tenant user without a tenant in name.", result); + + result = tenantService.getPrimaryDomain(USER2_WITH_DOMAIN); + assertNull("The primary domain should be null for a tenant user if multi tenancy is not enabled.", result); + + createTenant(DOMAIN); + result = tenantService.getPrimaryDomain(USER2_WITH_DOMAIN); + assertEquals("The primary domain of the USER2 should be " + DOMAIN + ", but was reported as " + result, DOMAIN, result); + + result = tenantService.getPrimaryDomain(USER1); + assertTrue("The primary domain should be the default one (empty string) for a non tenant user without a tenant in name.", result.equals(TenantService.DEFAULT_DOMAIN)); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetDomain() throws Exception { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + createUser(USER1, TenantService.DEFAULT_DOMAIN, PASS); String result = getDomainWork(STRING, TenantService.DEFAULT_DOMAIN, USER1, false); assertEquals("The domain should be reported as default.", TenantService.DEFAULT_DOMAIN, result); @@ -584,24 +694,43 @@ public class MultiTServiceImplTest { // Expected } + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetTenant() { - Tenant tenant = tenantService.getTenant(DOMAIN); - assertNull("The tenant should not exist.", tenant); - - createTenant(DOMAIN); - tenant = tenantService.getTenant(DOMAIN); - assertNotNull("The tenant should exist.", tenant); - assertTrue("The tenant should have the correct domain.", DOMAIN.equals(tenant.getTenantDomain())); - assertTrue("The tenant should be enabled.", tenant.isEnabled()); + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + Tenant tenant = tenantService.getTenant(DOMAIN); + assertNull("The tenant should not exist.", tenant); + + createTenant(DOMAIN); + tenant = tenantService.getTenant(DOMAIN); + assertNotNull("The tenant should exist.", tenant); + assertTrue("The tenant should have the correct domain.", DOMAIN.equals(tenant.getTenantDomain())); + assertTrue("The tenant should be enabled.", tenant.isEnabled()); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } @Test public void testGetUserDomain() { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + String result = tenantService.getUserDomain(USER1); assertEquals("The user domain should be the default one for a non tenant user without a tenant in name.", TenantService.DEFAULT_DOMAIN, result); @@ -614,6 +743,10 @@ public class MultiTServiceImplTest result = tenantService.getUserDomain(USER1); assertTrue("The user domain should be the default one (empty string) for a non tenant user without a tenant in name.", result.equals(TenantService.DEFAULT_DOMAIN)); + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); } /** @@ -736,7 +869,38 @@ public class MultiTServiceImplTest return personNodeRef; } - + + private void deleteTenant(final String tenantDomain) + { + AuthenticationUtil.runAs(new RunAsWork() + { + public Object doWork() throws Exception + { + RetryingTransactionHelper.RetryingTransactionCallback work = new RetryingTransactionHelper.RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + // delete tenant (if it exists) + if (tenantAdminService.existsTenant(tenantDomain)) + { + // TODO: WARNING: HACK for ALF-19155: MT deleteTenant does not work + // PersonService prevents 'guest' authorities from being deleted + { + BehaviourFilter behaviourFilter = (BehaviourFilter) ctx.getBean("policyBehaviourFilter"); + behaviourFilter.disableBehaviour(ContentModel.TYPE_PERSON); + behaviourFilter.disableBehaviour(ContentModel.ASPECT_UNDELETABLE); + } + tenantAdminService.deleteTenant(tenantDomain); + } + return null; + } + }; + transactionService.getRetryingTransactionHelper().doInTransaction(work); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + } + /** * Utility method to add a domain to an string id * @param id String diff --git a/source/test-java/org/alfresco/repo/usage/RepoUsageComponentTest.java b/source/test-java/org/alfresco/repo/usage/RepoUsageComponentTest.java index 790de46d38..0627eaab4b 100644 --- a/source/test-java/org/alfresco/repo/usage/RepoUsageComponentTest.java +++ b/source/test-java/org/alfresco/repo/usage/RepoUsageComponentTest.java @@ -166,11 +166,14 @@ public class RepoUsageComponentTest extends TestCase public void test4FullUse() throws Exception { - // Set the restrictions + // Update usage + updateUsage(UsageType.USAGE_ALL); + + // Set the restrictions RepoUsage restrictions = new RepoUsage( System.currentTimeMillis(), - 7L, - 600L, + getUsage().getUsers(), + 10000L, LicenseMode.TEAM, System.currentTimeMillis() + 24*3600000, false); @@ -178,12 +181,13 @@ public class RepoUsageComponentTest extends TestCase // Get the restrictions (should not need a txn for this) RepoUsage restrictionsCheck = repoUsageComponent.getRestrictions(); assertEquals("Restrictions should return without change.", restrictions, restrictionsCheck); - + // Update use updateUsage(UsageType.USAGE_ALL); - + // Get the usage - RepoUsage usage = getUsage(); + RepoUsage usage = getUsage(); + // Check assertNotNull("Usage is null", usage); assertNotNull("Invalid user count", usage.getUsers());