@Service public final class FileRealm extends IASRealm
In addition to the basic realm functionality, this class provides administration methods for the file realm.
Format of the keyfile used by this class is one line per user
containing username;password;groups where:
The file realm needs the following properties in its configuration:
| Modifier and Type | Field and Description |
|---|---|
static String |
AUTH_TYPE |
static String |
PARAM_KEYFILE |
JAAS_CONTEXT_PARAM, sm_logger, groupMapper, PARAM_GROUP_MAPPING| Constructor and Description |
|---|
FileRealm() |
FileRealm(String keyfile)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addUser(String name,
char[] password,
String[] groupList)
Adds new user to file realm.
|
String[] |
authenticate(String user,
char[] password)
Authenticates a user.
|
String |
getAuthType()
Returns a short (preferably less than fifteen characters) description
of the kind of authentication which is supported by this realm.
|
Enumeration |
getGroupNames()
Returns names of all the groups in this particular realm.
|
Enumeration |
getGroupNames(String username)
Returns the name of all the groups that this user belongs to.
|
static List<String> |
getRealmFileNames(Config config)
Return a list of the file names used by all file realms
defined for the specified config.
|
User |
getUser(String name)
Returns the information recorded about a particular named user.
|
Enumeration<String> |
getUserNames()
Returns names of all the users in this particular realm.
|
boolean |
hasAuthenticatableUser() |
protected void |
init(Properties props)
Initialize a realm with some properties.
|
void |
persist()
Persist the realm data to permanent storage
|
void |
refresh()
Refreshes the realm data so that new users/groups are visible.
|
void |
refresh(String configName)
Refreshes the realm data so that new users/groups are visible.
|
void |
removeUser(String name)
Remove user from file realm.
|
boolean |
supportsUserManagement() |
void |
updateUser(String name,
String newName,
char[] password,
String[] groups)
Update data for an existing user.
|
addUser, getAuthenticationHandler, updateUseraddAssignGroups, compareTo, getDefaultDigestAlgorithm, getDefaultInstance, getDefaultRealm, getInstance, getInstance, getJAASContext, getMappedGroupNames, getName, getProperties, getProperty, getRealmNames, getRealmStatsProvier, instantiate, instantiate, instantiate, isValidRealm, isValidRealm, setDefaultRealm, setName, setProperty, toString, unloadInstance, unloadInstance, updateInstance, updateInstancepublic static final String AUTH_TYPE
public static final String PARAM_KEYFILE
public FileRealm(String keyfile) throws BadRealmException, NoSuchRealmException
The created FileRealm instance is not registered in the Realm registry. This constructor can be used by admin tools to create a FileRealm 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.BadRealmException - If the configuration parameters
identify a corrupt realm.NoSuchRealmException - If the configuration parameters
specify a realm which doesn't exist.public FileRealm()
public static List<String> getRealmFileNames(Config config)
config - the config objectprotected void init(Properties props) throws BadRealmException, NoSuchRealmException
init in class Realmprops - Initialization parameters used by this realm.BadRealmException - If the configuration parameters
identify a corrupt realm.NoSuchRealmException - If the configuration parameters
specify a realm which doesn't exist.public String getAuthType()
getAuthType in class Realmpublic Enumeration<String> getUserNames() throws BadRealmException
getUserNames in class BaseRealmBadRealmException - if realm data structures are badpublic User getUser(String name) throws NoSuchUserException
getUser in class BaseRealmname - Name of the user whose information is desired.NoSuchUserException - if the user doesn't exist.BadRealmException - if realm data structures are bad.public Enumeration getGroupNames() throws BadRealmException
getGroupNames in class BaseRealmBadRealmException - if realm data structures are badpublic Enumeration getGroupNames(String username) throws NoSuchUserException
getGroupNames in class Realmusername - Name of the user in this realm whose group listing
is needed.InvalidOperationException - thrown if the realm does not
support this operation - e.g. Certificate realm does not support
this operation.NoSuchUserExceptionpublic void refresh()
throws BadRealmException
A new FileRealm instance is created and initialized from the keyfile on disk. The new instance is installed in the Realm registry so future Realm.getInstance() calls will obtain the new data. Any existing references to this instance (e.g. in active LoginModule sessions) are unaffected.
refresh in class BaseRealmBadRealmException - if realm data structures are badpublic void refresh(String configName) throws BadRealmException
A new FileRealm instance is created and initialized from the keyfile on disk. The new instance is installed in the Realm registry so future Realm.getInstance() calls will obtain the new data. Any existing references to this instance (e.g. in active LoginModule sessions) are unaffected.
refresh in class Realmconfig - BadRealmException - if realm data structures are badpublic void addUser(String name, char[] password, String[] groupList) throws BadRealmException, IASSecurityException
addUser in class BaseRealmname - User name.password - Cleartext password for the user.groupList - List of groups to which user belongs.BadRealmException - If there are problems adding user.IASSecurityExceptionpublic void removeUser(String name) throws NoSuchUserException, BadRealmException
removeUser in class BaseRealmname - User name.NoSuchUserException - If user does not exist.BadRealmExceptionpublic void updateUser(String name, String newName, char[] password, String[] groups) throws NoSuchUserException, BadRealmException, IASSecurityException
updateUser in class BaseRealmname - Current name of the user to update.newName - 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.BadRealmException - If there are problems adding user.NoSuchUserException - If user does not exist.IASSecurityExceptionpublic String[] authenticate(String user, 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.
user - Name of user to authenticate.password - Password provided by client.LoginException - If there are errors during authentication.public boolean hasAuthenticatableUser()
public boolean supportsUserManagement()
supportsUserManagement in class BaseRealmpublic void persist()
throws BadRealmException
persist in class BaseRealmBadRealmExceptionCopyright © 2017. All rights reserved.