|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mockftpserver.fake.UserAccount
public class UserAccount
Represents a single user account on the server, including the username, password, home directory, list of groups to which this user belongs, and default permissions applied to newly-created files and directories.
Theusername 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 .
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.
Field Summary
static String
DEFAULT_GROUP
static Permissions
DEFAULT_PERMISSIONS_FOR_NEW_DIRECTORY
static Permissions
DEFAULT_PERMISSIONS_FOR_NEW_FILE
static String
DEFAULT_USER
Constructor Summary
UserAccount()
Construct a new uninitialized instance.
UserAccount(String username,
String password,
String homeDirectory)
Construct a new initialized instance.
Method Summary
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()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Field Detail
DEFAULT_USER
public static final String DEFAULT_USER
- See Also:
- Constant Field Values
DEFAULT_GROUP
public static final String DEFAULT_GROUP
- See Also:
- Constant Field Values
DEFAULT_PERMISSIONS_FOR_NEW_FILE
public static final Permissions DEFAULT_PERMISSIONS_FOR_NEW_FILE
DEFAULT_PERMISSIONS_FOR_NEW_DIRECTORY
public static final Permissions DEFAULT_PERMISSIONS_FOR_NEW_DIRECTORY
Constructor Detail
UserAccount
public UserAccount()
- Construct a new uninitialized instance.
UserAccount
public UserAccount(String username,
String password,
String homeDirectory)
- Construct a new initialized instance.
- Parameters:
username - - the user namepassword - - the passwordhomeDirectory - - the home directory
Method Detail
getUsername
public String getUsername()
setUsername
public void setUsername(String username)
getPassword
public String getPassword()
setPassword
public void setPassword(String password)
getHomeDirectory
public String getHomeDirectory()
setHomeDirectory
public void setHomeDirectory(String homeDirectory)
getGroups
public List getGroups()
setGroups
public void setGroups(List groups)
isPasswordRequiredForLogin
public boolean isPasswordRequiredForLogin()
setPasswordRequiredForLogin
public void setPasswordRequiredForLogin(boolean passwordRequiredForLogin)
isPasswordCheckedDuringValidation
public boolean isPasswordCheckedDuringValidation()
setPasswordCheckedDuringValidation
public void setPasswordCheckedDuringValidation(boolean passwordCheckedDuringValidation)
isAccountRequiredForLogin
public boolean isAccountRequiredForLogin()
setAccountRequiredForLogin
public void setAccountRequiredForLogin(boolean accountRequiredForLogin)
getDefaultPermissionsForNewFile
public Permissions getDefaultPermissionsForNewFile()
setDefaultPermissionsForNewFile
public void setDefaultPermissionsForNewFile(Permissions defaultPermissionsForNewFile)
getDefaultPermissionsForNewDirectory
public Permissions getDefaultPermissionsForNewDirectory()
setDefaultPermissionsForNewDirectory
public void setDefaultPermissionsForNewDirectory(Permissions defaultPermissionsForNewDirectory)
getPrimaryGroup
public String getPrimaryGroup()
- Return the name of the primary group to which this user belongs. If this account has no associated
groups set, then this method returns the
DEFAULT_GROUP. Otherwise, this method
returns the first group name in the groups list.
- Returns:
- the name of the primary group for this user
isValidPassword
public boolean isValidPassword(String password)
- Return true if the specified password is the correct, valid password for this user account.
This implementation uses standard (case-sensitive) String comparison. Subclasses can provide
custom comparison behavior, for instance using encrypted password values, by overriding this
method.
- Parameters:
password - - the password to compare against the configured value
- Returns:
- true if the password is correct and valid
- Throws:
AssertFailedException - - if the username property is null
isValid
public boolean isValid()
- Returns:
- true if this UserAccount object is valid; i.e. if the homeDirectory is non-null and non-empty.
toString
public String toString()
- Overrides:
toString in class Object
- Returns:
- the String representation of this object
canRead
public boolean canRead(FileSystemEntry entry)
- Return true if this user has read access to the file/directory represented by the specified FileSystemEntry object.
- Parameters:
entry - - the FileSystemEntry representing the file or directory
- Returns:
- true if this use has read access
canWrite
public boolean canWrite(FileSystemEntry entry)
- Return true if this user has write access to the file/directory represented by the specified FileSystemEntry object.
- Parameters:
entry - - the FileSystemEntry representing the file or directory
- Returns:
- true if this use has write access
canExecute
public boolean canExecute(FileSystemEntry entry)
- Return true if this user has execute access to the file/directory represented by the specified FileSystemEntry object.
- Parameters:
entry - - the FileSystemEntry representing the file or directory
- Returns:
- true if this use has execute access
comparePassword
protected boolean comparePassword(String password)
- Return true if the specified password matches the password configured for this user account.
This implementation uses standard (case-sensitive) String comparison. Subclasses can provide
custom comparison behavior, for instance using encrypted password values, by overriding this
method.
- Parameters:
password - - the password to compare against the configured value
- Returns:
- true if the passwords match
equalOrBothNull
protected boolean equalOrBothNull(String string1,
String string2)
- Return true only if both Strings are null or they are equal (have the same contents).
- Parameters:
string1 - - the first Stringstring2 - - the second String
- Returns:
- true if both are null or both are equal
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
Copyright © 2014. All rights reserved.