public class UserAccount extends Object
The username
and homeDirectory
property must be non-null
and non-empty. The homeDirectory
property must also match the name of an existing
directory within the file system configured for the FakeFtpServer
.
The group name applied to newly created files/directories is determined by the groups
property.
If null or empty, then the default group name ("users") is used. Otherwise, the first value in the
groups
List is used. The groups
property defaults to an empty List.
The default value for defaultPermissionsForNewFile
is read and write permissions for
all (user/group/world). The default value for defaultPermissionsForNewDirectory
is read,
write and execute permissions for all (user/group/world).
The isValidPassword()
method returns true if the specified password matches
the password value configured for this user account. This implementation uses the
isEquals()
method to compare passwords.
If you want to provide a custom comparison, for instance using encrypted passwords, you can
subclass this class and override the comparePassword()
method to provide your own
custom implementation.
If the passwordCheckedDuringValidation
property is set to false, then the password
value is ignored, and the isValidPassword()
method just returns true
.
The accountRequiredForLogin
property defaults to false. If it is set to true, then
it is expected that the login for this account will require an ACCOUNT (ACCT) command after the
PASSWORD (PASS) command is completed.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_GROUP |
static Permissions |
DEFAULT_PERMISSIONS_FOR_NEW_DIRECTORY |
static Permissions |
DEFAULT_PERMISSIONS_FOR_NEW_FILE |
static String |
DEFAULT_USER |
Constructor and Description |
---|
UserAccount()
Construct a new uninitialized instance.
|
UserAccount(String username,
String password,
String homeDirectory)
Construct a new initialized instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canExecute(FileSystemEntry entry)
Return true if this user has execute access to the file/directory represented by the specified FileSystemEntry object.
|
boolean |
canRead(FileSystemEntry entry)
Return true if this user has read access to the file/directory represented by the specified FileSystemEntry object.
|
boolean |
canWrite(FileSystemEntry entry)
Return true if this user has write access to the file/directory represented by the specified FileSystemEntry object.
|
protected boolean |
comparePassword(String password)
Return true if the specified password matches the password configured for this user account.
|
protected boolean |
equalOrBothNull(String string1,
String string2)
Return true only if both Strings are null or they are equal (have the same contents).
|
Permissions |
getDefaultPermissionsForNewDirectory() |
Permissions |
getDefaultPermissionsForNewFile() |
List |
getGroups() |
String |
getHomeDirectory() |
String |
getPassword() |
String |
getPrimaryGroup()
Return the name of the primary group to which this user belongs.
|
String |
getUsername() |
boolean |
isAccountRequiredForLogin() |
boolean |
isPasswordCheckedDuringValidation() |
boolean |
isPasswordRequiredForLogin() |
boolean |
isValid() |
boolean |
isValidPassword(String password)
Return true if the specified password is the correct, valid password for this user account.
|
void |
setAccountRequiredForLogin(boolean accountRequiredForLogin) |
void |
setDefaultPermissionsForNewDirectory(Permissions defaultPermissionsForNewDirectory) |
void |
setDefaultPermissionsForNewFile(Permissions defaultPermissionsForNewFile) |
void |
setGroups(List groups) |
void |
setHomeDirectory(String homeDirectory) |
void |
setPassword(String password) |
void |
setPasswordCheckedDuringValidation(boolean passwordCheckedDuringValidation) |
void |
setPasswordRequiredForLogin(boolean passwordRequiredForLogin) |
void |
setUsername(String username) |
String |
toString() |
public static final String DEFAULT_USER
public static final String DEFAULT_GROUP
public static final Permissions DEFAULT_PERMISSIONS_FOR_NEW_FILE
public static final Permissions DEFAULT_PERMISSIONS_FOR_NEW_DIRECTORY
public String getUsername()
public void setUsername(String username)
public String getPassword()
public void setPassword(String password)
public String getHomeDirectory()
public void setHomeDirectory(String homeDirectory)
public List getGroups()
public void setGroups(List groups)
public boolean isPasswordRequiredForLogin()
public void setPasswordRequiredForLogin(boolean passwordRequiredForLogin)
public boolean isPasswordCheckedDuringValidation()
public void setPasswordCheckedDuringValidation(boolean passwordCheckedDuringValidation)
public boolean isAccountRequiredForLogin()
public void setAccountRequiredForLogin(boolean accountRequiredForLogin)
public Permissions getDefaultPermissionsForNewFile()
public void setDefaultPermissionsForNewFile(Permissions defaultPermissionsForNewFile)
public Permissions getDefaultPermissionsForNewDirectory()
public void setDefaultPermissionsForNewDirectory(Permissions defaultPermissionsForNewDirectory)
public String getPrimaryGroup()
DEFAULT_GROUP
. Otherwise, this method
returns the first group name in the groups
list.public boolean isValidPassword(String password)
password
- - the password to compare against the configured valueAssertFailedException
- - if the username property is nullpublic boolean isValid()
public String toString()
public boolean canRead(FileSystemEntry entry)
entry
- - the FileSystemEntry representing the file or directorypublic boolean canWrite(FileSystemEntry entry)
entry
- - the FileSystemEntry representing the file or directorypublic boolean canExecute(FileSystemEntry entry)
entry
- - the FileSystemEntry representing the file or directoryprotected boolean comparePassword(String password)
password
- - the password to compare against the configured valueCopyright © 2016. All rights reserved.