Java Code Examples for org.alfresco.service.cmr.repository.NodeService#createStore()

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#createStore() . 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 vote down vote up
@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 vote down vote up
@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: ExporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    exporterService = (ExporterService)applicationContext.getBean("exporterComponent");
    importerService = (ImporterService)applicationContext.getBean("importerComponent");
    fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
    categoryService = (CategoryService) applicationContext.getBean("categoryService");     
    transactionService = (TransactionService) applicationContext.getBean("transactionService");
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");

    this.authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    contentLocaleToRestore = I18NUtil.getContentLocale();
    localeToRestore = I18NUtil.getLocale();
}
 
Example 4
Source File: SOLRTrackingComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    txnHelper = transactionService.getRetryingTransactionHelper();

    solrTrackingComponent = (SOLRTrackingComponent) applicationContext.getBean("solrTrackingComponent");
    nodeDAO = (NodeDAO)applicationContext.getBean("nodeDAO");
    qnameDAO = (QNameDAO) applicationContext.getBean("qnameDAO");
    dictionaryDAO =  (DictionaryDAO)applicationContext.getBean("dictionaryDAO");
    nodeService = (NodeService)applicationContext.getBean("NodeService");
    fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService");
    dictionaryService = serviceRegistry.getDictionaryService();
    namespaceService = serviceRegistry.getNamespaceService();
    authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");

    dbNodeService = (DbNodeServiceImpl)applicationContext.getBean("dbNodeService");
    dbNodeService.setEnableTimestampPropagation(false);

    authenticationComponent.setSystemUserAsCurrentUser();

    storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example 5
Source File: FullTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 6
Source File: ImporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    importerService = (ImporterService)applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName());
    
    importerBootstrap = (ImporterBootstrap)applicationContext.getBean("spacesBootstrap");
    
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    this.versionService = (VersionService)this.applicationContext.getBean("VersionService");
    
    // Create the store
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    
    TimeZone tz = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(tz);
    // Joda time has already grabbed the JVM zone so re-set it here
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz));
}
 
Example 7
Source File: ConcurrentNodeServiceSearchTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 8
Source File: OwnableServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 9
Source File: AbstractBulkImportTests.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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: RoutingContentServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
    copyService = (CopyService) ctx.getBean("CopyService");
    this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    // authenticate
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // start the transaction
    txn = getUserTransaction();
    txn.begin();
    
    // create a store and get the root node
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);

    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT);
    contentNodeRef = assocRef.getChildRef();

    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-16");
    writer.setLocale(Locale.CHINESE);
    writer.setMimetype("text/plain");
    writer.putContent("sample content");
}
 
Example 11
Source File: RuleLinkTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 12
Source File: XmlMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 13
Source File: BaseCMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    
    cmisDictionaryService = (CMISDictionaryService) ctx.getBean("OpenCMISDictionaryService");
    cmisMapping = (CMISMapping) ctx.getBean("OpenCMISMapping");
    cmisQueryService = (CMISQueryService) ctx.getBean("OpenCMISQueryService");
    cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
    dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    nodeService = (NodeService) ctx.getBean("nodeService");
    fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
    namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    
    transactionService = (TransactionService) ctx.getBean("transactionComponent");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    searchService = (SearchService) ctx.getBean("searchService");
    
    contentService = (ContentService) ctx.getBean("contentService");
    
    permissionService = (PermissionService) ctx.getBean("permissionService");
    
    versionService = (VersionService) ctx.getBean("versionService");
    
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    
    thumbnailService = (ThumbnailService) ctx.getBean("thumbnailService");
    
    permissionModelDao = (ModelDAO) ctx.getBean("permissionsModelDAO");
    
    dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO");

    testTX = transactionService.getUserTransaction();
    testTX.begin();
    // Authenticate as the admin user
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    String storeName = "CMISTest-" + getStoreName() + "-" + (new Date().getTime());
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, storeName);
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    if(authenticationDAO.userExists("cmis"))
    {
        authenticationService.deleteAuthentication("cmis");
    }
    authenticationService.createAuthentication("cmis", "cmis".toCharArray());        
}
 
Example 14
Source File: EncryptionTests.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 15
Source File: SearchServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 16
Source File: PersonTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void setUp() throws Exception
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    transactionService = (TransactionService) ctx.getBean("transactionService");
    personService = (PersonService) ctx.getBean("personService");
    userNameMatcher = (UserNameMatcherImpl) ctx.getBean("userNameMatcher");
    nodeService = (NodeService) ctx.getBean("nodeService");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    policyBehaviourFilter = (BehaviourFilter) ctx.getBean("policyBehaviourFilter");

    testTX = transactionService.getUserTransaction();
    testTX.begin();

    //Set a max number of users.
    RepoUsageComponentImpl repoUsageComponent = (RepoUsageComponentImpl) ctx.getBean("repoUsageComponent");
    RepoUsage r = repoUsageComponent.getRestrictions();
    repoUsageComponent.setRestrictions(
            new RepoUsage(r.getLastUpdate(),
                    10000l,
                    r.getDocuments(),
                    r.getLicenseMode(),
                    r.getLicenseExpiryDate(),
                    r.isReadOnly()));
    
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
    
    for (NodeRef nodeRef : personService.getAllPeople())
    {
        String uid = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME));
        if (!uid.equals(AuthenticationUtil.getAdminUserName()) && !uid.equals(AuthenticationUtil.getGuestUserName()))
        {
            personService.deletePerson(nodeRef);
        }
    }
    
    personService.setCreateMissingPeople(true);
    
    testTX.commit();
    testTX = transactionService.getUserTransaction();
    testTX.begin();
}
 
Example 17
Source File: AuthenticationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 18
Source File: LockOwnerDynamicAuthorityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 19
Source File: AbstractPermissionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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());
}
 
Example 20
Source File: AclDaoComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO");
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryService = (DictionaryService) applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE
            .getLocalName());
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
    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");
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    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();
    NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    Map<QName, Serializable> props = createPersonProperties("andy");
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();
    props = createPersonProperties("lemur");
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();

    // create an authentication object e.g. the user
    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(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName());
    }
    authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    
    authenticationComponent.clearCurrentSecurityContext();
}