Java Code Examples for org.alfresco.util.GUID#generate()
The following examples show how to use
org.alfresco.util.GUID#generate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteMethodTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create file with versionable aspect * * @throws Exception */ private void createFileWithVersionableAscpect() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); txn = transactionService.getUserTransaction(); txn.begin(); // Create a test file with versionable aspect and content Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); versionableDocName = "doc-" + GUID.generate(); properties.put(ContentModel.PROP_NAME, versionableDocName); versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef(); contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent"); nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null); txn.commit(); txn = transactionService.getUserTransaction(); txn.begin(); }
Example 2
Source File: SiteExportServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public void testExportSiteWithNoUsers() throws Exception { // Create a site String shortName = GUID.generate(); createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); // Export site Response response = sendRequest(new GetRequest(getExportUrl(shortName)), 200); // check No_Users_In_Site.txt and No_Persons_In_Site.txt present List<String> entries = getEntries(new ZipInputStream(new ByteArrayInputStream( response.getContentAsByteArray()))); assertTrue(entries.contains("No_Users_In_Site.txt")); assertTrue(entries.contains("No_Persons_In_Site.txt")); assertFalse(entries.contains("Users.acp")); assertFalse(entries.contains("People.acp")); }
Example 3
Source File: CompositePasswordEncoderTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testUserChain() throws Exception { String rawPassword = "[email protected]"; String salt = GUID.generate(); ShaPasswordEncoderImpl sha = new ShaPasswordEncoderImpl(256); String shaEncoded = sha.encodePassword(rawPassword, salt); assertTrue(encoder.matches("sha256", rawPassword, shaEncoded, salt)); List<String> nowHashed = new ArrayList<String>(); nowHashed.add("sha256"); nowHashed.add("bcrypt10"); String nowEncoded = encoder.encode("bcrypt10", shaEncoded, salt); String nowEncoded2 = encoder.encode("bcrypt10", shaEncoded, salt); String nowEncoded3 = encoder.encode("bcrypt10", shaEncoded, salt); assertTrue(encoder.matchesPassword(rawPassword, nowEncoded, salt, nowHashed)); assertTrue(encoder.matchesPassword(rawPassword, nowEncoded2, salt, nowHashed)); assertTrue(encoder.matchesPassword(rawPassword, nowEncoded3, salt, nowHashed)); }
Example 4
Source File: BlogServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test for <a href=https://issues.alfresco.com/jira/browse/MNT-11964>MNT-11964</a> * @throws Exception */ public void testBlogPermission() throws Exception { this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); String siteName = SITE_SHORT_NAME_BLOG + GUID.generate(); this.siteService.createSite("BlogSitePreset", siteName, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC); String userName = USER_ONE + GUID.generate(); createUser(userName, SiteModel.SITE_COLLABORATOR, siteName); // Check permissions for admin checkBlogPermissions(siteName); // Check permissions for user this.authenticationComponent.setCurrentUser(userName); checkBlogPermissions(siteName); // Cleanup this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); this.siteService.deleteSite(siteName); // Create a new site as user this.authenticationComponent.setCurrentUser(userName); siteName = SITE_SHORT_NAME_BLOG + GUID.generate(); this.siteService.createSite("BlogSitePreset", siteName, "BlogSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC); // Check permissions for user checkBlogPermissions(siteName); // Check permissions for admin this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); checkBlogPermissions(siteName); // Cleanup this.siteService.deleteSite(siteName); this.personService.deletePerson(userName); }
Example 5
Source File: SiteServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void testGetMemberships() throws Exception { // Create a site String shortName = GUID.generate(); createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); // Check the memberships Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS), 200); JSONArray result = new JSONArray(response.getContentAsString()); assertNotNull(result); assertEquals(1, result.length()); JSONObject membership = result.getJSONObject(0); assertEquals(SiteModel.SITE_MANAGER, membership.get("role")); assertEquals(USER_ONE, membership.getJSONObject("authority").get("userName")); }
Example 6
Source File: LocalAuthenticationServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private String createPerson() { Map<QName, Serializable> properties = new HashMap<>(); String username = "user" + GUID.generate(); properties.put(ContentModel.PROP_USERNAME, username); properties.put(ContentModel.PROP_FIRSTNAME, username); properties.put(ContentModel.PROP_LASTNAME, username); personService.createPerson(properties); return username; }
Example 7
Source File: XSLTProcessorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private FileInfo createXmlFile(NodeRef folder, String content) { String name = GUID.generate(); FileInfo testXmlFile = fileFolderService.create(folder, name + ".xml", ContentModel.TYPE_CONTENT); ContentWriter writer = contentService.getWriter(testXmlFile.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.setMimetype("text/xml"); writer.setEncoding("UTF-8"); writer.putContent(content); return testXmlFile; }
Example 8
Source File: ComparePropertyValueEvaluatorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test some combinations of test file names that had been failing */ @Test public void testTempFileNames() { ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME); condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT); condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "~*.doc"); this.nodeService.setProperty(this.nodeRef, PROP_TEXT, "~1234.doc"); assertTrue(this.evaluator.evaluate(condition, this.nodeRef)); }
Example 9
Source File: StandardQuotaStrategyTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private File createFileOfSize(long sizeInKB) throws IOException { File file = new File(TempFileProvider.getSystemTempDir(), GUID.generate() + ".generated"); file.deleteOnExit(); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file)); for (long i = 0; i < sizeInKB; i++) { os.write(aKB); } os.close(); return file; }
Example 10
Source File: StandardRenditionLocationResolverTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NodeRef makeNode(NodeRef parent, QName nodeType) { String uuid = GUID.generate(); Map<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(ContentModel.PROP_NAME, uuid); ChildAssociationRef assoc = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.CONTENT_MODEL_1_0_URI, uuid), nodeType, props); return assoc.getChildRef(); }
Example 11
Source File: TestAuthenticationServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public String getNewTicket() { String currentUser = getCurrentUserName(); String ticket = userToTicket.get(currentUser); if (ticket == null) { ticket = GUID.generate(); userToTicket.put(currentUser, ticket); } return ticket; }
Example 12
Source File: TestAuthenticationServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public String getCurrentTicket() { String currentUser = getCurrentUserName(); String ticket = userToTicket.get(currentUser); if (ticket == null) { ticket = GUID.generate(); userToTicket.put(currentUser, ticket); } return ticket; }
Example 13
Source File: TransferServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test of Get TransferTargets * * @throws Exception */ @Test public void testGetTransferTargets() throws Exception { String nameA = "Test Transfer Target " + GUID.generate(); String nameB = "Test Transfer Target " + GUID.generate(); String title = "title"; String description = "description"; String endpointProtocol = "http"; String endpointHost = "localhost"; int endpointPort = 8080; String endpointPath = "rhubarb"; String username = "admin"; char[] password = "password".toCharArray(); /** * Now go ahead and create our first transfer target */ TransferTarget targetA = transferService.createAndSaveTransferTarget(nameA, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password); TransferTarget targetB = transferService.createAndSaveTransferTarget(nameB, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password); Set<TransferTarget> targets = transferService.getTransferTargets(); assertTrue("targets is empty", targets.size() > 0); assertTrue("didn't find target A", targets.contains(targetA) ); assertTrue("didn't find target B", targets.contains(targetB)); for(TransferTarget target : targets) { System.out.println("found target: " + target.getName()); } }
Example 14
Source File: ResetPasswordServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void requestReset(String userId, String clientName) { ParameterCheck.mandatoryString("userId", userId); ParameterCheck.mandatoryString("clientName", clientName); String userEmail = validateUserAndGetEmail(userId); // Get the (latest) workflow definition for reset-password. WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(WorkflowModelResetPassword.WORKFLOW_DEFINITION_NAME); // create workflow properties Map<QName, Serializable> props = new HashMap<>(7); props.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, I18NUtil.getMessage(WORKFLOW_DESCRIPTION_KEY)); props.put(WorkflowModelResetPassword.WF_PROP_USERNAME, userId); props.put(WorkflowModelResetPassword.WF_PROP_USER_EMAIL, userEmail); props.put(WorkflowModelResetPassword.WF_PROP_CLIENT_NAME, clientName); props.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null)); String guid = GUID.generate(); props.put(WorkflowModelResetPassword.WF_PROP_KEY, guid); props.put(WorkflowModelResetPassword.WF_PROP_TIMER_END, timerEnd); // start the workflow WorkflowPath path = workflowService.startWorkflow(wfDefinition.getId(), props); if (path.isActive()) { WorkflowTask startTask = workflowService.getStartTask(path.getInstance().getId()); workflowService.endTask(startTask.getId(), null); } }
Example 15
Source File: EventBehaviourTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private String getMockEndpointUri() { return "mock:" + this.getClass().getSimpleName() + "_" + GUID.generate(); }
Example 16
Source File: CheckOutCheckInServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void initTestData() { authenticationComponent.setSystemUserAsCurrentUser(); // Create the store and get the root node reference this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); this.rootNodeRef = nodeService.getRootNode(storeRef); // Create the node used for tests ChildAssociationRef childAssocRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_CONTENT); this.nodeRef = childAssocRef.getChildRef(); nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_TITLED, null); nodeService.setProperty(this.nodeRef, ContentModel.PROP_NAME, TEST_VALUE_NAME); nodeService.setProperty(this.nodeRef, PROP2_QNAME, TEST_VALUE_2); // Add the initial content to the node ContentWriter contentWriter = this.contentService.getWriter(this.nodeRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype("text/plain"); contentWriter.setEncoding("UTF-8"); contentWriter.putContent(CONTENT_1); // Add the lock and version aspects to the created node nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE, null); nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE, null); // Create and authenticate the user this.userName = "cociTest" + GUID.generate(); TestWithUserUtils.createUser(this.userName, PWD, this.rootNodeRef, this.nodeService, this.authenticationService); TestWithUserUtils.authenticateUser(this.userName, PWD, this.rootNodeRef, this.authenticationService); this.userNodeRef = TestWithUserUtils.getCurrentUser(this.authenticationService); permissionService.setPermission(this.rootNodeRef, this.userName, PermissionService.ALL_PERMISSIONS, true); permissionService.setPermission(this.nodeRef, this.userName, PermissionService.ALL_PERMISSIONS, true); folderNodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef(); fileNodeRef = nodeService.createNode( folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "file")).getChildRef(); contentWriter = this.contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true); contentWriter.setMimetype("text/plain"); contentWriter.setEncoding("UTF-8"); contentWriter.putContent(CONTENT_1); }
Example 17
Source File: WebDAVMethodTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private void checkLockedNodeTestWork() throws WebDAVServerException { req = new MockHttpServletRequest(); resp = new MockHttpServletResponse(); String rootPath = "/app:company_home"; String storeName = "workspace://SpacesStore"; StoreRef storeRef = new StoreRef(storeName); NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false); NodeRef defaultRootNode = nodeRefs.get(0); lockMethod = new LockMethod(); NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode); String strPath = "/" + "testLockedNode" + GUID.generate(); lockMethod.createExclusive = true; lockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef); lockMethod.m_strPath = strPath; // Lock the node (will create a new one). transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() { @Override public Object execute() throws Throwable { lockMethod.executeImpl(); return null; } }); // Prepare for PUT req.addHeader(WebDAV.HEADER_IF, "(<" + lockMethod.lockToken + ">)"); putMethod = new PutMethod(); putMethod.setDetails(req, resp, webDAVHelper, rootNodeRef); putMethod.parseRequestHeaders(); putMethod.m_strPath = strPath; String content = "test content stream"; req.setContent(content.getBytes()); // Issue a put request transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() { @Override public Object execute() throws Throwable { putMethod.executeImpl(); return null; } }); }
Example 18
Source File: XSLTRenderingEngineTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private FileInfo createXmlFile(NodeRef folder, String content) { String name = GUID.generate() + ".xml"; return createXmlFile(folder, name, content); }
Example 19
Source File: ImapServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test for MNT-12420 * * @throws Exception */ public void testMoveViaAppendAndDelete() throws Exception { AlfrescoImapUser poweredUser = new AlfrescoImapUser((USER_NAME + "@alfresco.com"), USER_NAME, USER_PASSWORD); String fileName = "testfile" + GUID.generate(); String destinationName = "testFolder" + GUID.generate(); String destinationPath = IMAP_ROOT + AlfrescoImapConst.HIERARCHY_DELIMITER + destinationName; String nodeContent = "test content"; NodeRef root = findCompanyHomeNodeRef(); AuthenticationUtil.setRunAsUserSystem(); // Create node and destination folder FileInfo origFile = fileFolderService.create(root, fileName, ContentModel.TYPE_CONTENT); ContentWriter contentWriter = contentService.getWriter(origFile.getNodeRef(), ContentModel.PROP_CONTENT, true); contentWriter.setMimetype("text/plain"); contentWriter.setEncoding("UTF-8"); contentWriter.putContent(nodeContent); FileInfo destinationNode = fileFolderService.create(root, destinationName, ContentModel.TYPE_FOLDER); nodeService.addAspect(origFile.getNodeRef(), ImapModel.ASPECT_IMAP_CONTENT, null); nodeService.addAspect(origFile.getNodeRef(), ContentModel.ASPECT_TAGGABLE, null); // Save the message and set X-Alfresco-NodeRef-ID header SimpleStoredMessage origMessage = imapService.getMessage(origFile); origMessage.getMimeMessage().addHeader(AlfrescoImapConst.X_ALF_NODEREF_ID, origFile.getNodeRef().getId()); origMessage.getMimeMessage().saveChanges(); // Append the message to destination AlfrescoImapFolder destinationMailbox = imapService.getOrCreateMailbox(poweredUser, destinationPath, true, false); long uuid = destinationMailbox.appendMessage(origMessage.getMimeMessage(), flags, null); // Delete the node imapService.setFlag(origFile, Flags.Flag.DELETED, true); imapService.expungeMessage(origFile); // Check the destination has copy of original file and only this file FileInfo copiedNode = fileFolderService.getFileInfo(nodeService.getNodeRef(uuid)); assertNotNull("The file should exist.", copiedNode); assertEquals("The file name should not change.", fileName, copiedNode.getName()); NodeRef copiedParentNodeRef = nodeService.getPrimaryParent(copiedNode.getNodeRef()).getParentRef(); assertEquals("The parent should change to destination.", destinationNode.getNodeRef(), copiedParentNodeRef); assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size()); assertTrue("New node should have original node aspects", nodeService.hasAspect(copiedNode.getNodeRef(), ContentModel.ASPECT_TAGGABLE)); }
Example 20
Source File: RepositoryAuthenticationDao.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void createUser(String caseSensitiveUserName, String hashedPassword, char[] rawPassword) throws AuthenticationException { tenantService.checkDomainUser(caseSensitiveUserName); NodeRef userRef = getUserOrNull(caseSensitiveUserName); if (userRef != null) { throw new AuthenticationException("User already exists: " + AuthenticationUtil.maskUsername(caseSensitiveUserName)); } NodeRef typesNode = getUserFolderLocation(caseSensitiveUserName); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); properties.put(ContentModel.PROP_USER_USERNAME, caseSensitiveUserName); String salt = GUID.generate(); properties.put(ContentModel.PROP_SALT, salt); boolean emptyPassword = rawPassword != null ? "".equals(new String(rawPassword)) : true; if (emptyPassword) { rawPassword = UUID.randomUUID().toString().toCharArray(); } if (hashedPassword == null) { if (logger.isTraceEnabled()) { logger.trace("Hashing raw password to " + compositePasswordEncoder.getPreferredEncoding() + " for " + AuthenticationUtil .maskUsername(caseSensitiveUserName)); } hashedPassword = compositePasswordEncoder.encodePreferred(new String(rawPassword), salt); } else { if (logger.isTraceEnabled()) { logger.trace("Using hashed password for " + AuthenticationUtil.maskUsername(caseSensitiveUserName)); } } properties.put(ContentModel.PROP_PASSWORD_HASH, hashedPassword); properties.put(ContentModel.PROP_HASH_INDICATOR, (Serializable) Arrays.asList(compositePasswordEncoder.getPreferredEncoding())); properties.put(ContentModel.PROP_ACCOUNT_EXPIRES, Boolean.valueOf(false)); properties.put(ContentModel.PROP_CREDENTIALS_EXPIRE, Boolean.valueOf(false)); properties.put(ContentModel.PROP_ENABLED, Boolean.valueOf(!emptyPassword)); properties.put(ContentModel.PROP_ACCOUNT_LOCKED, Boolean.valueOf(false)); nodeService.createNode(typesNode, ContentModel.ASSOC_CHILDREN, QName.createQName(ContentModel.USER_MODEL_URI, caseSensitiveUserName), ContentModel.TYPE_USER, properties); }