use of org.alfresco.jlan.server.filesys.PermissionDeniedException 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);
}
}
Aggregations