Search in sources :

Example 1 with AccessDeniedException

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

the class ContentDiskDriver2 method renameFile.

/**
 * Rename the specified file.
 *
 * @param rootNode
 * @param oldName path/name of old file
 * @param newName path/name of new file
 * @exception java.io.IOException The exception description.
 */
public void renameFile(NodeRef rootNode, final String oldName, final String newName, boolean soft, boolean moveAsSystem) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("RenameFile oldName=" + oldName + ", newName=" + newName + ", soft" + soft);
    }
    try {
        // Get the file/folder to move
        final NodeRef nodeToMoveRef = getCifsHelper().getNodeRef(rootNode, oldName);
        if (nodeToMoveRef != null && nodeService.getProperty(nodeToMoveRef, ContentModel.PROP_LINK_DESTINATION) != null) {
            throw new AccessDeniedException("Cannot rename link nodes");
        }
        // Get the new target folder - it must be a folder
        String[] splitPaths = FileName.splitPath(newName);
        String[] oldPaths = FileName.splitPath(oldName);
        final NodeRef targetFolderRef = getCifsHelper().getNodeRef(rootNode, splitPaths[0]);
        final NodeRef sourceFolderRef = getCifsHelper().getNodeRef(rootNode, oldPaths[0]);
        final String name = splitPaths[1];
        // Check if this is a rename within the same folder
        final boolean sameFolder = splitPaths[0].equalsIgnoreCase(oldPaths[0]);
        // Check if we are renaming a folder, or the rename is to a different folder
        boolean isFolder = getCifsHelper().isDirectory(nodeToMoveRef);
        if (isFolder == true || sameFolder == false) {
            // Rename or move the file/folder to another folder
            if (sameFolder == true) {
                fileFolderService.rename(nodeToMoveRef, name);
                if (logger.isDebugEnabled()) {
                    logger.debug("  Renamed " + (isFolder ? "folder" : "file") + ":" + "   Old name:      " + oldName + "\n" + "   New name:      " + newName + "\n");
                }
            } else {
                if (moveAsSystem) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Run move as System for: " + oldName);
                    }
                    AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {

                        public Object doWork() throws Exception {
                            return fileFolderService.moveFrom(nodeToMoveRef, sourceFolderRef, targetFolderRef, name);
                        }
                    }, AuthenticationUtil.getSystemUserName());
                } else {
                    fileFolderService.moveFrom(nodeToMoveRef, sourceFolderRef, targetFolderRef, name);
                }
                logger.debug("Moved between different folders: \n" + "   Old name:      " + oldName + "\n" + "   New name:      " + newName + "\n" + "   Source folder: " + sourceFolderRef + "\n" + "   Target folder: " + targetFolderRef + "\n" + "   Node:          " + nodeToMoveRef + "\n" + "   Aspects:       " + nodeService.getAspects(nodeToMoveRef));
            }
            if (logger.isDebugEnabled()) {
                logger.debug("  Renamed " + (isFolder ? "folder" : "file") + " using " + (sameFolder ? "rename" : "move"));
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Rename file within same folder: \n" + "   Old name:      " + oldName + "\n" + "   New name:      " + newName + "\n" + "   Source folder: " + sourceFolderRef + "\n" + "   Target folder: " + targetFolderRef + "\n" + "   Node:          " + nodeToMoveRef + "\n" + "   Aspects:       " + nodeService.getAspects(nodeToMoveRef));
            }
            if (soft) {
                logger.debug("this is a soft delete - use copy rather than rename");
                fileFolderService.copy(nodeToMoveRef, null, name);
                nodeService.addAspect(nodeToMoveRef, ContentModel.ASPECT_SOFT_DELETE, null);
            } else {
                fileFolderService.rename(nodeToMoveRef, name);
            }
        }
    } catch (org.alfresco.service.cmr.model.FileNotFoundException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Rename file - about to throw file not exists exception file:" + oldName, e);
        }
        throw new java.io.FileNotFoundException("renameFile: file not found file: + oldName");
    } catch (org.alfresco.service.cmr.model.FileExistsException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Rename file - about to throw file exists exception", e);
        }
        throw new org.alfresco.jlan.server.filesys.FileExistsException(newName);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Rename file - about to throw permissions denied exception", ex);
        }
        throw new org.alfresco.jlan.server.filesys.PermissionDeniedException("renameFile: No permissions to rename file:" + oldName);
    } catch (NodeLockedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Rename file - about to throw access denied exception", ex);
        }
        // Convert to an filesystem access denied exception
        throw new AccessDeniedException("renameFile:  Access Denied - Node locked file:" + oldName);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Rename file about to throw access denied exception", ex);
        }
        throw new AlfrescoRuntimeException("renameFile failed: \n" + "   Old name:      " + oldName + "\n" + "   New name:      " + newName + "\n" + ex);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) DiskFullException(org.alfresco.jlan.server.filesys.DiskFullException) IOControlNotImplementedException(org.alfresco.jlan.server.filesys.IOControlNotImplementedException) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileNotFoundException(java.io.FileNotFoundException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) SMBException(org.alfresco.jlan.smb.SMBException) FileNotFoundException(java.io.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException)

Example 2 with AccessDeniedException

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

the class ContentDiskDriver2 method closeFile.

/**
 * Close the file.
 *
 * @exception java.io.IOException If an error occurs.
 * @return node ref of deleted file
 */
public NodeRef closeFile(TreeConnection tree, NodeRef rootNode, String path, NetworkFile file) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Close file:" + path + ", readOnly=" + file.isReadOnly());
    }
    /**
     * Delete on close attribute - node needs to be deleted.
     */
    if (file.hasDeleteOnClose()) {
        NodeRef target = null;
        if (logger.isDebugEnabled()) {
            logger.debug("closeFile has delete on close set path:" + path);
        }
        try {
            target = getCifsHelper().getNodeRef(rootNode, path);
            if (target != null) {
                nodeService.deleteNode(target);
            }
        } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Delete file from close file- access denied", ex);
            }
            // Convert to a filesystem access denied status
            throw new AccessDeniedException("Unable to delete " + path);
        }
        // Still need to close the open file handle.
        file.close();
        if (logger.isDebugEnabled()) {
            logger.debug("Closed file: network file=" + file + " delete on close=" + file.hasDeleteOnClose());
        }
        return target;
    }
    // Check for a temp file - which will be a new file or a read/write file
    if (file instanceof TempNetworkFile) {
        if (logger.isDebugEnabled()) {
            logger.debug("Got a temp network file to close path:" + path);
        }
        // Some content was written to the temp file.
        TempNetworkFile tempFile = (TempNetworkFile) file;
        NodeRef target = getCifsHelper().getNodeRef(rootNode, tempFile.getFullName());
        lockKeeper.removeLock(target);
        if (nodeService.hasAspect(target, ContentModel.ASPECT_NO_CONTENT)) {
            if (logger.isDebugEnabled()) {
                logger.debug("removed no content aspect");
            }
            nodeService.removeAspect(target, ContentModel.ASPECT_NO_CONTENT);
        }
        if (tempFile.isChanged()) {
            tempFile.flushFile();
            tempFile.close();
            /*
                 * Need to work out whether content has changed.  Some odd situations do not change content.
                 */
            boolean contentChanged = true;
            ContentReader existingContent = contentService.getReader(target, ContentModel.PROP_CONTENT);
            if (existingContent != null) {
                existingContent.getSize();
                existingContent.getMimetype();
                contentChanged = isContentChanged(existingContent, tempFile);
                /* 
                     * MNT-248 fix
                     * No need to create a version of a zero byte file
                     */
                if (file.getFileSize() > 0 && existingContent.getSize() == 0 && nodeService.hasAspect(target, ContentModel.ASPECT_VERSIONABLE)) {
                    getPolicyFilter().disableBehaviour(target, ContentModel.ASPECT_VERSIONABLE);
                }
            }
            if (contentChanged) {
                logger.debug("content has changed, need to create a new content item");
                /**
                 * Take over the behaviour of the auditable aspect
                 */
                getPolicyFilter().disableBehaviour(target, ContentModel.ASPECT_AUDITABLE);
                nodeService.setProperty(target, ContentModel.PROP_MODIFIER, authService.getCurrentUserName());
                if (tempFile.isModificationDateSetDirectly()) {
                    logger.debug("modification date set directly");
                    nodeService.setProperty(target, ContentModel.PROP_MODIFIED, new Date(tempFile.getModifyDate()));
                } else {
                    logger.debug("modification date not set directly");
                    nodeService.setProperty(target, ContentModel.PROP_MODIFIED, new Date());
                }
                /**
                 *  Take a guess at the mimetype
                 */
                String mimetype = mimetypeService.guessMimetype(tempFile.getFullName(), new FileContentReader(tempFile.getFile()));
                logger.debug("guesssed mimetype:" + mimetype);
                /**
                 * mime type guessing may have failed in which case we should assume the mimetype has not changed.
                 */
                if (mimetype.equalsIgnoreCase(MimetypeMap.MIMETYPE_BINARY)) {
                    // mimetype guessing may have failed
                    if (existingContent != null) {
                        // copy the mimetype from the existing content.
                        mimetype = existingContent.getMimetype();
                        if (logger.isDebugEnabled()) {
                            logger.debug("using mimetype of existing content :" + mimetype);
                        }
                    }
                }
                String encoding;
                // Take a guess at the locale
                InputStream is = new BufferedInputStream(new FileInputStream(tempFile.getFile()));
                try {
                    ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
                    Charset charset = charsetFinder.getCharset(is, mimetype);
                    encoding = charset.name();
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                        // Ignore
                        }
                    }
                }
                ContentWriter writer = contentService.getWriter(target, ContentModel.PROP_CONTENT, true);
                writer.setMimetype(mimetype);
                writer.setEncoding(encoding);
                writer.putContent(tempFile.getFile());
            }
        // if content changed
        }
    }
    try {
        // Defer to the network file to close the stream and remove the content
        file.close();
        if (logger.isDebugEnabled()) {
            logger.debug("Closed file: network file=" + file + " delete on close=" + file.hasDeleteOnClose() + ", write count" + file.getWriteCount());
            if (file.hasDeleteOnClose() == false && file instanceof ContentNetworkFile) {
                ContentNetworkFile cFile = (ContentNetworkFile) file;
                logger.debug("  File " + file.getFullName() + ", version=" + nodeService.getProperty(cFile.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
            }
        }
        return null;
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception in closeFile - path:" + path, e);
        }
        throw new IOException("Unable to closeFile :" + path + e.toString(), e);
    } catch (Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception in closeFile - path:" + path, e);
        }
        throw e;
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ContentCharsetFinder(org.alfresco.repo.content.encoding.ContentCharsetFinder) Charset(java.nio.charset.Charset) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) Date(java.util.Date) FileInputStream(java.io.FileInputStream) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) BufferedInputStream(java.io.BufferedInputStream)

Example 3 with AccessDeniedException

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

the class ContentDiskDriver2 method deleteDirectory.

/**
 * Delete the directory from the filesystem.
 * <p>
 * The directory must be empty in order to be able to delete ity
 *
 * @param session Server session
 * @param tree Tree connection
 * @param dir Directory name.
 * @exception java.io.IOException The exception description.
 */
public void deleteDirectory(SrvSession session, TreeConnection tree, final String dir) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("deleteDirectory: " + dir + ", session:" + session.getUniqueId());
    }
    ContentContext ctx = (ContentContext) tree.getContext();
    final NodeRef deviceRootNodeRef = ctx.getRootNode();
    try {
        // Get the node for the folder
        NodeRef nodeRef = getCifsHelper().getNodeRef(deviceRootNodeRef, dir);
        if (fileFolderService.exists(nodeRef)) {
            // Check if the folder is empty
            if (getCifsHelper().isFolderEmpty(nodeRef)) {
                // Delete the folder node
                fileFolderService.delete(nodeRef);
            } else {
                throw new DirectoryNotEmptyException(dir);
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Deleted directory: directory=" + dir + " node=" + nodeRef);
        }
    // void return
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete directory - file not found, " + dir);
        }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete directory - access denied, " + dir);
        }
        throw new AccessDeniedException("Delete directory, access denied :" + dir);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Delete directory", ex);
        throw new IOException("Delete directory " + dir, ex);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException)

Example 4 with AccessDeniedException

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

the class ContentDiskDriver2 method getFileInformation.

/**
 * Get the file information for the specified file.
 *
 * @param session Server session
 * @param tree Tree connection
 * @param path File name/path that information is required for.
 * @return File information if valid, else null
 * @exception java.io.IOException The exception description.
 */
public FileInfo getFileInformation(SrvSession session, TreeConnection tree, String path) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("getFileInformation:" + path + ", session:" + session.getUniqueId());
    }
    ContentContext ctx = (ContentContext) tree.getContext();
    boolean readOnly = !m_transactionService.getAllowWrite();
    if (path == null || path.length() == 0) {
        path = FileName.DOS_SEPERATOR_STR;
    }
    String infoPath = path;
    try {
        FileInfo finfo = null;
        NodeRef nodeRef = getNodeForPath(tree, infoPath);
        if (nodeRef != null) {
            // Get the file information for the node
            finfo = getCifsHelper().getFileInformation(nodeRef, readOnly, isLockedFilesAsOffline);
            /**
             * Special processing for root node
             */
            if (path.equals(FileName.DOS_SEPERATOR_STR)) {
                finfo.setFileName("");
            }
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("getFileInformation found nodeRef for nodeRef :" + nodeRef + ", path: " + path);
            }
        // Moved to CIFS Helper
        // // Set the file id from the node's DBID
        // long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
        // finfo.setFileId((int) (id & 0xFFFFFFFFL));
        }
        // Return the file information or null if the node ref does not exist
        return finfo;
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled()) {
            // exception not logged - cifs does lots of these
            logger.debug("Get file info - file not found, " + path);
        }
        throw e;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Get file info - access denied, " + path, ex);
        }
        // Convert to a filesystem access denied status
        throw new AccessDeniedException("Get file information " + path);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Get file info error" + path, ex);
        }
        // Convert to a general I/O exception
        throw new IOException("Get file information " + path, ex);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 5 with AccessDeniedException

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

the class ContentDiskDriver2 method openFile.

/**
 * Open the file - Repo Specific implementation
 */
public NetworkFile openFile(SrvSession session, TreeConnection tree, NodeRef rootNode, String path, OpenFileMode mode, boolean truncate) throws IOException {
    ContentContext ctx = (ContentContext) tree.getContext();
    if (logger.isDebugEnabled()) {
        logger.debug("openFile :" + path + ", mode:" + mode);
    }
    try {
        String name = path;
        NodeRef nodeRef = getNodeForPath(rootNode, path);
        boolean readOnly = false;
        // Check permissions on the file/folder
        switch(mode) {
            case READ_ONLY:
            // follow through
            case ATTRIBUTES_ONLY:
                if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("about to throw an no read access denied exception path:" + path);
                    }
                    throw new AccessDeniedException("No read access to " + path);
                }
                readOnly = true;
                break;
            case READ_WRITE:
            case WRITE_ONLY:
                if (!m_transactionService.getAllowWrite()) {
                    throw new AccessDeniedException("Repo is write only, No write access to " + path);
                }
                if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) == AccessStatus.DENIED) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("about to throw an no write access denied exception path:" + path);
                    }
                    throw new AccessDeniedException("No write access to " + path);
                }
                lockService.checkForLock(nodeRef);
                readOnly = false;
                break;
            case DELETE:
                if (!m_transactionService.getAllowWrite()) {
                    throw new AccessDeniedException("Repo is write only, No write access to " + path);
                }
                lockService.checkForLock(nodeRef);
        }
        // Check if the node is a link node
        NodeRef linkRef = (NodeRef) nodeService.getProperty(nodeRef, ContentModel.PROP_LINK_DESTINATION);
        NetworkFile netFile = null;
        if (linkRef == null) {
            // A normal node, not a link node
            // TODO MER REWRITE HERE
            FileInfo fileInfo = cifsHelper.getFileInformation(nodeRef, "", false, false);
            // TODO this is wasteful - the isDirectory is in the params.   We should split off an openDirectory method.
            if (fileInfo.isDirectory()) {
                logger.debug("open file - is a directory!");
                netFile = new AlfrescoFolder(path, fileInfo, readOnly);
            } else {
                // A normal file
                switch(mode) {
                    case READ_ONLY:
                        logger.debug("open file for read only");
                        netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, false, session);
                        netFile.setGrantedAccess(NetworkFile.READONLY);
                        break;
                    case READ_WRITE:
                        {
                            logger.debug("open file for read write");
                            File file = TempFileProvider.createTempFile("cifs", ".bin");
                            lockKeeper.addLock(nodeRef);
                            if (!truncate) {
                                // Need to open a temp file with a copy of the content.
                                ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
                                if (reader != null) {
                                    reader.getContent(file);
                                }
                            }
                            netFile = new TempNetworkFile(file, name);
                            netFile.setCreationDate(fileInfo.getCreationDateTime());
                            netFile.setModifyDate(fileInfo.getModifyDateTime());
                            netFile.setGrantedAccess(NetworkFile.READWRITE);
                            if (truncate) {
                                netFile.truncateFile(0);
                            }
                            if (logger.isDebugEnabled()) {
                                logger.debug("Created file: path=" + name + " node=" + nodeRef + " network file=" + netFile);
                            }
                        }
                        break;
                    case ATTRIBUTES_ONLY:
                        logger.debug("open file for attributes only");
                        netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, true, session);
                        netFile.setGrantedAccess(NetworkFile.READONLY);
                        break;
                    case DELETE:
                        // TODO Not sure about this one.
                        logger.debug("open file for delete");
                        netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, false, session);
                        netFile.setGrantedAccess(NetworkFile.READONLY);
                        break;
                    case WRITE_ONLY:
                        {
                            // consider this as open read/write/truncate)
                            logger.debug("open file write only");
                            File file = TempFileProvider.createTempFile("cifs", ".bin");
                            netFile = new TempNetworkFile(file, name);
                            // Needs to be READWRITE for JavaNetworkFile - there's no such thing as WRITEONLY!
                            netFile.setGrantedAccess(NetworkFile.READWRITE);
                            if (logger.isDebugEnabled()) {
                                logger.debug("Created temporary file: path=" + name + " node=" + nodeRef + " network file=" + netFile);
                            }
                        }
                }
            }
        // end of a normal file
        } else {
            // This is a link node
            // TODO - This server name stuff should be replaced In particular the
            // See PseudoFileOverlayImp
            // Get the CIFS server name
            String srvName = null;
            SMBServer cifsServer = (SMBServer) session.getServer().getConfiguration().findServer("CIFS");
            if (session instanceof SMBSrvSession) {
                SMBSrvSession smbSess = (SMBSrvSession) session;
                srvName = smbSess.getShareHostName();
            } else if (cifsServer != null) {
                // Use the CIFS server name in the URL
                srvName = cifsServer.getServerName();
            } else {
                // Use the local server name in the URL
                srvName = InetAddress.getLocalHost().getHostName();
            }
            // Convert the target node to a path, convert to URL format
            String pathl = getPathForNode(rootNode, linkRef);
            path = pathl.replace(FileName.DOS_SEPERATOR, '/');
            String lnkForWinPath = convertStringToUnicode(path);
            // Build the URL file data
            StringBuilder urlStr = new StringBuilder();
            urlStr.append("[InternetShortcut]\r\n");
            urlStr.append("URL=file://");
            urlStr.append(srvName);
            urlStr.append("/");
            urlStr.append(tree.getSharedDevice().getName());
            urlStr.append(lnkForWinPath);
            urlStr.append("\r\n");
            // Create the in memory pseudo file for the URL link
            byte[] urlData = urlStr.toString().getBytes();
            // Get the file information for the link node
            FileInfo fInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline);
            // Set the file size to the actual data length
            fInfo.setFileSize(urlData.length);
            // Create the network file using the in-memory file data
            netFile = new LinkMemoryNetworkFile(fInfo.getFileName(), urlData, fInfo, nodeRef);
            netFile.setFullName(pathl);
        }
        if (netFile != null) {
            long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
            netFile.setFileId((int) (id & 0xFFFFFFFFL));
            // Indicate the file is open
            netFile.setClosed(false);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Opened network file: path=" + path + " network file=" + netFile);
        }
        return netFile;
    } catch (NodeLockedException nle) {
        if (logger.isDebugEnabled()) {
            logger.debug("Open file - node is locked, " + path);
        }
        throw new AccessDeniedException("File is locked, no write access to " + path);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Open file - access denied, " + path);
        }
        throw new AccessDeniedException("Open file " + path);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Open file error", ex);
        }
        throw new IOException("Open file " + path, ex);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) SMBServer(org.alfresco.jlan.smb.server.SMBServer) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) SMBSrvSession(org.alfresco.jlan.smb.server.SMBSrvSession) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) File(java.io.File)

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