@Override protected void tearDown() throws Exception { super.tearDown(); // admin user required to delete user this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_WIKI); if (siteInfo != null) { // delete the site siteService.deleteSite(SITE_SHORT_NAME_WIKI); nodeArchiveService.purgeArchivedNode( nodeArchiveService.getArchivedNode(siteInfo.getNodeRef())); } // delete the users if (personService.personExists(USER_ONE)) { personService.deletePerson(USER_ONE); } if (this.authenticationService.authenticationExists(USER_ONE)) { this.authenticationService.deleteAuthentication(USER_ONE); } if (personService.personExists(USER_TWO)) { personService.deletePerson(USER_TWO); } if (this.authenticationService.authenticationExists(USER_TWO)) { this.authenticationService.deleteAuthentication(USER_TWO); } }
@Override protected String applyInternal() throws Exception { // get all users in the system List<PersonInfo> personInfos = _personService .getPeople(null, null, null, new PagingRequest(Integer.MAX_VALUE, null)) .getPage(); Set<NodeRef> people = new HashSet<NodeRef>(personInfos.size()); for (PersonInfo personInfo : personInfos) { people.add(personInfo.getNodeRef()); } int count = 0; // iterate through all the users for (final NodeRef person : people) { // get the username from the node final Serializable username = nodeService.getProperty(person, ContentModel.PROP_USERNAME); // if no username, continue if (username == null) { continue; } // if it's the guest or admin, skip as well if (username.toString().equals("guest") || username.toString().equals("admin")) { continue; } // list all sites that the user is excplicit member in final List<SiteInfo> sites = _siteService.listSites(username.toString()); // the user is member of 1 site or more, continue if (sites.size() > 0) { continue; } // if this point is reached, the user is not a member of any site, so it // should be deleted LOG.error("Deleting user '" + username + "', user is not a member of any site"); _personService.deletePerson(username.toString()); count++; } LOG.error( "Deleted " + count + " of " + people.size() + " users that wasn't a member in any sites."); return I18NUtil.getMessage(MSG_SUCCESS); }
@Override public void setUp() throws Exception { ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry"); authenticationService = serviceRegistry.getAuthenticationService(); imapService = serviceRegistry.getImapService(); importerService = serviceRegistry.getImporterService(); NodeService nodeService = serviceRegistry.getNodeService(); SearchService searchService = serviceRegistry.getSearchService(); NamespaceService namespaceService = serviceRegistry.getNamespaceService(); PersonService personService = serviceRegistry.getPersonService(); FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); TransactionService transactionService = serviceRegistry.getTransactionService(); PermissionService permissionService = serviceRegistry.getPermissionService(); // start the transaction UserTransaction txn = transactionService.getUserTransaction(); txn.begin(); authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray()); anotherUserName = "******"; NodeRef person = personService.getPerson(anotherUserName); if (person != null) { personService.deletePerson(anotherUserName); PropertyMap testUser = new PropertyMap(); testUser.put(ContentModel.PROP_USERNAME, anotherUserName); testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName); testUser.put(ContentModel.PROP_LASTNAME, anotherUserName); testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com"); testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle"); personService.createPerson(testUser); } if (authenticationService.authenticationExists(anotherUserName)) { authenticationService.deleteAuthentication(anotherUserName); } authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray()); user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName); String storePath = "workspace://SpacesStore"; String companyHomePathInStore = "/app:company_home"; StoreRef storeRef = new StoreRef(storePath); NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes( storeRootNodeRef, companyHomePathInStore, null, namespaceService, false); NodeRef companyHomeNodeRef = nodeRefs.get(0); ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap"); ApplicationContext imapCtx = imap.getApplicationContext(); ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService"); // Delete test folder nodeRefs = searchService.selectNodes( storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false); if (nodeRefs.size() == 1) { NodeRef ch = nodeRefs.get(0); nodeService.deleteNode(ch); } // Creating IMAP test folder for IMAP root LinkedList<String> folders = new LinkedList<String>(); folders.add(TEST_IMAP_ROOT_FOLDER_NAME); FileFolderServiceImpl.makeFolders( fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER); // Setting IMAP root RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean(); imapHome.setStore(storePath); imapHome.setRootPath(companyHomePathInStore); imapHome.setFolderPath(TEST_IMAP_ROOT_FOLDER_NAME); imapServiceImpl.setImapHome(imapHome); // Starting IMAP imapServiceImpl.startupInTxn(true); nodeRefs = searchService.selectNodes( storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false); // Used to create User's folder NodeRef userFolderRef = imapService.getUserImapHomeRef(anotherUserName); permissionService.setPermission( userFolderRef, anotherUserName, PermissionService.ALL_PERMISSIONS, true); importTestData("imap/load_test_data.acp", userFolderRef); reauthenticate(anotherUserName, anotherUserName); AlfrescoImapFolder testDataFolder = imapService.getOrCreateMailbox(user, TEST_DATA_FOLDER_NAME, true, false); SimpleStoredMessage m = testDataFolder.getMessages().get(0); m = testDataFolder.getMessage(m.getUid()); AlfrescoImapFolder folder = imapService.getOrCreateMailbox(user, TEST_FOLDER_NAME, false, true); logger.info("Creating folders..."); long t = System.currentTimeMillis(); try { for (int i = 0; i < MESSAGE_QUANTITY; i++) { System.out.println("i = " + i); folder.appendMessage(m.getMimeMessage(), new Flags(), new Date()); } } catch (Exception e) { logger.error(e, e); } t = System.currentTimeMillis() - t; logger.info("Create time: " + t + " ms (" + t / 1000 + " s (" + t / 60000 + " min))"); txn.commit(); }
public void test_MNT11595() throws Exception { final String user = "******"; try { // admin authentication this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); MutableAuthenticationService mas = (MutableAuthenticationService) getServer().getApplicationContext().getBean("authenticationService"); // create user createUser(user, SiteModel.SITE_MANAGER); assertTrue(personService.personExists(user)); // invite user to a site with 'Manager' role siteService.setMembership(SITE_SHORT_NAME_WIKI, user, SiteRole.SiteManager.toString()); // user authentication this.authenticationComponent.setCurrentUser(user); // create wiki page by user ('Manager' role) WikiPageInfo wikiPage = this.wikiService.createWikiPage( SITE_SHORT_NAME_WIKI, "test wiki page", "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals. Sir Winston Churchill"); String uri = "/slingshot/wiki/page/" + SITE_SHORT_NAME_WIKI + "/Main_Page?alf_ticket=" + mas.getCurrentTicket() + "application/json"; Response responseManagerRole = sendRequest(new GetRequest(uri), 404); JSONObject resultManagerRole = new JSONObject(responseManagerRole.getContentAsString()); JSONObject permissionsManagerRole = resultManagerRole.getJSONObject("permissions"); assertTrue(permissionsManagerRole.getBoolean("create")); assertTrue(permissionsManagerRole.getBoolean("edit")); // admin authentication this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); // change user role - 'Consumer' role siteService.setMembership(SITE_SHORT_NAME_WIKI, user, SiteRole.SiteConsumer.toString()); // user authentication this.authenticationComponent.setCurrentUser(user); Response responseConsumerRole = sendRequest(new GetRequest(uri), 404); JSONObject resultConsumerRole = new JSONObject(responseConsumerRole.getContentAsString()); JSONObject permissionsConsumerRole = resultConsumerRole.getJSONObject("permissions"); assertFalse(permissionsConsumerRole.getBoolean("create")); assertFalse(permissionsConsumerRole.getBoolean("edit")); } finally { this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); if (personService.personExists(user)) { personService.deletePerson(user); } if (this.authenticationService.authenticationExists(user)) { this.authenticationService.deleteAuthentication(user); } } }
/** Listing */ public void testOverallListing() throws Exception { JSONObject pages; JSONArray entries; // Initially, there are no events pages = getPages(null, null); assertEquals("Incorrect JSON: " + pages.toString(), true, pages.has("totalPages")); assertEquals(0, pages.getInt("totalPages")); // Add two links to get started with createOrUpdatePage(PAGE_TITLE_ONE, PAGE_CONTENTS_ONE, null, Status.STATUS_OK); createOrUpdatePage(PAGE_TITLE_TWO, PAGE_CONTENTS_TWO, null, Status.STATUS_OK); // Check again pages = getPages(null, null); // Should have two links assertEquals("Incorrect JSON: " + pages.toString(), true, pages.has("totalPages")); assertEquals(2, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(2, entries.length()); // Sorted by newest created first assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title")); // Add a third, which is internal, and created by the other user this.authenticationComponent.setCurrentUser(USER_TWO); JSONObject page3 = createOrUpdatePage(PAGE_TITLE_THREE, PAGE_CONTENTS_THREE, null, Status.STATUS_OK); String name3 = PAGE_TITLE_THREE.replace(' ', '_'); createOrUpdatePage(PAGE_TITLE_THREE, "UD" + PAGE_CONTENTS_THREE, null, Status.STATUS_OK); this.authenticationComponent.setCurrentUser(USER_ONE); // Check now, should have three links pages = getPages(null, null); assertEquals(3, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(3, entries.length()); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title")); // Ask for filtering by user pages = getPages(null, USER_ONE); assertEquals(2, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(2, entries.length()); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title")); pages = getPages(null, USER_TWO); assertEquals(1, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(1, entries.length()); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title")); // Ask for filtering by recently added docs pages = getPages("recentlyAdded", null); assertEquals(3, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(3, entries.length()); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title")); // Push one back into the past pushPageCreatedDateBack(name3, 10); pages = getPages("recentlyAdded", null); assertEquals(2, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(2, entries.length()); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title")); // Now for recently modified ones pages = getPages("recentlyModified", null); assertEquals(3, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(3, entries.length()); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title")); // assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(2).getString("title")); // Change the owner+creator of one of the pages to System, ensure that // this doesn't break anything in the process String pageTwoName = entries.getJSONObject(1).getString("name"); WikiPageInfo pageTwo = wikiService.getWikiPage(SITE_SHORT_NAME_WIKI, pageTwoName); nodeService.setProperty( pageTwo.getNodeRef(), ContentModel.PROP_OWNER, AuthenticationUtil.SYSTEM_USER_NAME); nodeService.setProperty( pageTwo.getNodeRef(), ContentModel.PROP_CREATOR, AuthenticationUtil.SYSTEM_USER_NAME); nodeService.setProperty( pageTwo.getNodeRef(), ContentModel.PROP_MODIFIER, AuthenticationUtil.SYSTEM_USER_NAME); // Check the listing still works (note - order will have changed) pages = getPages("recentlyModified", null); assertEquals(3, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(3, entries.length()); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title")); // Delete User Two, who owns the 3rd page, and ensure that this // doesn't break anything this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); personService.deletePerson(USER_TWO); this.authenticationComponent.setCurrentUser(USER_ONE); // Check the listing still works pages = getPages("recentlyModified", null); assertEquals(3, pages.getInt("totalPages")); entries = pages.getJSONArray("pages"); assertEquals(3, entries.length()); assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title")); assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title")); assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title")); // Now hide the site, and remove the user from it, won't be allowed to see it this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI); site.setVisibility(SiteVisibility.PRIVATE); siteService.updateSite(site); siteService.removeMembership(SITE_SHORT_NAME_WIKI, USER_ONE); this.authenticationComponent.setCurrentUser(USER_ONE); sendRequest(new GetRequest(URL_WIKI_LIST), Status.STATUS_NOT_FOUND); }