Package org.apache.sshd.sftp.server
Class AbstractSftpSubsystemHelper
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
-
- All Implemented Interfaces:
SessionContextHolder
,SessionHolder<ServerSession>
,ServerChannelSessionHolder
,ServerSessionHolder
,SftpErrorStatusDataHandlerProvider
,SftpEventListenerManager
,SftpFileSystemAccessorProvider
,SftpSubsystemEnvironment
,SftpSubsystemProxy
,SftpUnsupportedAttributePolicyProvider
- Direct Known Subclasses:
SftpSubsystem
public abstract class AbstractSftpSubsystemHelper extends AbstractLoggingBean implements SftpSubsystemProxy
- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static Set<Integer>
DEFAULT_ACL_SUPPORTED_MASK
static List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
DEFAULT_OPEN_SSH_EXTENSIONS
static List<String>
DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
static NavigableMap<String,OptionalFeature>
DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
The default reported supported client extensions (case insensitive)-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
ALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SUPPORTED_SFTP_VERSIONS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSftpSubsystemHelper(ChannelSession channelSession, SftpSubsystemConfigurator configurator)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected NavigableMap<String,Object>
addMissingAttribute(Path file, NavigableMap<String,Object> current, String name, FileInfoExtractor<?> x, LinkOption... options)
boolean
addSftpEventListener(SftpEventListener listener)
Register a listener instanceprotected int
appendAclSupportedExtension(Buffer buffer, ServerSession session)
protected void
appendExtensions(Buffer buffer, String supportedVersions)
protected void
appendNewlineExtension(Buffer buffer, ServerSession session)
Appends the "newline" extension to the buffer.protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
appendOpenSSHExtensions(Buffer buffer, ServerSession session)
protected void
appendSupported2Extension(Buffer buffer, Collection<String> extras)
Appends the "supported2" extension to the buffer.protected void
appendSupportedExtension(Buffer buffer, Collection<String> extras)
Appends the "supported" extension to the buffer.protected void
appendVendorIdExtension(Buffer buffer, Map<String,?> versionProperties, ServerSession session)
Appends the "vendor-id" extension to the buffer.protected void
appendVersionsExtension(Buffer buffer, String value, ServerSession session)
Appends the "versions" extension to the buffer.protected Map.Entry<Integer,String>
checkVersionCompatibility(Buffer buffer, int id, int proposed, int failureOpcode)
Checks if a proposed version is within supported range.protected abstract void
createLink(int id, String existingPath, String linkPath, boolean symLink)
protected abstract void
doBlock(int id, String handle, long offset, long length, int mask)
protected void
doBlock(Buffer buffer, int id)
protected abstract void
doCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, Buffer buffer)
protected void
doCheckFileHash(int id, Path file, NamedFactory<? extends Digest> factory, long startOffset, long length, int blockSize, Buffer buffer)
protected void
doCheckFileHash(Buffer buffer, int id, String targetType)
protected abstract void
doClose(int id, String handle)
protected void
doClose(Buffer buffer, int id)
protected abstract void
doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset)
protected void
doCopyData(Buffer buffer, int id)
protected void
doCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination)
protected void
doCopyFile(int id, String srcFile, String dstFile, Collection<CopyOption> opts)
protected void
doCopyFile(Buffer buffer, int id)
protected void
doExtended(Buffer buffer, int id)
protected abstract void
doFSetStat(int id, String handle, Map<String,?> attrs)
protected void
doFSetStat(Buffer buffer, int id)
protected abstract Map<String,Object>
doFStat(int id, String handle, int flags)
protected void
doFStat(Buffer buffer, int id)
protected abstract void
doInit(Buffer buffer, int id)
protected void
doLink(int id, String targetPath, String linkPath, boolean symLink)
protected void
doLink(Buffer buffer, int id)
protected Map<String,Object>
doLStat(int id, String path, int flags)
protected void
doLStat(Buffer buffer, int id)
protected void
doMakeDirectory(int id, String path, Map<String,?> attrs, boolean followLinks)
protected void
doMakeDirectory(Buffer buffer, int id)
protected abstract byte[]
doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash)
protected byte[]
doMD5Hash(int id, Path path, long startOffset, long length, byte[] quickCheckHash)
protected void
doMD5Hash(Buffer buffer, int id, String targetType)
protected abstract String
doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs)
protected void
doOpen(Buffer buffer, int id)
protected abstract String
doOpenDir(int id, String path, Path p, LinkOption... options)
protected void
doOpenDir(Buffer buffer, int id)
protected abstract void
doOpenSSHFsync(int id, String handle)
protected void
doOpenSSHFsync(Buffer buffer, int id)
protected void
doOpenSSHHardLink(int id, String srcFile, String dstFile)
protected void
doOpenSSHHardLink(Buffer buffer, int id)
protected void
doPosixRename(Buffer buffer, int id)
protected void
doProcess(Buffer buffer, int length, int type, int id)
protected abstract int
doRead(int id, String handle, long offset, int length, byte[] data, int doff)
protected void
doRead(Buffer buffer, int id)
protected int
doReadDir(int id, String handle, DirectoryHandle dir, Buffer buffer, int maxSize, boolean followLinks)
protected abstract void
doReadDir(Buffer buffer, int id)
protected AbstractMap.SimpleImmutableEntry<Path,String>
doReadLink(int id, String path)
protected void
doReadLink(Buffer buffer, int id)
protected void
doRealPath(Buffer buffer, int id)
protected AbstractMap.SimpleImmutableEntry<Path,Boolean>
doRealPathV345(int id, String path, Path p, LinkOption... options)
protected AbstractMap.SimpleImmutableEntry<Path,Boolean>
doRealPathV6(int id, String path, Collection<String> extraPaths, Path p, LinkOption... options)
protected void
doRemove(int id, Path p, boolean isDirectory)
Called when need to delete a file / directory - also informs theSftpEventListener
protected void
doRemove(Buffer buffer, int id)
protected void
doRemoveDirectory(int id, String path, boolean followLinks)
protected void
doRemoveDirectory(Buffer buffer, int id)
protected void
doRemoveFile(int id, String path, boolean followLinks)
protected void
doRename(int id, String oldPath, String newPath, int flags)
protected void
doRename(int id, String oldPath, String newPath, Collection<CopyOption> opts)
protected void
doRename(Buffer buffer, int id)
protected void
doSetAttributes(int cmd, String extension, Path file, Map<String,?> attributes, boolean followLinks)
protected void
doSetStat(int id, String path, int cmd, String extension, Map<String,?> attrs, Boolean followLinks)
protected void
doSetStat(Buffer buffer, int id, String extension, int cmd, Boolean followLinks)
protected SpaceAvailableExtensionInfo
doSpaceAvailable(int id, String path)
protected void
doSpaceAvailable(Buffer buffer, int id)
protected Map<String,Object>
doStat(int id, String path, int flags)
protected void
doStat(Buffer buffer, int id)
protected void
doSymLink(int id, String targetPath, String linkPath)
protected void
doSymLink(Buffer buffer, int id)
protected abstract void
doTextSeek(int id, String handle, long line)
protected void
doTextSeek(Buffer buffer, int id)
protected abstract void
doUnblock(int id, String handle, long offset, long length)
protected void
doUnblock(Buffer buffer, int id)
protected void
doUnsupported(Buffer buffer, int length, int type, int id)
protected void
doUnsupportedExtension(Buffer buffer, int id, String extension)
protected void
doVersionSelect(Buffer buffer, int id)
protected abstract void
doVersionSelect(Buffer buffer, int id, String proposed)
protected abstract void
doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining)
protected void
doWrite(Buffer buffer, int id)
protected void
executeExtendedCommand(Buffer buffer, int id, String extension)
protected NavigableMap<String,Object>
getAttributes(Path file, int flags, LinkOption... options)
protected NavigableMap<String,Object>
getAttributes(Path file, LinkOption... options)
SftpErrorStatusDataHandler
getErrorStatusDataHandler()
SftpFileSystemAccessor
getFileSystemAccessor()
protected String
getLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options)
protected String
getLongName(Path f, String shortName, LinkOption... options)
protected String
getLongName(Path f, String shortName, Map<String,?> attributes)
protected LinkOption[]
getPathResolutionLinkOption(int cmd, String extension, Path path)
ChannelSession
getServerChannelSession()
SftpEventListener
getSftpEventListenerProxy()
protected String
getShortName(Path f)
protected Map<String,OptionalFeature>
getSupportedClientExtensions(ServerSession session)
UnsupportedAttributePolicy
getUnsupportedAttributePolicy()
protected NavigableMap<String,Object>
handleReadFileAttributesException(Path file, String view, LinkOption[] options, IOException e)
protected void
handleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e)
protected NavigableMap<String,Object>
handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options)
protected void
handleUnsupportedAttributes(Collection<String> attributes)
protected void
handleUserPrincipalLookupServiceException(Class<? extends Principal> principalType, String name, IOException e)
protected Path
normalize(Path f)
protected abstract Buffer
prepareReply(Buffer buffer)
protected void
process(Buffer buffer)
Process an SFTP command.protected Map<String,Object>
readAttrs(Buffer buffer)
protected NavigableMap<String,Object>
readFileAttributes(Path file, String view, LinkOption... options)
boolean
removeSftpEventListener(SftpEventListener listener)
Remove a listener instanceprotected Collection<Integer>
resolveAclSupportedCapabilities(ServerSession session)
protected Path
resolveFile(String remotePath)
protected NavigableMap<String,Object>
resolveFileAttributes(Path file, int flags, LinkOption... options)
protected NavigableMap<String,Object>
resolveMissingFileAttributes(Path file, int flags, Map<String,Object> current, LinkOption... options)
Called bygetAttributes(Path, int, LinkOption...)
in order to complete any attributes that could not be retrieved via the supported file system views.protected Object
resolveMissingFileAttributeValue(Path file, String name, Object value, FileInfoExtractor<?> x, LinkOption... options)
protected String
resolveNewlineValue(ServerSession session)
protected Path
resolveNormalizedLocation(String remotePath)
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension>
resolveOpenSSHExtensions(ServerSession session)
protected boolean
resolvePathResolutionFollowLinks(int cmd, String extension, Path path)
protected abstract void
send(Buffer buffer)
protected void
sendAttrs(Buffer buffer, int id, Map<String,?> attributes)
protected void
sendHandle(Buffer buffer, int id, String handle)
protected void
sendLink(Buffer buffer, int id, Path file, String link)
protected void
sendPath(Buffer buffer, int id, Path f, Map<String,?> attrs)
protected void
sendStatus(Buffer buffer, int id, int substatus, String msg)
protected void
sendStatus(Buffer buffer, int id, int substatus, String msg, String lang)
protected void
sendStatus(Buffer buffer, int id, Throwable e, int cmd, Object... args)
Invoked when an exception was thrown due to the execution of some SFTP commandprotected void
setFileAccessControl(Path file, List<AclEntry> acl, LinkOption... options)
protected void
setFileAttribute(Path file, String view, String attribute, Object value, LinkOption... options)
protected void
setFileAttributes(Path file, Map<String,?> attributes, LinkOption... options)
protected void
setFileExtensions(Path file, Map<String,byte[]> extensions, LinkOption... options)
protected void
setFileOwnership(Path file, String attribute, Principal value, LinkOption... options)
protected void
setFilePermissions(Path file, Set<PosixFilePermission> perms, LinkOption... options)
protected void
setFileRawViewAttribute(Path file, String view, String attribute, Object value, LinkOption... options)
protected void
setFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options)
protected <E extends IOException>
EsignalOpenFailure(int id, String pathValue, Path path, boolean isDir, E thrown)
protected <E extends IOException>
EsignalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown, boolean isRemoveDirectory)
protected GroupPrincipal
toGroup(Path file, GroupPrincipal name)
protected UserPrincipal
toUser(Path file, UserPrincipal name)
protected <H extends Handle>
HvalidateHandle(String handle, Handle h, Class<H> type)
Makes sure that the local handle is not null and of the specified typeprotected Boolean
validateProposedVersion(Buffer buffer, int id, String proposal)
protected AbstractMap.SimpleImmutableEntry<Path,Boolean>
validateRealPath(int id, String path, Path f, LinkOption... options)
protected void
writeAttrs(Buffer buffer, Map<String,?> attributes)
protected void
writeDirEntry(int id, DirectoryHandle dir, Map<String,Path> entries, Buffer buffer, int index, Path f, String shortName, LinkOption... options)
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.server.session.ServerSessionHolder
getServerSession
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Methods inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
getDefaultDirectory, getSession, getVersion
-
-
-
-
Field Detail
-
DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
public static final NavigableMap<String,OptionalFeature> DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
The default reported supported client extensions (case insensitive)
-
DEFAULT_OPEN_SSH_EXTENSIONS
public static final List<AbstractOpenSSHExtensionParser.OpenSSHExtension> DEFAULT_OPEN_SSH_EXTENSIONS
-
DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
public static final List<String> DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
-
-
Constructor Detail
-
AbstractSftpSubsystemHelper
protected AbstractSftpSubsystemHelper(ChannelSession channelSession, SftpSubsystemConfigurator configurator)
-
-
Method Detail
-
getServerChannelSession
public ChannelSession getServerChannelSession()
- Specified by:
getServerChannelSession
in interfaceServerChannelSessionHolder
-
getUnsupportedAttributePolicy
public UnsupportedAttributePolicy getUnsupportedAttributePolicy()
- Specified by:
getUnsupportedAttributePolicy
in interfaceSftpUnsupportedAttributePolicyProvider
- Returns:
- The
UnsupportedAttributePolicy
to use if failed to access some local file attributes
-
getFileSystemAccessor
public SftpFileSystemAccessor getFileSystemAccessor()
- Specified by:
getFileSystemAccessor
in interfaceSftpFileSystemAccessorProvider
- Returns:
- The
SftpFileSystemAccessor
to use for accessing files and directories
-
getSftpEventListenerProxy
public SftpEventListener getSftpEventListenerProxy()
- Specified by:
getSftpEventListenerProxy
in interfaceSftpEventListenerManager
- Returns:
- An instance representing all the currently registered listeners. Any method invocation is replicated to the actually registered listeners
-
addSftpEventListener
public boolean addSftpEventListener(SftpEventListener listener)
Description copied from interface:SftpEventListenerManager
Register a listener instance- Specified by:
addSftpEventListener
in interfaceSftpEventListenerManager
- Parameters:
listener
- TheSftpEventListener
instance to add - nevernull
- Returns:
true
if listener is a previously un-registered one
-
removeSftpEventListener
public boolean removeSftpEventListener(SftpEventListener listener)
Description copied from interface:SftpEventListenerManager
Remove a listener instance- Specified by:
removeSftpEventListener
in interfaceSftpEventListenerManager
- Parameters:
listener
- TheSftpEventListener
instance to remove - nevernull
- Returns:
true
if listener is a (removed) registered one
-
getErrorStatusDataHandler
public SftpErrorStatusDataHandler getErrorStatusDataHandler()
- Specified by:
getErrorStatusDataHandler
in interfaceSftpErrorStatusDataHandlerProvider
- Returns:
- The (never
null
)SftpErrorStatusDataHandler
to use when generating failed commands error messages
-
validateProposedVersion
protected Boolean validateProposedVersion(Buffer buffer, int id, String proposal) throws IOException
- Parameters:
buffer
- TheBuffer
holding the requestid
- The request idproposal
- The proposed value- Returns:
- A
Boolean
indicating whether to accept/reject the proposal. Ifnull
then rejection response has been sent, otherwise and appropriate response is generated - Throws:
IOException
- If failed send an independent rejection response
-
checkVersionCompatibility
protected Map.Entry<Integer,String> checkVersionCompatibility(Buffer buffer, int id, int proposed, int failureOpcode) throws IOException
Checks if a proposed version is within supported range. Note: if the user forced a specific value via theSftpModuleProperties.SFTP_VERSION
property, then it is used to validate the proposed value- Parameters:
buffer
- TheBuffer
containing the requestid
- The SSH message ID to be used to send the failure message if requiredproposed
- The proposed version valuefailureOpcode
- The failure opcode to send if validation fails- Returns:
- A "pair" whose key is the negotiated version and value a
String
of comma separated values representing all the supported versions.null
if validation failed and an appropriate status message was sent - Throws:
IOException
- If failed to send the failure status message
-
process
protected void process(Buffer buffer) throws IOException
Process an SFTP command. If the command throws an exception, the channel will be closed.- Parameters:
buffer
- the buffer to process- Throws:
IOException
- if anything wrong happens
-
doProcess
protected void doProcess(Buffer buffer, int length, int type, int id) throws IOException
- Throws:
IOException
-
doUnsupported
protected void doUnsupported(Buffer buffer, int length, int type, int id) throws IOException
- Throws:
IOException
-
doInit
protected abstract void doInit(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doVersionSelect
protected void doVersionSelect(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doVersionSelect
protected abstract void doVersionSelect(Buffer buffer, int id, String proposed) throws IOException
- Throws:
IOException
-
doOpen
protected void doOpen(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doOpen
protected abstract String doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs) throws IOException
- Parameters:
id
- Request idpath
- Pathpflags
- Open mode flags - seeSSH_FXF_XXX
flagsaccess
- Access mode flags - seeACE4_XXX
flagsattrs
- Requested attributes- Returns:
- The assigned (opaque) handle
- Throws:
IOException
- if failed to execute
-
signalOpenFailure
protected <E extends IOException> E signalOpenFailure(int id, String pathValue, Path path, boolean isDir, E thrown) throws IOException
- Throws:
IOException
-
doClose
protected void doClose(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doClose
protected abstract void doClose(int id, String handle) throws IOException
- Throws:
IOException
-
doRead
protected void doRead(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doRead
protected abstract int doRead(int id, String handle, long offset, int length, byte[] data, int doff) throws IOException
- Throws:
IOException
-
doWrite
protected void doWrite(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doWrite
protected abstract void doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining) throws IOException
- Throws:
IOException
-
doLStat
protected void doLStat(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doLStat
protected Map<String,Object> doLStat(int id, String path, int flags) throws IOException
- Throws:
IOException
-
doSetStat
protected void doSetStat(Buffer buffer, int id, String extension, int cmd, Boolean followLinks) throws IOException
- Throws:
IOException
-
doSetStat
protected void doSetStat(int id, String path, int cmd, String extension, Map<String,?> attrs, Boolean followLinks) throws IOException
- Throws:
IOException
-
doFStat
protected void doFStat(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doFStat
protected abstract Map<String,Object> doFStat(int id, String handle, int flags) throws IOException
- Throws:
IOException
-
doFSetStat
protected void doFSetStat(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doFSetStat
protected abstract void doFSetStat(int id, String handle, Map<String,?> attrs) throws IOException
- Throws:
IOException
-
doOpenDir
protected void doOpenDir(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doOpenDir
protected abstract String doOpenDir(int id, String path, Path p, LinkOption... options) throws IOException
- Throws:
IOException
-
doReadDir
protected abstract void doReadDir(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doLink
protected void doLink(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doLink
protected void doLink(int id, String targetPath, String linkPath, boolean symLink) throws IOException
- Throws:
IOException
-
doSymLink
protected void doSymLink(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doSymLink
protected void doSymLink(int id, String targetPath, String linkPath) throws IOException
- Throws:
IOException
-
createLink
protected abstract void createLink(int id, String existingPath, String linkPath, boolean symLink) throws IOException
- Throws:
IOException
-
doOpenSSHHardLink
protected void doOpenSSHHardLink(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doOpenSSHHardLink
protected void doOpenSSHHardLink(int id, String srcFile, String dstFile) throws IOException
- Throws:
IOException
-
doSpaceAvailable
protected void doSpaceAvailable(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doSpaceAvailable
protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException
- Throws:
IOException
-
doTextSeek
protected void doTextSeek(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doTextSeek
protected abstract void doTextSeek(int id, String handle, long line) throws IOException
- Throws:
IOException
-
doOpenSSHFsync
protected void doOpenSSHFsync(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doOpenSSHFsync
protected abstract void doOpenSSHFsync(int id, String handle) throws IOException
- Throws:
IOException
-
doCheckFileHash
protected void doCheckFileHash(Buffer buffer, int id, String targetType) throws IOException
- Throws:
IOException
-
doCheckFileHash
protected void doCheckFileHash(int id, Path file, NamedFactory<? extends Digest> factory, long startOffset, long length, int blockSize, Buffer buffer) throws Exception
- Throws:
Exception
-
doMD5Hash
protected void doMD5Hash(Buffer buffer, int id, String targetType) throws IOException
- Throws:
IOException
-
doMD5Hash
protected abstract byte[] doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash) throws Exception
- Throws:
Exception
-
doMD5Hash
protected byte[] doMD5Hash(int id, Path path, long startOffset, long length, byte[] quickCheckHash) throws Exception
- Throws:
Exception
-
doCheckFileHash
protected abstract void doCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, Buffer buffer) throws Exception
- Throws:
Exception
-
doReadLink
protected void doReadLink(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doReadLink
protected AbstractMap.SimpleImmutableEntry<Path,String> doReadLink(int id, String path) throws IOException
- Parameters:
id
- Request identifierpath
- Referenced path- Returns:
- A "pair" containing the local link
Path
and its referenced symbolic link - Throws:
IOException
- If failed to resolve the requested data
-
doRename
protected void doRename(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doRename
protected void doRename(int id, String oldPath, String newPath, int flags) throws IOException
- Throws:
IOException
-
doRename
protected void doRename(int id, String oldPath, String newPath, Collection<CopyOption> opts) throws IOException
- Throws:
IOException
-
doPosixRename
protected void doPosixRename(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doCopyData
protected void doCopyData(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doCopyData
protected abstract void doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) throws IOException
- Throws:
IOException
-
doCopyFile
protected void doCopyFile(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doCopyFile
protected void doCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination) throws IOException
- Throws:
IOException
-
doCopyFile
protected void doCopyFile(int id, String srcFile, String dstFile, Collection<CopyOption> opts) throws IOException
- Throws:
IOException
-
doBlock
protected void doBlock(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doBlock
protected abstract void doBlock(int id, String handle, long offset, long length, int mask) throws IOException
- Throws:
IOException
-
doUnblock
protected void doUnblock(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doUnblock
protected abstract void doUnblock(int id, String handle, long offset, long length) throws IOException
- Throws:
IOException
-
doStat
protected void doStat(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doStat
protected Map<String,Object> doStat(int id, String path, int flags) throws IOException
- Throws:
IOException
-
doRealPath
protected void doRealPath(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doRealPathV6
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> doRealPathV6(int id, String path, Collection<String> extraPaths, Path p, LinkOption... options) throws IOException
- Throws:
IOException
-
doRealPathV345
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> doRealPathV345(int id, String path, Path p, LinkOption... options) throws IOException
- Throws:
IOException
-
validateRealPath
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) throws IOException
- Parameters:
id
- The request identifierpath
- The original pathf
- The resolvePath
options
- TheLinkOption
s to use to verify file existence and access- Returns:
- A
AbstractMap.SimpleImmutableEntry
whose key is the absolute normalizedPath
and value is aBoolean
indicating its status - Throws:
IOException
- If failed to validate the file- See Also:
IoUtils.checkFileExists(Path, LinkOption...)
-
doRemoveDirectory
protected void doRemoveDirectory(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doRemoveDirectory
protected void doRemoveDirectory(int id, String path, boolean followLinks) throws IOException
- Throws:
IOException
-
doRemove
protected void doRemove(int id, Path p, boolean isDirectory) throws IOException
Called when need to delete a file / directory - also informs theSftpEventListener
- Parameters:
id
- Deletion request IDp
-Path
to deleteisDirectory
- Whether the requested path represents a directory or a regular file- Throws:
IOException
- If failed to delete
-
doMakeDirectory
protected void doMakeDirectory(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doMakeDirectory
protected void doMakeDirectory(int id, String path, Map<String,?> attrs, boolean followLinks) throws IOException
- Throws:
IOException
-
doRemove
protected void doRemove(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
doRemoveFile
protected void doRemoveFile(int id, String path, boolean followLinks) throws IOException
- Throws:
IOException
-
signalRemovalPreConditionFailure
protected <E extends IOException> E signalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown, boolean isRemoveDirectory) throws IOException
- Throws:
IOException
-
doExtended
protected void doExtended(Buffer buffer, int id) throws IOException
- Throws:
IOException
-
executeExtendedCommand
protected void executeExtendedCommand(Buffer buffer, int id, String extension) throws IOException
- Parameters:
buffer
- The commandBuffer
id
- The request idextension
- The extension name- Throws:
IOException
- If failed to execute the extension
-
doUnsupportedExtension
protected void doUnsupportedExtension(Buffer buffer, int id, String extension) throws IOException
- Throws:
IOException
-
appendAclSupportedExtension
protected int appendAclSupportedExtension(Buffer buffer, ServerSession session)
-
resolveAclSupportedCapabilities
protected Collection<Integer> resolveAclSupportedCapabilities(ServerSession session)
-
appendOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> appendOpenSSHExtensions(Buffer buffer, ServerSession session)
-
resolveOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> resolveOpenSSHExtensions(ServerSession session)
-
getSupportedClientExtensions
protected Map<String,OptionalFeature> getSupportedClientExtensions(ServerSession session)
-
appendVersionsExtension
protected void appendVersionsExtension(Buffer buffer, String value, ServerSession session)
Appends the "versions" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer
- TheBuffer
to append tovalue
- The recommended value - ignored ifnull
/emptysession
- TheServerSession
for which this extension is added- See Also:
SftpConstants.EXT_VERSIONS
-
appendNewlineExtension
protected void appendNewlineExtension(Buffer buffer, ServerSession session)
Appends the "newline" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer
- TheBuffer
to append tosession
- TheServerSession
for which this extension is added- See Also:
SftpConstants.EXT_NEWLINE
,resolveNewlineValue(ServerSession)
-
resolveNewlineValue
protected String resolveNewlineValue(ServerSession session)
-
appendVendorIdExtension
protected void appendVendorIdExtension(Buffer buffer, Map<String,?> versionProperties, ServerSession session)
Appends the "vendor-id" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer
- TheBuffer
to append toversionProperties
- The currently available version properties - ignored ifnull
/empty. The code expects the following values:groupId
- as the vendor nameartifactId
- as the product nameversion
- as the product version
session
- TheServerSession
for which these properties are added- See Also:
SftpConstants.EXT_VENDOR_ID
, DRAFT 09 - section 4.4
-
appendSupportedExtension
protected void appendSupportedExtension(Buffer buffer, Collection<String> extras)
Appends the "supported" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer
- TheBuffer
to append toextras
- The extra extensions that are available and can be reported - may benull
/empty
-
appendSupported2Extension
protected void appendSupported2Extension(Buffer buffer, Collection<String> extras)
Appends the "supported2" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer
- TheBuffer
to append toextras
- The extra extensions that are available and can be reported - may benull
/empty- See Also:
SftpConstants.EXT_SUPPORTED
, DRAFT 13 section 5.4
-
sendHandle
protected void sendHandle(Buffer buffer, int id, String handle) throws IOException
- Throws:
IOException
-
sendAttrs
protected void sendAttrs(Buffer buffer, int id, Map<String,?> attributes) throws IOException
- Throws:
IOException
-
sendLink
protected void sendLink(Buffer buffer, int id, Path file, String link) throws IOException
- Throws:
IOException
-
sendPath
protected void sendPath(Buffer buffer, int id, Path f, Map<String,?> attrs) throws IOException
- Throws:
IOException
-
doReadDir
protected int doReadDir(int id, String handle, DirectoryHandle dir, Buffer buffer, int maxSize, boolean followLinks) throws IOException
- Parameters:
id
- Request idhandle
- The (opaque) handle assigned to this directorydir
- TheDirectoryHandle
buffer
- TheBuffer
to write the resultsmaxSize
- Max. buffer sizefollowLinks
- Whether to follow symbolic links when querying the directory contents- Returns:
- Number of written entries
- Throws:
IOException
- If failed to generate an entry
-
writeDirEntry
protected void writeDirEntry(int id, DirectoryHandle dir, Map<String,Path> entries, Buffer buffer, int index, Path f, String shortName, LinkOption... options) throws IOException
- Parameters:
id
- Request iddir
- TheDirectoryHandle
entries
- An in / outMap
for updating the written entry - key = short name, value = entryPath
buffer
- TheBuffer
to write the resultsindex
- Zero-based index of the entry to be writtenf
- The entryPath
shortName
- The entry short nameoptions
- TheLinkOption
s to use for querying the entry-s attributes- Throws:
IOException
- If failed to generate the entry data
-
getLongName
protected String getLongName(Path f, String shortName, LinkOption... options) throws IOException
- Throws:
IOException
-
getLongName
protected String getLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options) throws IOException
- Throws:
IOException
-
getLongName
protected String getLongName(Path f, String shortName, Map<String,?> attributes) throws IOException
- Throws:
IOException
-
getShortName
protected String getShortName(Path f) throws IOException
- Throws:
IOException
-
resolveFileAttributes
protected NavigableMap<String,Object> resolveFileAttributes(Path file, int flags, LinkOption... options) throws IOException
- Throws:
IOException
-
writeAttrs
protected void writeAttrs(Buffer buffer, Map<String,?> attributes) throws IOException
- Throws:
IOException
-
getAttributes
protected NavigableMap<String,Object> getAttributes(Path file, LinkOption... options) throws IOException
- Throws:
IOException
-
handleUnknownStatusFileAttributes
protected NavigableMap<String,Object> handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options) throws IOException
- Throws:
IOException
-
getAttributes
protected NavigableMap<String,Object> getAttributes(Path file, int flags, LinkOption... options) throws IOException
- Parameters:
file
- ThePath
location for the required attributesflags
- A mask of the original required attributes - ignored by the default implementationoptions
- TheLinkOption
s to use in order to access the file if necessary- Returns:
- A
Map
of the retrieved attributes - Throws:
IOException
- If failed to access the file- See Also:
resolveMissingFileAttributes(Path, int, Map, LinkOption...)
-
resolveMissingFileAttributes
protected NavigableMap<String,Object> resolveMissingFileAttributes(Path file, int flags, Map<String,Object> current, LinkOption... options) throws IOException
Called bygetAttributes(Path, int, LinkOption...)
in order to complete any attributes that could not be retrieved via the supported file system views. These attributes are deemed important so an extra effort is made to provide a value for them- Parameters:
file
- ThePath
location for the required attributesflags
- A mask of the original required attributes - ignored by the default implementationcurrent
- TheMap
of attributes already retrieved - may benull
/empty and/or unmodifiableoptions
- TheLinkOption
s to use in order to access the file if necessary- Returns:
- A
Map
of the extra attributes whose values need to be updated in the original map. Note: it is allowed to specify values which override existing ones - the default implementation does not override values that have a non-null
value - Throws:
IOException
- If failed to access the attributes - in which case an error is returned to the SFTP client- See Also:
SftpFileSystemAccessor.FILEATTRS_RESOLVERS
-
resolveMissingFileAttributeValue
protected Object resolveMissingFileAttributeValue(Path file, String name, Object value, FileInfoExtractor<?> x, LinkOption... options) throws IOException
- Throws:
IOException
-
addMissingAttribute
protected NavigableMap<String,Object> addMissingAttribute(Path file, NavigableMap<String,Object> current, String name, FileInfoExtractor<?> x, LinkOption... options) throws IOException
- Throws:
IOException
-
readFileAttributes
protected NavigableMap<String,Object> readFileAttributes(Path file, String view, LinkOption... options) throws IOException
- Throws:
IOException
-
handleReadFileAttributesException
protected NavigableMap<String,Object> handleReadFileAttributesException(Path file, String view, LinkOption[] options, IOException e) throws IOException
- Throws:
IOException
-
doSetAttributes
protected void doSetAttributes(int cmd, String extension, Path file, Map<String,?> attributes, boolean followLinks) throws IOException
- Throws:
IOException
-
getPathResolutionLinkOption
protected LinkOption[] getPathResolutionLinkOption(int cmd, String extension, Path path) throws IOException
- Throws:
IOException
-
resolvePathResolutionFollowLinks
protected boolean resolvePathResolutionFollowLinks(int cmd, String extension, Path path) throws IOException
- Throws:
IOException
-
setFileAttributes
protected void setFileAttributes(Path file, Map<String,?> attributes, LinkOption... options) throws IOException
- Throws:
IOException
-
handleSetFileAttributeFailure
protected void handleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e) throws IOException
- Throws:
IOException
-
setFileAttribute
protected void setFileAttribute(Path file, String view, String attribute, Object value, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileTime
protected void setFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileRawViewAttribute
protected void setFileRawViewAttribute(Path file, String view, String attribute, Object value, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileOwnership
protected void setFileOwnership(Path file, String attribute, Principal value, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileExtensions
protected void setFileExtensions(Path file, Map<String,byte[]> extensions, LinkOption... options) throws IOException
- Throws:
IOException
-
setFilePermissions
protected void setFilePermissions(Path file, Set<PosixFilePermission> perms, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileAccessControl
protected void setFileAccessControl(Path file, List<AclEntry> acl, LinkOption... options) throws IOException
- Throws:
IOException
-
handleUnsupportedAttributes
protected void handleUnsupportedAttributes(Collection<String> attributes)
-
toGroup
protected GroupPrincipal toGroup(Path file, GroupPrincipal name) throws IOException
- Throws:
IOException
-
toUser
protected UserPrincipal toUser(Path file, UserPrincipal name) throws IOException
- Throws:
IOException
-
handleUserPrincipalLookupServiceException
protected void handleUserPrincipalLookupServiceException(Class<? extends Principal> principalType, String name, IOException e) throws IOException
- Throws:
IOException
-
readAttrs
protected Map<String,Object> readAttrs(Buffer buffer) throws IOException
- Throws:
IOException
-
validateHandle
protected <H extends Handle> H validateHandle(String handle, Handle h, Class<H> type) throws IOException
Makes sure that the local handle is not null and of the specified type- Type Parameters:
H
- The generic handle type- Parameters:
handle
- The original handle idh
- The resolvedHandle
instancetype
- The expected handle type- Returns:
- The cast type
- Throws:
IOException
- If a generic exception occurredFileNotFoundException
- If the handle instance isnull
InvalidHandleException
- If the handle instance is not of the expected type
-
sendStatus
protected void sendStatus(Buffer buffer, int id, Throwable e, int cmd, Object... args) throws IOException
Invoked when an exception was thrown due to the execution of some SFTP command- Parameters:
buffer
- ABuffer
to be used to build the status replyid
- Command identifiere
- Thrown exceptioncmd
- The command that was attemptedargs
- The relevant command arguments - Note: provided only for logging purposes and subject to type and/or order change at any version- Throws:
IOException
- If failed to build and send the status buffer
-
sendStatus
protected void sendStatus(Buffer buffer, int id, int substatus, String msg) throws IOException
- Throws:
IOException
-
sendStatus
protected void sendStatus(Buffer buffer, int id, int substatus, String msg, String lang) throws IOException
- Throws:
IOException
-
send
protected abstract void send(Buffer buffer) throws IOException
- Throws:
IOException
-
resolveNormalizedLocation
protected Path resolveNormalizedLocation(String remotePath) throws IOException, InvalidPathException
- Throws:
IOException
InvalidPathException
-
resolveFile
protected Path resolveFile(String remotePath) throws IOException, InvalidPathException
- Parameters:
remotePath
- The remote path - separated by '/'- Returns:
- The local
Path
- Throws:
IOException
- If failed to resolve the local pathInvalidPathException
- If bad local path specification
-
-