Search in sources :

Example 11 with AccessDeniedException

use of org.alfresco.jlan.server.filesys.AccessDeniedException in project alfresco-repository by Alfresco.

the class NonTransactionalRuleContentDiskDriver method openFile.

@Override
public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams param) throws IOException {
    String path = param.getPath();
    boolean truncate = param.isOverwrite();
    if (logger.isDebugEnabled()) {
        int sharedAccess = param.getSharedAccess();
        String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);
        logger.debug("openFile:" + path + ", isDirectory: " + param.isDirectory() + ", isStream: " + param.isStream() + ", readOnlyAccess: " + param.isReadOnlyAccess() + ", readWriteAccess: " + param.isReadWriteAccess() + ", writeOnlyAccess:" + param.isWriteOnlyAccess() + ", attributesOnlyAccess:" + param.isAttributesOnlyAccess() + ", sequentialAccessOnly:" + param.isSequentialAccessOnly() + ", writeThrough:" + param.isWriteThrough() + ", truncate:" + truncate + ", requestBatchOpLock:" + param.requestBatchOpLock() + ", requestExclusiveOpLock:" + param.requestExclusiveOpLock() + ", isDeleteOnClose:" + param.isDeleteOnClose() + ", allocationSize:" + param.getAllocationSize() + ", sharedAccess: " + strSharedAccess + ", openAction: " + param.getOpenAction() + param);
    }
    ContentContext tctx = (ContentContext) tree.getContext();
    NodeRef rootNode = tctx.getRootNode();
    DriverState driverState = getDriverState(sess);
    String[] paths = FileName.splitPath(path);
    String folder = paths[0];
    String file = paths[1];
    EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
    OpenFileMode openMode = OpenFileMode.READ_ONLY;
    if (param.isAttributesOnlyAccess()) {
        openMode = OpenFileMode.ATTRIBUTES_ONLY;
    } else if (param.isReadWriteAccess()) {
        openMode = OpenFileMode.READ_WRITE;
    } else if (param.isWriteOnlyAccess()) {
        openMode = OpenFileMode.WRITE_ONLY;
    } else if (param.isReadOnlyAccess()) {
        openMode = OpenFileMode.READ_ONLY;
    } else if (param.isDeleteOnClose()) {
        if (logger.isDebugEnabled()) {
            logger.debug("open file has delete on close");
        }
        openMode = OpenFileMode.DELETE;
    }
    try {
        Operation o = new OpenFileOperation(file, openMode, truncate, rootNode, path);
        Command c = ruleEvaluator.evaluate(ctx, o);
        Object ret = commandExecutor.execute(sess, tree, c);
        if (ret != null && ret instanceof NetworkFile) {
            NetworkFile x = (NetworkFile) ret;
            if (logger.isDebugEnabled()) {
                logger.debug("returning open file: for path:" + path + ", ret:" + ret);
            }
            return x;
        } else {
            // Error - contact broken
            logger.error("contract broken - NetworkFile not returned. " + ret == null ? "Return value is null" : ret);
            return null;
        }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
        throw new AccessDeniedException("Unable to open file " + param.getPath(), ade);
    }
// return diskInterface.openFile(sess, tree, params);
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext) OpenFileOperation(org.alfresco.filesys.repo.rules.operations.OpenFileOperation) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation) Operation(org.alfresco.filesys.repo.rules.Operation) MoveFileOperation(org.alfresco.filesys.repo.rules.operations.MoveFileOperation) CloseFileOperation(org.alfresco.filesys.repo.rules.operations.CloseFileOperation) OpenFileOperation(org.alfresco.filesys.repo.rules.operations.OpenFileOperation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Example 12 with AccessDeniedException

use of org.alfresco.jlan.server.filesys.AccessDeniedException in project alfresco-repository by Alfresco.

the class NonTransactionalRuleContentDiskDriver method deleteFile.

@Override
public void deleteFile(SrvSession sess, TreeConnection tree, String name) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("deleteFile name:" + name);
    }
    try {
        ContentContext tctx = (ContentContext) tree.getContext();
        NodeRef rootNode = tctx.getRootNode();
        DriverState driverState = getDriverState(sess);
        String[] paths = FileName.splitPath(name);
        String folder = paths[0];
        String file = paths[1];
        EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
        Operation o = new DeleteFileOperation(file, rootNode, name);
        Command c = ruleEvaluator.evaluate(ctx, o);
        commandExecutor.execute(sess, tree, c);
        releaseEvaluatorContextIfEmpty(driverState, ctx, folder);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
        throw new AccessDeniedException("Unable to delete file " + name, ade);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) OpenFileOperation(org.alfresco.filesys.repo.rules.operations.OpenFileOperation) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation) Operation(org.alfresco.filesys.repo.rules.Operation) MoveFileOperation(org.alfresco.filesys.repo.rules.operations.MoveFileOperation) CloseFileOperation(org.alfresco.filesys.repo.rules.operations.CloseFileOperation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command)

Example 13 with AccessDeniedException

use of org.alfresco.jlan.server.filesys.AccessDeniedException in project alfresco-repository by Alfresco.

the class ContentDiskDriver2 method createDirectory.

/**
 * Create a new directory on this file system.
 *
 * @param sess Server session
 * @param tree Tree connection.
 * @param params Directory create parameters
 * @exception java.io.IOException If an error occurs.
 */
public void createDirectory(SrvSession sess, final TreeConnection tree, final FileOpenParams params) throws IOException {
    final ContentContext ctx = (ContentContext) tree.getContext();
    if (logger.isDebugEnabled()) {
        logger.debug("createDirectory :" + params);
    }
    try {
        NodeRef dirNodeRef;
        String folderName;
        String path = params.getPath();
        String[] paths = FileName.splitPath(path);
        if (paths[0] != null && paths[0].length() > 1) {
            // lookup parent directory
            dirNodeRef = getNodeForPath(tree, paths[0]);
            folderName = paths[1];
        } else {
            dirNodeRef = ctx.getRootNode();
            folderName = path;
        }
        if (dirNodeRef == null) {
            throw new IOException("Create directory parent folder not found" + params.getFullPath());
        }
        NodeRef nodeRef = getCifsHelper().createNode(dirNodeRef, folderName, ContentModel.TYPE_FOLDER);
        if (logger.isDebugEnabled()) {
            logger.debug("Created directory: path=" + params.getPath() + " file open params=" + params + " node=" + nodeRef);
        }
    // void return
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create directory - access denied, " + params.getFullPath());
        }
        throw new AccessDeniedException("Create directory " + params.getFullPath());
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create directory error", ex);
        }
        throw new IOException("Create directory " + params.getFullPath(), ex);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException)

Example 14 with AccessDeniedException

use of org.alfresco.jlan.server.filesys.AccessDeniedException in project alfresco-repository by Alfresco.

the class ContentDiskDriver2 method createFile.

@Override
public NetworkFile createFile(NodeRef rootNode, String path, long allocationSize, boolean isHidden) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("createFile :" + path);
    }
    try {
        NodeRef dirNodeRef;
        String folderName;
        String[] paths = FileName.splitPath(path);
        if (paths[0] != null && paths[0].length() > 1) {
            // lookup parent directory
            dirNodeRef = getNodeForPath(rootNode, paths[0]);
            folderName = paths[1];
        } else {
            dirNodeRef = rootNode;
            folderName = path;
        }
        boolean soft = false;
        NodeRef existing = fileFolderService.searchSimple(dirNodeRef, folderName);
        if (existing != null) {
            if (nodeService.hasAspect(existing, ContentModel.ASPECT_SOFT_DELETE)) {
                logger.debug("existing node has soft delete aspect");
                soft = true;
            }
        }
        NodeRef nodeRef = null;
        if (soft) {
            nodeRef = existing;
        } else {
            nodeRef = cifsHelper.createNode(dirNodeRef, folderName, ContentModel.TYPE_CONTENT);
            nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null);
            lockKeeper.addLock(nodeRef);
        }
        if (isHidden) {
            // yes is hidden
            if (logger.isDebugEnabled()) {
                logger.debug("Set hidden aspect, nodeRef:" + nodeRef);
            }
            hiddenAspect.hideNodeExplicit(nodeRef);
        }
        File file = TempFileProvider.createTempFile("cifs", ".bin");
        TempNetworkFile netFile = new TempNetworkFile(file, path);
        netFile.setChanged(true);
        Serializable created = nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED);
        if (created != null && created instanceof Date) {
            Date d = (Date) created;
            if (logger.isDebugEnabled()) {
                logger.debug("replacing create date to date:" + d);
            }
            netFile.setCreationDate(d.getTime());
            netFile.setModifyDate(d.getTime());
        }
        // Always allow write access to a newly created file
        netFile.setGrantedAccess(NetworkFile.READWRITE);
        netFile.setAllowedAccess(NetworkFile.READWRITE);
        if (netFile != null) {
            long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
            netFile.setFileId((int) (id & 0xFFFFFFFFL));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Created file: path=" + path + " node=" + nodeRef + " network file=" + netFile);
        }
        return netFile;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create file - access denied, " + path);
        }
        throw new AccessDeniedException("Unable to create file " + path);
    } catch (IOException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create file - content I/O error, " + path);
        }
        throw ex;
    } catch (ContentIOException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create file - content I/O error, " + path);
        }
        throw new DiskFullException("Unable to create file " + path);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create file error", ex);
        }
        throw new IOException("Unable to create file " + path, ex);
    }
}
Also used : Serializable(java.io.Serializable) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) Date(java.util.Date) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DiskFullException(org.alfresco.jlan.server.filesys.DiskFullException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) File(java.io.File)

Example 15 with AccessDeniedException

use of org.alfresco.jlan.server.filesys.AccessDeniedException in project alfresco-repository by Alfresco.

the class ContentDiskDriver2 method setFileInformation.

/**
 * Set file information
 *
 * @param sess SrvSession
 * @param tree TreeConnection
 * @param name String
 * @param info FileInfo
 * @exception IOException
 */
public void setFileInformation(SrvSession sess, final TreeConnection tree, final String name, final FileInfo info) throws IOException {
    // Get the device context
    final ContentContext ctx = (ContentContext) tree.getContext();
    if (logger.isDebugEnabled()) {
        logger.debug("setFileInformation name=" + name + ", info=" + info);
    }
    NetworkFile networkFile = info.getNetworkFile();
    try {
        // Get the file/folder node
        NodeRef nodeRef = getNodeForPath(tree, name);
        if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) == AccessStatus.DENIED) {
            if (logger.isDebugEnabled()) {
                logger.debug("write access denied to :" + name);
            }
            throw new AccessDeniedException("No write access to " + name);
        }
        // Inhibit versioning for this transaction
        getPolicyFilter().disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
        /* 
            * Which DeleteOnClose flag has priority?
            * SetDeleteOnClose is not set or used in this method.   
            * The NTProtocolHandler sets the deleteOnClose in both
            * info and the NetworkFile - it's the one in NetworkFile that results in the file being deleted.
            */
        if (info.hasSetFlag(FileInfo.SetDeleteOnClose) && info.hasDeleteOnClose()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set Delete On Close for :" + name);
            }
            // Check for delete permission
            if (permissionService.hasPermission(nodeRef, PermissionService.DELETE) == AccessStatus.DENIED) {
                throw new PermissionDeniedException("No delete access to :" + name);
            }
            // Check if the node is locked
            lockService.checkForLock(nodeRef);
            if (fileFolderService.exists(nodeRef)) {
                // Check if it is a folder that is being deleted, make sure it is empty
                boolean isFolder = true;
                ContentFileInfo cInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline);
                if (cInfo != null && cInfo.isDirectory() == false) {
                    isFolder = false;
                }
                // Check if the folder is empty
                if (isFolder == true && getCifsHelper().isFolderEmpty(nodeRef) == false) {
                    throw new DirectoryNotEmptyException(name);
                }
            }
        }
        if (info.hasSetFlag(FileInfo.SetAttributes)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set attributes" + name + ", file attrs = " + info.getFileAttributes());
            }
            // TODO MER Think we may need to implement, Temporary, Hidden, System, Archive
            if (info.isSystem()) {
                logger.debug("Set system aspect (not yet implemented)" + name);
            }
            if (info.isTemporary()) {
                logger.debug("Set temporary aspect (not yet implemented)" + name);
            }
            if (info.isHidden()) {
                // yes is hidden
                if (logger.isDebugEnabled()) {
                    logger.debug("Set hidden aspect" + name);
                }
                hiddenAspect.hideNodeExplicit(nodeRef);
            } else {
                // not hidden
                if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Reset hidden aspect" + name);
                    }
                    hiddenAspect.unhideExplicit(nodeRef);
                }
            }
        }
        if (info.hasSetFlag(FileInfo.SetAllocationSize)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set allocation size" + name + info.getAllocationSize());
            }
        // Not yet implemented
        }
        if (info.hasSetFlag(FileInfo.SetFileSize)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set file size" + name + info.getSize());
            }
        // Not yet implemented
        }
        if (info.hasSetFlag(FileInfo.SetMode)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set Mode" + name + info.getMode());
            }
        // Not yet implemented - set the unix mode e.g. 777
        }
        // Set the creation and modified date/time
        Map<QName, Serializable> auditableProps = new HashMap<QName, Serializable>(5);
        if (info.hasSetFlag(FileInfo.SetCreationDate) && info.hasCreationDateTime()) {
            // Set the creation date on the file/folder node
            Date createDate = new Date(info.getCreationDateTime());
            auditableProps.put(ContentModel.PROP_CREATED, createDate);
            if (logger.isDebugEnabled()) {
                logger.debug("Set creation date" + name + ", " + createDate);
            }
        }
        if (info.hasSetFlag(FileInfo.SetModifyDate) && info.hasModifyDateTime()) {
            // Set the modification date on the file/folder node
            Date modifyDate = new Date(info.getModifyDateTime());
            auditableProps.put(ContentModel.PROP_MODIFIED, modifyDate);
            // Set the network file so we don't reverse this change in close file.
            if (networkFile != null && !networkFile.isReadOnly()) {
                networkFile.setModifyDate(info.getModifyDateTime());
                if (networkFile instanceof TempNetworkFile) {
                    TempNetworkFile tnf = (TempNetworkFile) networkFile;
                    tnf.setModificationDateSetDirectly(true);
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Set modification date" + name + ", " + modifyDate);
            }
        }
        // Change Date is last write ?
        if (info.hasSetFlag(FileInfo.SetChangeDate) && info.hasChangeDateTime()) {
            Date changeDate = new Date(info.getChangeDateTime());
            if (logger.isDebugEnabled()) {
                logger.debug("Set change date (Not implemented)" + name + ", " + changeDate);
            }
        }
        if (info.hasSetFlag(FileInfo.SetAccessDate) && info.hasAccessDateTime()) {
            Date accessDate = new Date(info.getAccessDateTime());
            if (logger.isDebugEnabled()) {
                logger.debug("Set access date (Not implemented)" + name + ", " + accessDate);
            }
        }
        // Did we have any cm:auditable properties?
        if (auditableProps.size() > 0) {
            getPolicyFilter().disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
            nodeService.addProperties(nodeRef, auditableProps);
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("Set auditable props: " + auditableProps + " file=" + name);
            }
        }
        return;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Set file information - access denied, " + name);
        }
        // Convert to a filesystem access denied status
        throw new AccessDeniedException("Set file information " + name);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Open file error", ex);
        }
        throw new IOException("Set file information " + name, ex);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Aggregations

AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)25 NodeRef (org.alfresco.service.cmr.repository.NodeRef)24 IOException (java.io.IOException)19 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)18 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)17 FileNotFoundException (java.io.FileNotFoundException)11 FileState (org.alfresco.jlan.server.filesys.cache.FileState)9 DirectoryNotEmptyException (org.alfresco.jlan.server.filesys.DirectoryNotEmptyException)8 FileInfo (org.alfresco.jlan.server.filesys.FileInfo)7 Date (java.util.Date)6 DiskFullException (org.alfresco.jlan.server.filesys.DiskFullException)6 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)6 NodeLockedException (org.alfresco.service.cmr.lock.NodeLockedException)6 Command (org.alfresco.filesys.repo.rules.Command)5 EvaluatorContext (org.alfresco.filesys.repo.rules.EvaluatorContext)5 Operation (org.alfresco.filesys.repo.rules.Operation)5 CloseFileOperation (org.alfresco.filesys.repo.rules.operations.CloseFileOperation)5 CreateFileOperation (org.alfresco.filesys.repo.rules.operations.CreateFileOperation)5 DeleteFileOperation (org.alfresco.filesys.repo.rules.operations.DeleteFileOperation)5 MoveFileOperation (org.alfresco.filesys.repo.rules.operations.MoveFileOperation)5