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
Watches over changes for a file and re-loads them if file has changed - including if file is deleted or (re-)created
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Path
private final AtomicBoolean
private final AtomicLong
private final AtomicLong
protected final LinkOption[]
static final Set
<PosixFilePermission> TheSet
ofPosixFilePermission
not allowed if strict permissions are enforced on key filesFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Constructor Summary
ConstructorsConstructorDescriptionModifiableFileWatcher
(Path file) ModifiableFileWatcher
(Path file, LinkOption... options) -
Method Summary
Modifier and TypeMethodDescriptionboolean
final boolean
exists()
final Path
getPath()
final FileTime
void
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 timefinal long
size()
toPathResource
(OpenOption... options) toString()
void
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.validateStrictConfigFilePermissions
(Path path, LinkOption... options) Checks if a path has strict permissions
-
Field Details
-
STRICTLY_PROHIBITED_FILE_PERMISSION
TheSet
ofPosixFilePermission
not allowed if strict permissions are enforced on key files -
options
-
file
-
lastExisted
-
lastSize
-
lastModified
-
-
Constructor Details
-
ModifiableFileWatcher
-
ModifiableFileWatcher
-
-
Method Details
-
getPath
- Returns:
- The watched
Path
-
exists
- Throws:
IOException
-
size
- Throws:
IOException
-
lastModified
- Throws:
IOException
-
checkReloadRequired
- Returns:
true
if the watched file has probably been changed- Throws:
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
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. If the file does not exist then the attributes are reset to an "unknown" state.- Throws:
IOException
- If failed to access the file (if exists)- See Also:
-
toPathResource
-
toPathResource
-
toString
-
validateStrictConfigFilePermissions
public static AbstractMap.SimpleImmutableEntry<String,Object> validateStrictConfigFilePermissions(Path path, LinkOption... options) throws IOException Checks if a path has strict permissions
-
(For
Unix
) The path may not have group or others write permissions -
The path must be owned by current user.
-
(For
Unix
) The path may be owned by root.
- Parameters:
path
- ThePath
to be checked - ignored ifnull
or does not existoptions
- TheLinkOption
s to use to query the file's permissions- Returns:
- The violated permission as
AbstractMap.SimpleImmutableEntry
where key is a loggable message and value is the offending object - e.g.,PosixFilePermission
orString
for owner. Return value isnull
if no violations detected - Throws:
IOException
- If failed to retrieve the permissions- See Also:
-
-