Java Code Examples for org.alfresco.service.cmr.repository.NodeService#getRootNode()
The following examples show how to use
org.alfresco.service.cmr.repository.NodeService#getRootNode() .
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: WebDAVHelperIntegrationTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 8 votes |
@Before public void setUp() { AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); webDAVHelper = (WebDAVHelper) ctx.getBean("webDAVHelper"); fileFolderService = (FileFolderService) ctx.getBean("FileFolderService"); nodeService = (NodeService) ctx.getBean("NodeService"); StoreRef storeRef = nodeService.createStore("workspace", "WebDAVHelperTest-"+UUID.randomUUID()); rootNodeRef = nodeService.getRootNode(storeRef); rootFolder = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_FOLDER).getChildRef(); //eventPublisher = (EventPublisherForTestingOnly) ctx.getBean("eventPublisher"); }
Example 2
Source File: NodeRefPropertyMethodInterceptorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void before() throws Exception { mlAwareNodeService = (NodeService) applicationContext.getBean("mlAwareNodeService"); nodeService = (NodeService) applicationContext.getBean("nodeService"); dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); authenticationComponent.setSystemUserAsCurrentUser(); ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/NodeRefTestModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDAO.putModel(model); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); }
Example 3
Source File: LockableAspectInterceptorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Before public void setUp() { appCtx = ApplicationContextHelper.getApplicationContext(); // The user that will create locks, this should be different from the user that queries them (ALF-19465) lockOwner = "jbloggs"; // The 'current' user. userName = AuthenticationUtil.getAdminUserName(); AuthenticationUtil.setFullyAuthenticatedUser(userName); transactionService = (TransactionService) appCtx.getBean("TransactionService"); nodeService = (NodeService) appCtx.getBean("NodeService"); rawNodeService = (NodeService) appCtx.getBean("dbNodeService"); lockStore = (LockStore) appCtx.getBean("lockStore"); rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); interceptor = (LockableAspectInterceptor) appCtx.getBean("lockableAspectInterceptor"); lockService = (LockService)appCtx.getBean("lockService"); fileFolderService = (FileFolderService) appCtx.getBean("FileFolderService"); actionService = (ActionService) appCtx.getBean("ActionService"); }
Example 4
Source File: FullTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void canGuessMimeType() { AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); ContentService contentService = (ContentService) ctx.getBean("ContentService"); NodeService nodeService = (NodeService) ctx.getBean("NodeService"); StoreRef storeRef = nodeService.createStore("workspace", getClass().getName()+UUID.randomUUID()); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); NodeRef nodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getClass().getSimpleName()), ContentModel.TYPE_CONTENT).getChildRef(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); // Pre-condition of test is that we're testing with a potentially problematic BackingStoreAwareCacheWriter // rather than a FileContentWriter, which we would expect to work. assertTrue(writer instanceof BackingStoreAwareCacheWriter); String content = "This is some content"; writer.putContent(content); writer.guessMimetype("myfile.txt"); assertEquals("text/plain", writer.getMimetype()); }
Example 5
Source File: OwnableServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void setUp() throws Exception { if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) { throw new AlfrescoRuntimeException( "A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId()); } nodeService = (NodeService) ctx.getBean("nodeService"); authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService"); authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); ownableService = (OwnableService) ctx.getBean("ownableService"); permissionService = (PermissionService) ctx.getBean("permissionService"); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao"); TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName()); txn = transactionService.getUserTransaction(); txn.begin(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true); if(authenticationDAO.userExists("andy")) { authenticationService.deleteAuthentication("andy"); } authenticationService.createAuthentication("andy", "andy".toCharArray()); dynamicAuthority = new OwnerDynamicAuthority(); dynamicAuthority.setOwnableService(ownableService); authenticationComponent.clearCurrentSecurityContext(); }
Example 6
Source File: ConcurrentNodeServiceSearchTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(); DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO"); // load the system model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); nodeService = (NodeService) ctx.getBean("dbNodeService"); transactionService = (TransactionService) ctx.getBean("transactionComponent"); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); this.authenticationComponent.setSystemUserAsCurrentUser(); // create a first store directly UserTransaction tx = transactionService.getUserTransaction(); tx.begin(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); tx.commit(); }
Example 7
Source File: PerformanceNodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void setUp() throws Exception { applicationContext = ApplicationContextHelper.getApplicationContext(); DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); // load the system model ClassLoader cl = PerformanceNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); DictionaryComponent dictionary = new DictionaryComponent(); dictionary.setDictionaryDAO(dictionaryDao); dictionaryService = loadModel(applicationContext); nodeService = (NodeService) applicationContext.getBean("nodeService"); txnService = (TransactionService) applicationContext.getBean("transactionComponent"); contentService = (ContentService) applicationContext.getBean("contentService"); // create a first store directly RetryingTransactionCallback<NodeRef> createStoreWork = new RetryingTransactionCallback<NodeRef>() { public NodeRef execute() { StoreRef storeRef = nodeService.createStore( StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime()); return nodeService.getRootNode(storeRef); } }; rootNodeRef = txnService.getRetryingTransactionHelper().doInTransaction(createStoreWork); }
Example 8
Source File: RuleLinkTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void before() throws Exception { // Get the services nodeService = (NodeService) applicationContext.getBean("nodeService"); ruleService = (RuleService) applicationContext.getBean("ruleService"); actionService = (ActionService) applicationContext.getBean("actionService"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService"); //authenticationComponent.setSystemUserAsCurrentUser(); authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); // Create the store and get the root node testStoreRef = nodeService.createStore( StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(testStoreRef); // Create the node used for tests NodeRef folder = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef(); folderOne = fileFolderService.create(folder, "folderOne", ContentModel.TYPE_FOLDER).getNodeRef(); folderTwo = fileFolderService.create(folder, "folderTwo", ContentModel.TYPE_FOLDER).getNodeRef(); folderThree = fileFolderService.create(folder, "folderThree", ContentModel.TYPE_FOLDER).getNodeRef(); }
Example 9
Source File: AbstractBulkImportTests.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setup() throws SystemException, NotSupportedException { try { nodeService = (NodeService)ctx.getBean("nodeService"); fileFolderService = (FileFolderService)ctx.getBean("fileFolderService"); transactionService = (TransactionService)ctx.getBean("transactionService"); bulkImporter = (MultiThreadedBulkFilesystemImporter)ctx.getBean("bulkFilesystemImporter"); contentService = (ContentService)ctx.getBean("contentService"); actionService = (ActionService)ctx.getBean("actionService"); ruleService = (RuleService)ctx.getBean("ruleService"); versionService = (VersionService)ctx.getBean("versionService"); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); String s = "BulkFilesystemImport" + System.currentTimeMillis(); txn = transactionService.getUserTransaction(); txn.begin(); AuthenticationUtil.pushAuthentication(); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, s); rootNodeRef = nodeService.getRootNode(storeRef); top = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}top"), ContentModel.TYPE_FOLDER).getChildRef(); topLevelFolder = fileFolderService.create(top, s, ContentModel.TYPE_FOLDER); txn.commit(); } catch(Throwable e) { fail(e.getMessage()); } }
Example 10
Source File: RepositoryPathConfigBean.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Helper method to resolve the path represented by this configuration bean. * <p> * Authentication and transactions are the client's responsibility. * * @return Returns the node reference (first one found) or <tt>null</tt> */ public NodeRef resolveNodePath(NamespaceService namespaceService, NodeService nodeService, SearchService searchService) { NodeRef rootNodeRef = nodeService.getRootNode(store); List<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, rootPath, null, namespaceService, true); if (nodeRefs.size() == 0) { return null; } else { return nodeRefs.get(0); } }
Example 11
Source File: RepositoryStartStopTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void doTestBasicWriteOperations(ApplicationContext ctx) throws Exception { // Grab the beans we need serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); transactionService = serviceRegistry.getTransactionService(); // So we can write test nodes AuthenticationUtil.setRunAsUserSystem(); // Check it looks fine assertFalse("The transaction is read-only - further unit tests are pointless.", transactionService.isReadOnly()); // A basic write operation on a node RetryingTransactionCallback<Void> addPropertyCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { NodeService nodeService = serviceRegistry.getNodeService(); NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); nodeService.setProperty(rootNodeRef, ContentModel.PROP_NAME, "SanityCheck"); writeTestWorked = true; return null; } }; // Now do a write operation, and ensure it worked writeTestWorked = false; transactionService.getRetryingTransactionHelper().doInTransaction(addPropertyCallback, false, true); assertTrue("The Node Write didn't occur or failed with an error", writeTestWorked); }
Example 12
Source File: EncryptionTests.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setUp() throws Exception { dictionaryService = (DictionaryService)ctx.getBean("dictionaryService"); nodeService = (NodeService)ctx.getBean("nodeService"); transactionService = (TransactionService)ctx.getBean("transactionService"); tenantService = (TenantService)ctx.getBean("tenantService"); dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO"); metadataEncryptor = (MetadataEncryptor)ctx.getBean("metadataEncryptor"); authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); keyResourceLoader = (KeyResourceLoader)ctx.getBean("springKeyResourceLoader"); reEncryptor = (ReEncryptor)ctx.getBean("reEncryptor"); backupKeyStoreParameters = (KeyStoreParameters)ctx.getBean("backupKeyStoreParameters"); keyStoreChecker = (KeyStoreChecker)ctx.getBean("keyStoreChecker"); encryptionKeysRegistry = (EncryptionKeysRegistryImpl)ctx.getBean("encryptionKeysRegistry"); //backupKeyStore = (AlfrescoKeyStoreImpl)ctx.getBean("backupKeyStore"); mainKeyStore = (AlfrescoKeyStoreImpl)ctx.getBean("keyStore"); mainEncryptor = (DefaultEncryptor)ctx.getBean("mainEncryptor"); backupEncryptor = (DefaultEncryptor)ctx.getBean("backupEncryptor"); // reencrypt in one txn (since we don't commit the model, the qnames won't be available across transactions) reEncryptor.setSplitTxns(false); this.authenticationComponent.setSystemUserAsCurrentUser(); tx = transactionService.getUserTransaction(); tx.begin(); StoreRef storeRef = nodeService.createStore( StoreRef.PROTOCOL_WORKSPACE, "ReEncryptor_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); keyAlgorithm = "DESede"; newKeys.setKey(KeyProvider.ALIAS_METADATA, generateSecretKey(keyAlgorithm)); // Load models DictionaryBootstrap bootstrap = new DictionaryBootstrap(); List<String> bootstrapModels = new ArrayList<String>(); bootstrapModels.add(TEST_MODEL); // List<String> labels = new ArrayList<String>(); // labels.add(TEST_BUNDLE); bootstrap.setModels(bootstrapModels); // bootstrap.setLabels(labels); bootstrap.setDictionaryDAO(dictionaryDAO); bootstrap.setTenantService(tenantService); bootstrap.bootstrap(); }
Example 13
Source File: SearchServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(); nodeService = (NodeService) ctx.getBean("dbNodeService"); authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService"); authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao"); pubSearchService = (SearchService) ctx.getBean("SearchService"); pubPermissionService = (PermissionService) ctx.getBean("PermissionService"); this.authenticationComponent.setSystemUserAsCurrentUser(); TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE .getLocalName()); tx = transactionService.getUserTransaction(); tx.begin(); if (!authenticationDAO.userExists("andy")) { authenticationService.createAuthentication("andy", "andy".toCharArray()); } if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) { authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray()); } if (!authenticationDAO.userExists("administrator")) { authenticationService.createAuthentication("administrator", "administrator".toCharArray()); } StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}01"), ContentModel.TYPE_FOLDER).getChildRef(); pubPermissionService.setPermission(n1, "andy", "Read", true); n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}02"), ContentModel.TYPE_FOLDER).getChildRef(); pubPermissionService.setPermission(n2, "andy", "Read", true); n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}03"), ContentModel.TYPE_FOLDER).getChildRef(); pubPermissionService.setPermission(n3, "andy", "Read", true); n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}04"), ContentModel.TYPE_FOLDER).getChildRef(); pubPermissionService.setPermission(n4, "andy", "Read", true); n5 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}05"), ContentModel.TYPE_FOLDER).getChildRef(); pubPermissionService.setPermission(n5, "andy", "Read", true); nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}06"), ContentModel.TYPE_FOLDER).getChildRef(); nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}07"), ContentModel.TYPE_FOLDER).getChildRef(); nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}08"), ContentModel.TYPE_FOLDER).getChildRef(); nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}09"), ContentModel.TYPE_FOLDER).getChildRef(); nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}10"), ContentModel.TYPE_FOLDER).getChildRef(); }
Example 14
Source File: FFCLoadsOfFiles.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public static void doExample(ServiceRegistry serviceRegistry) throws Exception { // // locate the company home node // SearchService searchService = serviceRegistry.getSearchService(); NodeService nodeService = serviceRegistry.getNodeService(); NamespaceService namespaceService = serviceRegistry.getNamespaceService(); StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false); if (results.size() == 0) { throw new AlfrescoRuntimeException("Can't find /app:company_home"); } NodeRef companyHomeNodeRef = results.get(0); results = searchService.selectNodes(companyHomeNodeRef, "./cm:LoadTest", null, namespaceService, false); final NodeRef loadTestHome; if (results.size() == 0) { loadTestHome = nodeService.createNode( companyHomeNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "LoadTest"), ContentModel.TYPE_FOLDER).getChildRef(); } else { loadTestHome = results.get(0); } if ((currentDoc + docsPerTx) > totalNumDocs) { docsPerTx = totalNumDocs - currentDoc; } // Create new Space String spaceName = "Bulk Load Space (" + System.currentTimeMillis() + ") from " + currentDoc + " to " + (currentDoc + docsPerTx - 1) + " of " + totalNumDocs; Map<QName, Serializable> spaceProps = new HashMap<QName, Serializable>(); spaceProps.put(ContentModel.PROP_NAME, spaceName); NodeRef newSpace = nodeService.createNode(loadTestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, spaceName),ContentModel.TYPE_FOLDER,spaceProps).getChildRef(); // create new content node within new Space home for (int k = 1;k<=docsPerTx;k++) { currentDoc++; System.out.println("About to start document " + currentDoc); // assign name String name = "BulkLoad (" + System.currentTimeMillis() + ") " + currentDoc ; Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(); contentProps.put(ContentModel.PROP_NAME, name); // create content node // NodeService nodeService = serviceRegistry.getNodeService(); ChildAssociationRef association = nodeService.createNode(newSpace, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), ContentModel.TYPE_CONTENT, contentProps); NodeRef content = association.getChildRef(); // add titled aspect (for Web Client display) Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(); titledProps.put(ContentModel.PROP_TITLE, name); titledProps.put(ContentModel.PROP_DESCRIPTION, name); nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps); // // write some content to new node // ContentService contentService = serviceRegistry.getContentService(); ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); String text = "This is some text in a doc"; writer.putContent(text); System.out.println("About to get child assocs "); //Circa // nodeService.getChildAssocs(newSpace); for (int count=0;count<=10000;count++) { nodeService.getChildAssocs(newSpace); } } //doSearch(searchService); System.out.println("About to end transaction " ); }
Example 15
Source File: UserUsageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
protected void setUp() throws Exception { applicationContext = ApplicationContextHelper.getApplicationContext(); if (AlfrescoTransactionSupport.isActualTransactionActive()) { fail("Test started with transaction in progress"); } nodeService = (NodeService) applicationContext.getBean("nodeService"); fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService"); authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao"); transactionService = (TransactionService) applicationContext.getBean("transactionComponent"); contentService = (ContentService) applicationContext.getBean("contentService"); personService = (PersonService) applicationContext.getBean("personService"); contentUsageImpl = (ContentUsageImpl) applicationContext.getBean("contentUsageImpl"); usageService = (UsageService) applicationContext.getBean("usageService"); ownableService = (OwnableService) applicationContext.getBean("ownableService"); repoAdminService = (RepoAdminService) applicationContext.getBean("repoAdminService"); testTX = transactionService.getUserTransaction(); testTX.begin(); //Authenticate as the admin user AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // get default store (as configured for content usage service) StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); rootNodeRef = nodeService.getRootNode(storeRef); // create test users createTestUsers(); // deploy custom model InputStream modelStream = getClass().getClassLoader().getResourceAsStream("tenant/exampleModel.xml"); repoAdminService.deployModel(modelStream, "exampleModel.xml"); testTX.commit(); authenticationComponent.clearCurrentSecurityContext(); testTX = transactionService.getUserTransaction(); testTX.begin(); }
Example 16
Source File: AuthenticationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setUp() throws Exception { if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) { throw new AlfrescoRuntimeException( "A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId()); } dialect = (Dialect) ctx.getBean("dialect"); nodeService = (NodeService) ctx.getBean("nodeService"); authorityService = (AuthorityService) ctx.getBean("authorityService"); tenantService = (TenantService) ctx.getBean("tenantService"); tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService"); compositePasswordEncoder = (CompositePasswordEncoder) ctx.getBean("compositePasswordEncoder"); ticketComponent = (TicketComponent) ctx.getBean("ticketComponent"); authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService"); pubAuthenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService"); authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); authenticationComponentImpl = (AuthenticationComponent) ctx.getBean("authenticationComponent"); pubPersonService = (PersonService) ctx.getBean("PersonService"); personService = (PersonService) ctx.getBean("personService"); policyComponent = (PolicyComponent) ctx.getBean("policyComponent"); behaviourFilter = (BehaviourFilter) ctx.getBean("policyBehaviourFilter"); authenticationCache = (SimpleCache<String, CacheEntry>) ctx.getBean("authenticationCache"); immutableSingletonCache = (SimpleCache<String, NodeRef>) ctx.getBean("immutableSingletonCache"); // permissionServiceSPI = (PermissionServiceSPI) // ctx.getBean("permissionService"); ticketsCache = (SimpleCache<String, Ticket>) ctx.getBean("ticketsCache"); usernameToTicketIdCache = (SimpleCache<String, String>) ctx.getBean("usernameToTicketIdCache"); ChildApplicationContextFactory sysAdminSubsystem = (ChildApplicationContextFactory) ctx.getBean("sysAdmin"); assertNotNull("sysAdminSubsystem", sysAdminSubsystem); ApplicationContext sysAdminCtx = sysAdminSubsystem.getApplicationContext(); sysAdminParams = (SysAdminParamsImpl) sysAdminCtx.getBean("sysAdminParams"); dao = (MutableAuthenticationDao) ctx.getBean("authenticationDao"); // Let's look inside the alfresco authentication subsystem to get the DAO-wired authentication manager ChildApplicationContextManager authenticationChain = (ChildApplicationContextManager) ctx.getBean("Authentication"); ApplicationContext subsystem = authenticationChain.getApplicationContext(authenticationChain.getInstanceIds().iterator().next()); authenticationManager = (AuthenticationManager) subsystem.getBean("authenticationManager"); transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName()); // Clean up before we start trying to create the test user transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() { @Override public Void execute() throws Throwable { AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); try { deleteAndy(); return null; } finally { authenticationComponent.clearCurrentSecurityContext(); } } }, false, true); userTransaction = transactionService.getUserTransaction(); userTransaction.begin(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); QName children = ContentModel.ASSOC_CHILDREN; QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system"); QName container = ContentModel.TYPE_CONTAINER; QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people"); systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef(); typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef(); Map<QName, Serializable> props = createPersonProperties("Andy"); personAndyNodeRef = nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef(); assertNotNull(personAndyNodeRef); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); authenticationComponent.clearCurrentSecurityContext(); }
Example 17
Source File: XmlMetadataExtracterTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Tests metadata extraction using an action with an EAGER MetadataExtracter for XML. */ public void testLifecycleOfXmlMetadataExtraction() throws Exception { NodeService nodeService = serviceRegistry.getNodeService(); ContentService contentService = serviceRegistry.getContentService(); ActionExecuter executer = (ActionExecuter) ctx.getBean("extract-metadata"); Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, null); StoreRef storeRef = new StoreRef("test", getName()); NodeRef rootNodeRef = null; if (nodeService.exists(storeRef)) { rootNodeRef = nodeService.getRootNode(storeRef); } else { nodeService.createStore("test", getName()); rootNodeRef = nodeService.getRootNode(storeRef); } // Set up some properties PropertyMap properties = new PropertyMap(); properties.put(ContentModel.PROP_TITLE, "My title"); properties.put(ContentModel.PROP_DESCRIPTION, "My description"); NodeRef contentNodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()), ContentModel.TYPE_CONTENT, properties).getChildRef(); // Add some content ContentReader alfrescoModelReader = getReader(FILE_ALFRESCO_MODEL); assertTrue(alfrescoModelReader.exists()); ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); writer.setMimetype(MimetypeMap.MIMETYPE_XML); writer.putContent(alfrescoModelReader); // Execute the action executer.execute(action, contentNodeRef); // Check the node's properties. The EAGER overwrite policy should have replaced the required // properties. String checkTitle = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_TITLE); String checkDescription = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_DESCRIPTION); assertEquals("fm:forummodel", checkTitle); assertEquals("Forum Model", checkDescription); }
Example 18
Source File: WebDAVServlet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param storeValue String * @param rootPath String * @param context WebApplicationContext * @param nodeService NodeService * @param searchService SearchService * @param namespaceService NamespaceService * @param tenantService TenantService * @param m_transactionService TransactionService */ private void initializeRootNode(String storeValue, String rootPath, WebApplicationContext context, NodeService nodeService, SearchService searchService, NamespaceService namespaceService, TenantService tenantService, TransactionService m_transactionService) { // Use the system user as the authenticated context for the filesystem initialization AuthenticationContext authComponent = (AuthenticationContext) context.getBean("authenticationContext"); authComponent.setSystemUserAsCurrentUser(); // Wrap the initialization in a transaction UserTransaction tx = m_transactionService.getUserTransaction(true); try { // Start the transaction if (tx != null) tx.begin(); StoreRef storeRef = new StoreRef(storeValue); if (nodeService.exists(storeRef) == false) { throw new RuntimeException("No store for path: " + storeRef); } NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false); if (nodeRefs.size() > 1) { throw new RuntimeException("Multiple possible children for : \n" + " path: " + rootPath + "\n" + " results: " + nodeRefs); } else if (nodeRefs.size() == 0) { throw new RuntimeException("Node is not found for : \n" + " root path: " + rootPath); } defaultRootNode = nodeRefs.get(0); // Commit the transaction if (tx != null) tx.commit(); } catch (Exception ex) { logger.error(ex); } finally { // Clear the current system user authComponent.clearCurrentSecurityContext(); } }
Example 19
Source File: LockOwnerDynamicAuthorityTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setUp() throws Exception { if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) { throw new AlfrescoRuntimeException( "A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId()); } nodeService = (NodeService) ctx.getBean("nodeService"); authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService"); authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); lockService = (LockService) ctx.getBean("lockService"); permissionService = (PermissionService) ctx.getBean("permissionService"); authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao"); checkOutCheckInService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService"); ownableService = (OwnableService) ctx.getBean("ownableService"); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE .getLocalName()); userTransaction = transactionService.getUserTransaction(); userTransaction.begin(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); permissionService.setPermission(rootNodeRef, PermissionService.ALL_AUTHORITIES, PermissionService.ADD_CHILDREN, true); if (authenticationDAO.userExists("andy")) { authenticationService.deleteAuthentication("andy"); } authenticationService.createAuthentication("andy", "andy".toCharArray()); if (authenticationDAO.userExists("lemur")) { authenticationService.deleteAuthentication("lemur"); } authenticationService.createAuthentication("lemur", "lemur".toCharArray()); if (authenticationDAO.userExists("frog")) { authenticationService.deleteAuthentication("frog"); } authenticationService.createAuthentication("frog", "frog".toCharArray()); dynamicAuthority = new LockOwnerDynamicAuthority(); dynamicAuthority.setLockService(lockService); authenticationComponent.clearCurrentSecurityContext(); }
Example 20
Source File: AbstractPermissionTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setUp() throws Exception { if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) { throw new AlfrescoRuntimeException( "A previous tests did not clean up transaction: " + AlfrescoTransactionSupport.getTransactionId()); } nodeService = (NodeService) applicationContext.getBean("nodeService"); dictionaryService = (DictionaryService) applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE .getLocalName()); permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService"); permissionServiceImpl = (PermissionServiceImpl) applicationContext.getBean("permissionServiceImpl"); namespacePrefixResolver = (NamespacePrefixResolver) applicationContext .getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName()); authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); permissionModelDAO = (ModelDAO) applicationContext.getBean("permissionsModelDAO"); personService = (PersonService) applicationContext.getBean("personService"); authorityService = (AuthorityService) applicationContext.getBean("authorityService"); authorityDAO = (AuthorityDAO) applicationContext.getBean("authorityDAO"); siteService = (SiteService) applicationContext.getBean("SiteService"); // Big 'S' authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao"); nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO"); aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO"); publicServiceAccessService = (PublicServiceAccessService) applicationContext.getBean("publicServiceAccessService"); policyComponent = (PolicyComponent) applicationContext.getBean("policyComponent"); retryingTransactionHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper"); transactionService = (TransactionService) applicationContext.getBean("transactionComponent"); testTX = transactionService.getUserTransaction(); testTX.begin(); testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime()); rootNodeRef = nodeService.getRootNode(testStoreRef); QName children = ContentModel.ASSOC_CHILDREN; QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system"); QName container = ContentModel.TYPE_CONTAINER; QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people"); systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef(); NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef(); Map<QName, Serializable> props = createPersonProperties(USER1_ANDY); nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef(); props = createPersonProperties(USER2_LEMUR); nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef(); // create an authentication object e.g. the user if(authenticationDAO.userExists(USER1_ANDY)) { authenticationService.deleteAuthentication(USER1_ANDY); } authenticationService.createAuthentication(USER1_ANDY, USER1_ANDY.toCharArray()); if(authenticationDAO.userExists(USER2_LEMUR)) { authenticationService.deleteAuthentication(USER2_LEMUR); } authenticationService.createAuthentication(USER2_LEMUR, USER2_LEMUR.toCharArray()); if(authenticationDAO.userExists(USER3_PAUL)) { authenticationService.deleteAuthentication(USER3_PAUL); } authenticationService.createAuthentication(USER3_PAUL, USER3_PAUL.toCharArray()); if(authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) { authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName()); } authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray()); authenticationComponent.clearCurrentSecurityContext(); assertTrue(permissionServiceImpl.getAnyDenyDenies()); }