1 17 package org.alfresco.jcr.test; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.Properties ; 22 23 import org.alfresco.repo.importer.ImporterBootstrap; 24 import org.alfresco.repo.security.authentication.AuthenticationComponent; 25 import org.alfresco.repo.security.authentication.MutableAuthenticationDao; 26 import org.alfresco.service.ServiceRegistry; 27 import org.alfresco.service.cmr.repository.NodeService; 28 import org.alfresco.service.cmr.repository.StoreRef; 29 import org.alfresco.service.cmr.security.PermissionService; 30 import org.alfresco.service.cmr.view.ImporterService; 31 import org.alfresco.service.namespace.NamespaceService; 32 import org.alfresco.service.transaction.TransactionService; 33 import org.springframework.context.ApplicationContext; 34 import org.springframework.context.support.ClassPathXmlApplicationContext; 35 36 37 38 public class TestData 39 { 40 public static final String TEST_WORKSPACE = "test"; 41 42 47 public static void main(String [] args) 48 { 49 ApplicationContext context = new ClassPathXmlApplicationContext("org/alfresco/jcr/test/test-context.xml"); 50 generateTestData(context, TEST_WORKSPACE); 51 System.out.println("Generated TCK test data to workspace: " + TEST_WORKSPACE); 52 System.exit(0); 53 } 54 55 61 public static void generateTestData(ApplicationContext applicationContext, String workspaceName) 62 { 63 { 64 MutableAuthenticationDao authDAO = (MutableAuthenticationDao) applicationContext.getBean("alfDaoImpl"); 66 if (authDAO.userExists("superuser") == false) 67 { 68 authDAO.createUser("superuser", "".toCharArray()); 69 } 70 if (authDAO.userExists("user") == false) 71 { 72 authDAO.createUser("user", "".toCharArray()); 73 } 74 if (authDAO.userExists("anonymous") == false) 75 { 76 authDAO.createUser("anonymous", "".toCharArray()); 77 } 78 } 79 80 try 81 { 82 AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); 83 authenticationComponent.setSystemUserAsCurrentUser(); 84 85 try 86 { 87 StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, workspaceName); 89 90 ImporterBootstrap bootstrap = new ImporterBootstrap(); 91 bootstrap.setAuthenticationComponent((AuthenticationComponent) applicationContext.getBean("authenticationComponent")); 92 bootstrap.setImporterService((ImporterService) applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName())); 93 bootstrap.setNodeService((NodeService) applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName())); 94 bootstrap.setNamespaceService((NamespaceService) applicationContext.getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName())); 95 bootstrap.setTransactionService((TransactionService) applicationContext.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName())); 96 bootstrap.setStoreUrl(storeRef.toString()); 97 98 List <Properties > views = new ArrayList <Properties >(); 99 Properties testView = new Properties (); 100 testView.setProperty("path", "/"); 101 testView.setProperty("location", "org/alfresco/jcr/test/testData.xml"); 102 views.add(testView); 103 bootstrap.setBootstrapViews(views); 104 bootstrap.bootstrap(); 105 106 authenticationComponent.setSystemUserAsCurrentUser(); 108 109 PermissionService permissionService = (PermissionService)applicationContext.getBean(ServiceRegistry.PERMISSIONS_SERVICE.getLocalName()); 110 NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName()); 111 112 permissionService.setPermission(nodeService.getRootNode(storeRef), "superuser", PermissionService.ALL_PERMISSIONS, true); 114 permissionService.setPermission(nodeService.getRootNode(storeRef), "anonymous", PermissionService.READ, true); 115 permissionService.setPermission(nodeService.getRootNode(storeRef), "user", PermissionService.READ, true); 116 permissionService.setPermission(nodeService.getRootNode(storeRef), "user", PermissionService.WRITE, true); 117 } 118 finally 119 { 120 authenticationComponent.clearCurrentSecurityContext(); 121 } 122 } 123 catch (RuntimeException e) 124 { 125 System.out.println("Exception: " + e); 126 e.printStackTrace(); 127 throw e; 128 } 129 } 130 131 } 132 | Popular Tags |