Search in sources :

Example 1 with ExtendedDiskInterface

use of org.alfresco.filesys.alfresco.ExtendedDiskInterface in project alfresco-repository by Alfresco.

the class ServerConfigurationBean method isContentDiskDriver2.

/**
 * Returns true if either: the disk interface is a ContentDiskDriver2; or
 * the disk interface is a {@link BufferedContentDiskDriver} and its disk
 * interface is a ContentDiskDriver2 (wrapped by several other DiskInterface objects).
 *
 * @param diskInterface ExtendedDiskInterface
 * @return boolean
 */
private boolean isContentDiskDriver2(ExtendedDiskInterface diskInterface) {
    if (diskInterface instanceof ContentDiskDriver2) {
        return true;
    }
    if (diskInterface instanceof BufferedContentDiskDriver) {
        BufferedContentDiskDriver bufferedDriver = (BufferedContentDiskDriver) diskInterface;
        ExtendedDiskInterface underlyingDriver = bufferedDriver.getDiskInterface();
        if (underlyingDriver instanceof LegacyFileStateDriver) {
            LegacyFileStateDriver legacyDriver = (LegacyFileStateDriver) underlyingDriver;
            underlyingDriver = legacyDriver.getDiskInterface();
            if (underlyingDriver instanceof NonTransactionalRuleContentDiskDriver) {
                // say for sure if it is a ContentDiskDriver2.
                return true;
            }
        }
    }
    return false;
}
Also used : ContentDiskDriver2(org.alfresco.filesys.repo.ContentDiskDriver2) BufferedContentDiskDriver(org.alfresco.filesys.repo.BufferedContentDiskDriver) NonTransactionalRuleContentDiskDriver(org.alfresco.filesys.repo.NonTransactionalRuleContentDiskDriver) LegacyFileStateDriver(org.alfresco.filesys.repo.LegacyFileStateDriver) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface)

Example 2 with ExtendedDiskInterface

use of org.alfresco.filesys.alfresco.ExtendedDiskInterface in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testFileInformationUpdatingByEditorUserForAlf8808.

// testDirListing
public void testFileInformationUpdatingByEditorUserForAlf8808() throws Exception {
    final Holder<org.alfresco.service.cmr.model.FileInfo> editorFolder = new Holder<org.alfresco.service.cmr.model.FileInfo>();
    final Holder<org.alfresco.service.cmr.model.FileInfo> testFile = new Holder<org.alfresco.service.cmr.model.FileInfo>();
    // Configuring test server with test server configuration and getting test tree connection for test shared device
    ServerConfiguration config = new ServerConfiguration(ContentDiskDriverTest.TEST_SERVER_NAME);
    TestServer server = new TestServer(ContentDiskDriverTest.TEST_SERVER_NAME, config);
    DiskSharedDevice device = getDiskSharedDevice();
    final TreeConnection treeConnection = server.getTreeConnection(device);
    // Getting target entity for testing - ContentDiskDriver
    final ExtendedDiskInterface deviceInterface = (ExtendedDiskInterface) treeConnection.getInterface();
    // Creating mock-session
    final SrvSession session = new TestSrvSession(13, server, ContentDiskDriverTest.TEST_PROTOTYPE_NAME, ContentDiskDriverTest.TEST_REMOTE_NAME);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                NodeRef rootNode = repositoryHelper.getCompanyHome();
                // Creating test user to invite him as Editor for test content. This user will be created correctly (with person and authentication options)
                createUser(ContentDiskDriverTest.TEST_USER_AUTHORITY, ContentDiskDriverTest.TEST_USER_AUTHORITY, rootNode);
                // Safely creating folder for test content
                editorFolder.value = getOrCreateNode(rootNode, PermissionService.EDITOR, ContentModel.TYPE_FOLDER).getFirst();
                // Creating test content which will be editable by user created above
                testFile.value = getOrCreateNode(rootNode, "Test.txt", ContentModel.TYPE_CONTENT).getFirst();
                // Applying 'Editor' role for test user to test file
                permissionService.setPermission(testFile.value.getNodeRef(), ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);
                try {
                    // Creating data for target method invocation
                    final FileInfo updatedInfo = new FileInfo();
                    updatedInfo.setFileName(testFile.value.getName());
                    updatedInfo.setFileId(DefaultTypeConverter.INSTANCE.intValue(testFile.value.getProperties().get(ContentModel.PROP_NODE_DBID)));
                    // Testing ContentDiskDriver.setFileInformation() with test user authenticated who has 'Editor' role for test content.
                    // This method should fail if check on 'DELETE' permission was not moved to 'DeleteOnClose' context
                    AuthenticationUtil.runAs(new RunAsWork<Void>() {

                        @Override
                        public Void doWork() throws Exception {
                            deviceInterface.setFileInformation(session, treeConnection, testFile.value.getName(), updatedInfo);
                            return null;
                        }
                    }, ContentDiskDriverTest.TEST_USER_AUTHORITY);
                } catch (Exception e) {
                    // Informing about test failure. Expected exception is 'org.alfresco.jlan.server.filesys.AccessDeniedException'
                    if (e.getCause() instanceof AccessDeniedException) {
                        fail("For user='" + TEST_USER_AUTHORITY + "' " + e.getCause().toString());
                    } else {
                        fail("Unexpected exception was caught: " + e.toString());
                    }
                }
            } finally {
                if (authenticationService.authenticationExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    authenticationService.deleteAuthentication(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }
                if (personService.personExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    personService.deletePerson(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }
                try {
                    if (null != testFile.value) {
                        nodeService.deleteNode(testFile.value.getNodeRef());
                    }
                } catch (Exception e) {
                // Doing nothing
                }
                try {
                    if (null != editorFolder.value) {
                        nodeService.deleteNode(editorFolder.value.getNodeRef());
                    }
                } catch (Exception e) {
                // Doing nothing
                }
            }
            return null;
        }
    }, false, true);
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) SrvSession(org.alfresco.jlan.server.SrvSession) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface) Holder(javax.xml.ws.Holder) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 3 with ExtendedDiskInterface

use of org.alfresco.filesys.alfresco.ExtendedDiskInterface in project alfresco-repository by Alfresco.

the class ServerConfigurationBean method processFilesystemsConfig.

/**
 * Process the filesystems configuration
 */
protected void processFilesystemsConfig() {
    // Create the filesystems configuration section
    FilesystemsConfigSection fsysConfig = new FilesystemsConfigSection(this);
    // Access the security configuration section
    SecurityConfigSection secConfig = (SecurityConfigSection) getConfigSection(SecurityConfigSection.SectionName);
    if (this.filesystemContexts != null) {
        for (DeviceContext filesystem : this.filesystemContexts) {
            try {
                // Check the filesystem type and use the appropriate driver
                DiskSharedDevice filesys = null;
                // Create a new filesystem driver instance and register a context for
                // the new filesystem
                ExtendedDiskInterface filesysDriver = getRepoDiskInterface();
                ContentContext filesysContext = (ContentContext) filesystem;
                // Create state cache here and inject
                StandaloneFileStateCache standaloneCache = new StandaloneFileStateCache();
                standaloneCache.initializeCache(new GenericConfigElement(""), this);
                filesysContext.setStateCache(standaloneCache);
                if (filesysContext.hasStateCache()) {
                    // Register the state cache with the reaper thread
                    // has many side effects including initialisation of the cache
                    fsysConfig.addFileStateCache(filesystem.getDeviceName(), filesysContext.getStateCache());
                    // Create the lock manager for the context.
                    FileStateLockManager lockMgr = new FileStateLockManager(filesysContext.getStateCache());
                    filesysContext.setLockManager(lockMgr);
                    filesysContext.setOpLockManager(lockMgr);
                }
                if (!ftpConfigBean.getServerEnabled() && isContentDiskDriver2(filesysDriver)) {
                    ((ContentContext) filesystem).setDisableNodeMonitor(true);
                }
                filesysDriver.registerContext(filesystem);
                // Check if an access control list has been specified
                AccessControlList acls = null;
                AccessControlListBean accessControls = filesysContext.getAccessControlList();
                if (accessControls != null) {
                    // Parse the access control list
                    acls = accessControls.toAccessControlList(secConfig);
                } else if (secConfig.hasGlobalAccessControls()) {
                    // Use the global access control list for this disk share
                    acls = secConfig.getGlobalAccessControls();
                }
                // Create the shared filesystem
                filesys = new DiskSharedDevice(filesystem.getDeviceName(), filesysDriver, filesysContext);
                filesys.setConfiguration(this);
                // Add any access controls to the share
                filesys.setAccessControlList(acls);
                if (filesysContext.getDisableChangeNotifications() == false)
                    filesysContext.enableChangeHandler(true);
                // Start the filesystem
                filesysContext.startFilesystem(filesys);
                // Add the new filesystem
                fsysConfig.addShare(filesys);
            } catch (DeviceContextException ex) {
                throw new AlfrescoRuntimeException("Error creating filesystem " + filesystem.getDeviceName(), ex);
            } catch (InvalidConfigurationException ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }
    } else {
        // No filesystems defined
        logger.warn("No filesystems defined");
    }
// home folder share mapper could be declared in security config
}
Also used : AccessControlList(org.alfresco.jlan.server.auth.acl.AccessControlList) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) SecurityConfigSection(org.alfresco.jlan.server.config.SecurityConfigSection) GenericConfigElement(org.springframework.extensions.config.element.GenericConfigElement) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface) StandaloneFileStateCache(org.alfresco.jlan.server.filesys.cache.StandaloneFileStateCache) AccessControlListBean(org.alfresco.filesys.config.acl.AccessControlListBean) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException) FilesystemsConfigSection(org.alfresco.jlan.server.filesys.FilesystemsConfigSection) DeviceContext(org.alfresco.jlan.server.core.DeviceContext) FileStateLockManager(org.alfresco.jlan.server.filesys.cache.FileStateLockManager) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ContentContext(org.alfresco.filesys.repo.ContentContext) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Aggregations

ExtendedDiskInterface (org.alfresco.filesys.alfresco.ExtendedDiskInterface)3 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)2 DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Holder (javax.xml.ws.Holder)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AccessControlListBean (org.alfresco.filesys.config.acl.AccessControlListBean)1 BufferedContentDiskDriver (org.alfresco.filesys.repo.BufferedContentDiskDriver)1 ContentContext (org.alfresco.filesys.repo.ContentContext)1 ContentDiskDriver2 (org.alfresco.filesys.repo.ContentDiskDriver2)1 LegacyFileStateDriver (org.alfresco.filesys.repo.LegacyFileStateDriver)1 NonTransactionalRuleContentDiskDriver (org.alfresco.filesys.repo.NonTransactionalRuleContentDiskDriver)1 SrvSession (org.alfresco.jlan.server.SrvSession)1 AccessControlList (org.alfresco.jlan.server.auth.acl.AccessControlList)1 InvalidConfigurationException (org.alfresco.jlan.server.config.InvalidConfigurationException)1 SecurityConfigSection (org.alfresco.jlan.server.config.SecurityConfigSection)1 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)1 DeviceContext (org.alfresco.jlan.server.core.DeviceContext)1 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)1