Class SimpleAccessControlSftpEventListener

  • All Implemented Interfaces:
    java.util.EventListener, SshdEventListener, SftpEventListener

    public abstract class SimpleAccessControlSftpEventListener
    extends AbstractSftpEventListenerAdapter
    Provides a simple access control by making a distinction between methods that provide information - including reading data - and those that modify it
    • Constructor Detail

      • SimpleAccessControlSftpEventListener

        protected SimpleAccessControlSftpEventListener()
    • Method Detail

      • opening

        public void opening​(ServerSession session,
                            java.lang.String remoteHandle,
                            Handle localHandle)
                     throws java.io.IOException
        Description copied from interface: SftpEventListener
        Specified file / directory is being opened
        Specified by:
        opening in interface SftpEventListener
        Overrides:
        opening in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        remoteHandle - The (opaque) assigned handle for the file / directory
        localHandle - The associated file / directory Handle
        Throws:
        java.io.IOException - If failed to handle the call
      • readEntries

        public void readEntries​(ServerSession session,
                                java.lang.String remoteHandle,
                                DirectoryHandle localHandle,
                                java.util.Map<java.lang.String,​java.nio.file.Path> entries)
                         throws java.io.IOException
        Description copied from interface: SftpEventListener
        Result of reading entries from a directory - Note: it may be a partial result if the directory contains more entries than can be accommodated in the response
        Specified by:
        readEntries in interface SftpEventListener
        Overrides:
        readEntries in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        remoteHandle - The (opaque) assigned handle for the directory
        localHandle - The associated DirectoryHandle
        entries - A Map of the listed entries - key = short name, value = Path of the sub-entry
        Throws:
        java.io.IOException - If failed to handle the call
      • reading

        public void reading​(ServerSession session,
                            java.lang.String remoteHandle,
                            FileHandle localHandle,
                            long offset,
                            byte[] data,
                            int dataOffset,
                            int dataLen)
                     throws java.io.IOException
        Description copied from interface: SftpEventListener
        Preparing to read from a file
        Specified by:
        reading in interface SftpEventListener
        Overrides:
        reading in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        remoteHandle - The (opaque) assigned handle for the file
        localHandle - The associated FileHandle
        offset - Offset in file from which to read
        data - Buffer holding the read data
        dataOffset - Offset of read data in buffer
        dataLen - Requested read length
        Throws:
        java.io.IOException - If failed to handle the call
      • isAccessAllowed

        protected boolean isAccessAllowed​(ServerSession session,
                                          java.lang.String remoteHandle,
                                          Handle localHandle)
                                   throws java.io.IOException
        Parameters:
        session - The ServerSession throw which the request was made
        remoteHandle - The remote handle value
        localHandle - The local handle
        Returns:
        true if allowed to access the handle
        Throws:
        java.io.IOException - If failed to handle the call
      • isAccessAllowed

        protected abstract boolean isAccessAllowed​(ServerSession session,
                                                   java.lang.String remoteHandle,
                                                   java.nio.file.Path localPath)
                                            throws java.io.IOException
        Parameters:
        session - The ServerSession throw which the request was made
        remoteHandle - The remote handle value
        localPath - The local Path
        Returns:
        true if allowed to access the path
        Throws:
        java.io.IOException - If failed to handle the call
      • writing

        public void writing​(ServerSession session,
                            java.lang.String remoteHandle,
                            FileHandle localHandle,
                            long offset,
                            byte[] data,
                            int dataOffset,
                            int dataLen)
                     throws java.io.IOException
        Description copied from interface: SftpEventListener
        Preparing to write to file
        Specified by:
        writing in interface SftpEventListener
        Overrides:
        writing in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        remoteHandle - The (opaque) assigned handle for the file
        localHandle - The associated FileHandle
        offset - Offset in file to which to write
        data - Buffer holding the written data
        dataOffset - Offset of write data in buffer
        dataLen - Requested write length
        Throws:
        java.io.IOException - If failed to handle the call
      • unblocking

        public void unblocking​(ServerSession session,
                               java.lang.String remoteHandle,
                               FileHandle localHandle,
                               long offset,
                               long length)
                        throws java.io.IOException
        Description copied from interface: SftpEventListener
        Called prior to un-blocking a file section
        Specified by:
        unblocking in interface SftpEventListener
        Overrides:
        unblocking in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        remoteHandle - The (opaque) assigned handle for the file
        localHandle - The associated FileHandle
        offset - Offset in file for un-locking
        length - Section size for un-locking
        Throws:
        java.io.IOException - If failed to handle the call
      • removed

        public void removed​(ServerSession session,
                            java.nio.file.Path path,
                            boolean isDirectory,
                            java.lang.Throwable thrown)
                     throws java.io.IOException
        Description copied from interface: SftpEventListener
        Called after a file has been removed
        Specified by:
        removed in interface SftpEventListener
        Overrides:
        removed in class AbstractSftpEventListenerAdapter
        Parameters:
        session - The ServerSession through which the request was handled
        path - The Path to be removed
        isDirectory - Whether this was a folder or a file
        thrown - If not-null then the reason for the failure to execute
        Throws:
        java.io.IOException - If failed to handle the call
      • isModificationAllowed

        protected abstract boolean isModificationAllowed​(ServerSession session,
                                                         java.lang.String remoteHandle,
                                                         java.nio.file.Path localPath)
                                                  throws java.io.IOException
        Parameters:
        session - The ServerSession throw which the request was made
        remoteHandle - The remote handle value
        localPath - The local Path
        Returns:
        true if allowed to modify the path
        Throws:
        java.io.IOException - If failed to handle the call