public final class FileRealmStorageManager extends Object
This class provides administration methods for the file realm. It is used by the FileRealm class to provide the FileRealm functionality. But some administration classes that need direct access to the File without using the security module use this class directly.
Format of the keyfile used by this class is one line per user containing username;password;groups
where:
If the password is "RESET", then the password must be reset before that user can authenticate.
The file realm needs the following properties in its configuration:
Modifier and Type | Class and Description |
---|---|
static class |
FileRealmStorageManager.User
Represents a FileRealm user.
|
Modifier and Type | Field and Description |
---|---|
static String |
MISC_VALID_CHARS |
static String |
PARAM_KEYFILE |
Constructor and Description |
---|
FileRealmStorageManager(String keyfileName)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addUser(String username,
char[] password,
String[] groupList)
Adds new user to file realm.
|
String[] |
authenticate(String username,
char[] password)
Authenticates a user.
|
Set<String> |
getGroupNames()
Returns names of all the groups in this particular realm.
|
String[] |
getGroupNames(String username)
Returns the name of all the groups that this user belongs to.
|
FileRealmStorageManager.User |
getUser(String name)
Returns the information recorded about a particular named user.
|
Set<String> |
getUserNames()
Returns names of all the users in this particular realm.
|
boolean |
hasAuthenticatableUser()
Test whether their is a user in the FileRealm that has a password that has been set, i.e., something other than the
resetKey.
|
void |
persist()
Write keyfile data out to disk.
|
void |
removeUser(String username)
Remove user from file realm.
|
void |
updateUser(String username,
String newUsername,
char[] password,
String[] groups)
Update data for an existing user.
|
static void |
validateGroupList(String[] groupNames)
Validates syntax of a list of group names.
|
static void |
validateGroupName(String group)
Validates syntax of a group name.
|
static void |
validatePassword(char[] password)
Validates syntax of a password.
|
static void |
validateUserName(String name)
Validates syntax of a user name.
|
public static final String PARAM_KEYFILE
public static final String MISC_VALID_CHARS
public FileRealmStorageManager(String keyfileName) throws IOException
The created FileRealmStorageManager instance is not registered in the Realm registry. This constructor can be used by admin tools to create a FileRealmStorageManager instance which can be edited by adding or removing users and then saved to disk, without affecting the installed realm instance.
The file provided should always exist. A default (empty) keyfile is installed with the server so this should always be the case unless the user has manually deleted this file. If this file path provided does not point to an existing file this constructor will first attempt to create it. If this succeeds the constructor returns normally and an empty keyfile will have been created; otherwise an exception is thrown.
keyfile
- Full path to the keyfile to read for user data.IOException
- If the configuration parameters identify a corrupt keyfilepublic FileRealmStorageManager.User getUser(String name)
name
- Name of the user whose information is desired.public Set<String> getUserNames()
public Set<String> getGroupNames()
public String[] getGroupNames(String username)
username
- Name of the user in this realm whose group listing is needed.public String[] authenticate(String username, char[] password)
This method is invoked by the FileLoginModule in order to authenticate a user in the file realm. The authentication decision is kept within the realm class implementation in order to keep the password cache in a single location with no public accessors, to simplify future improvements.
username
- Name of user to authenticate.password
- Password provided by client.public boolean hasAuthenticatableUser()
public void addUser(String username, char[] password, String[] groupList) throws IllegalArgumentException
username
- User name.password
- Cleartext password for the user.groupList
- List of groups to which user belongs.IllegalArgumentException
- If there are problems adding user.public void removeUser(String username) throws IllegalArgumentException
username
- User name.IllegalArgumentException
- If user does not exist.public void updateUser(String username, String newUsername, char[] password, String[] groups) throws IllegalArgumentException
username
- Current name of the user to update.newUsername
- New name to give this user. It can be the same as the original name. Otherwise it must be a new user
name which does not already exist as a user.password
- Cleartext password for the user. If non-null the user password is changed to this value. If null, the
original password is retained.groupList
- List of groups to which user belongs.IllegalArgumentException
- If there are problems adding user.public void persist() throws IOException
IOException
- if there is a failurepublic static void validateUserName(String name) throws IllegalArgumentException
This method throws an exception if the provided value is not valid. The message of the exception provides a reason why it is not valid. This is used internally by add/modify User to validate the client-provided values. It is not necessary for the client to call these methods first. However, these are provided as public methods for convenience in case some client (e.g. GUI client) wants to provide independent field validation prior to calling add/modify user.
name
- User name to validate.IllegalArgumentException
- Thrown if the value is not valid.public static void validatePassword(char[] password) throws IllegalArgumentException
This method throws an exception if the provided value is not valid. The message of the exception provides a reason why it is not valid. This is used internally by add/modify User to validate the client-provided values. It is not necessary for the client to call these methods first. However, these are provided as public methods for convenience in case some client (e.g. GUI client) wants to provide independent field validation prior to calling add/modify user.
password
- Password to validate.IllegalArgumentException
- Thrown if the value is not valid.public static void validateGroupName(String group) throws IllegalArgumentException
This method throws an exception if the provided value is not valid. The message of the exception provides a reason why it is not valid. This is used internally by add/modify User to validate the client-provided values. It is not necessary for the client to call these methods first. However, these are provided as public methods for convenience in case some client (e.g. GUI client) wants to provide independent field validation prior to calling add/modify user.
group
- Group name to validate.IllegalArgumentException
- Thrown if the value is not valid.public static void validateGroupList(String[] groupNames) throws IllegalArgumentException
This is equivalent to calling validateGroupName on every element of the groupList.
groupNames
- Array of group names to validate.IASSecurityException
- Thrown if the value is not valid.IllegalArgumentException
Copyright © 2019. All rights reserved.