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;
}
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);
}
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
}
Aggregations