Package org.apache.sshd.common.util.io
Class ModifiableFileWatcher
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.util.io.ModifiableFileWatcher
-
- Direct Known Subclasses:
AuthorizedKeysAuthenticator,ClientIdentityFileWatcher,ConfigFileHostEntryResolver,FileWatcherKeyPairResourceLoader,KnownHostsServerKeyVerifier
public class ModifiableFileWatcher extends AbstractLoggingBean
Watches over changes for a file and re-loads them if file has changed - including if file is deleted or (re-)created
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.file.Pathfileprivate java.util.concurrent.atomic.AtomicBooleanlastExistedprivate java.util.concurrent.atomic.AtomicLonglastModifiedprivate java.util.concurrent.atomic.AtomicLonglastSizeprotected java.nio.file.LinkOption[]optionsstatic java.util.Set<java.nio.file.attribute.PosixFilePermission>STRICTLY_PROHIBITED_FILE_PERMISSIONTheSetofPosixFilePermissionnot allowed if strict permissions are enforced on key files-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ModifiableFileWatcher(java.nio.file.Path file)ModifiableFileWatcher(java.nio.file.Path file, java.nio.file.LinkOption... options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckReloadRequired()booleanexists()java.nio.file.PathgetPath()java.nio.file.attribute.FileTimelastModified()voidresetReloadAttributes()Resets the state attributes used to detect changes to the initial construction values - i.e., file assumed not to exist and no known size of modify timelongsize()PathResourcetoPathResource()PathResourcetoPathResource(java.nio.file.OpenOption... options)java.lang.StringtoString()voidupdateReloadAttributes()May be called to refresh the state attributes used to detect changes e.g., file existence, size and last-modified time once re-loading is successfully completed.static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,java.lang.Object>validateStrictConfigFilePermissions(java.nio.file.Path path, java.nio.file.LinkOption... options)Checks if a path has strict permissions-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
-
-
-
Field Detail
-
STRICTLY_PROHIBITED_FILE_PERMISSION
public static final java.util.Set<java.nio.file.attribute.PosixFilePermission> STRICTLY_PROHIBITED_FILE_PERMISSION
TheSetofPosixFilePermissionnot allowed if strict permissions are enforced on key files
-
options
protected final java.nio.file.LinkOption[] options
-
file
private final java.nio.file.Path file
-
lastExisted
private final java.util.concurrent.atomic.AtomicBoolean lastExisted
-
lastSize
private final java.util.concurrent.atomic.AtomicLong lastSize
-
lastModified
private final java.util.concurrent.atomic.AtomicLong lastModified
-
-
Method Detail
-
getPath
public final java.nio.file.Path getPath()
- Returns:
- The watched
Path
-
exists
public final boolean exists() throws java.io.IOException- Throws:
java.io.IOException
-
size
public final long size() throws java.io.IOException- Throws:
java.io.IOException
-
lastModified
public final java.nio.file.attribute.FileTime lastModified() throws java.io.IOException- Throws:
java.io.IOException
-
checkReloadRequired
public boolean checkReloadRequired() throws java.io.IOException- Returns:
trueif the watched file has probably been changed- Throws:
java.io.IOException- If failed to query file data
-
resetReloadAttributes
public void resetReloadAttributes()
Resets the state attributes used to detect changes to the initial construction values - i.e., file assumed not to exist and no known size of modify time
-
updateReloadAttributes
public void updateReloadAttributes() throws java.io.IOExceptionMay be called to refresh the state attributes used to detect changes e.g., file existence, size and last-modified time once re-loading is successfully completed. If the file does not exist then the attributes are reset to an "unknown" state.- Throws:
java.io.IOException- If failed to access the file (if exists)- See Also:
resetReloadAttributes()
-
toPathResource
public PathResource toPathResource()
-
toPathResource
public PathResource toPathResource(java.nio.file.OpenOption... options)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
validateStrictConfigFilePermissions
public static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,java.lang.Object> validateStrictConfigFilePermissions(java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.IOExceptionChecks if a path has strict permissions
(For
Unix) The path may not have group or others write permissionsThe path must be owned by current user.
(For
Unix) The path may be owned by root.
- Parameters:
path- ThePathto be checked - ignored ifnullor does not existoptions- TheLinkOptions to use to query the file's permissions- Returns:
- The violated permission as
AbstractMap.SimpleImmutableEntrywhere key is a loggable message and value is the offending object - e.g.,PosixFilePermissionorStringfor owner. Return value isnullif no violations detected - Throws:
java.io.IOException- If failed to retrieve the permissions- See Also:
STRICTLY_PROHIBITED_FILE_PERMISSION
-
-