Class EjwsUserTable<A extends EjwsAuthenticator,E extends EjwsAuthenticator.Entry>
- Direct Known Subclasses:
GPGSecureBasicUT
EjwsBasicAuthenticator and EjwsSecureBasicAuth,
which require a simpler API than instances of
Map provides.
Subclasses of this class can be written so that user data is
stored in a database, or whatever type of persistent storage is
desired. A sublcass should override hasDB()
so that it will always return true. A subclass should also override
the following protected methods:
-
loadEntriesFromDB(Map). This method will load the current map with entries from persistent storage. -
getEntryFromDB(E, java.lang.String). This method will fetch an entry from persistent storage. -
createEntryFromDB(String). This method creates a new entry based on data in persistent storage. -
copyEntryToDB(String,EjwsAuthenticator.Entry,boolean). This method will add an entry to persistent storage. -
removeEntryFromDB(java.lang.String). This method will remove an entry from persistent storage.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcopyEntryToDB(String user, E entry, boolean newEntry) Add an entry to persistent storage.protected voidcreateEntryFromDB(String user) Create an entry corresponding to the data in persistent storage.protected AGet the authenticator that uses thisEjwsUserTable.final EGet an entry.protected EgetEntryFromDB(E oldEntry, String user) Get an entry corresponding to the data in persistent storage.Get the roles for a user.protected booleanhasDB()Determine if persistent storage exists.protected voidloadEntriesFromDB(Map<String, E> map) Set up the map based on information in persistent storage.final booleanmakeActive(String user) protected voidmakeActiveInDB(String user) final booleanAdd or replace an entry.final booleanremoveEntry(String user) Remove an entry.protected voidremoveEntryFromDB(String user) Remove an entry from persistent storage.voidSet the authenticator that uses thisEjwsUserTable.voidSet the user-table's map.final booleanupdateEntry(String user) Update an entry in the map.
-
Constructor Details
-
EjwsUserTable
public EjwsUserTable()Constructor.
-
-
Method Details
-
setMap
Set the user-table's map. This method is called byEjwsBasicAuthenticator.setUserTable(org.bzdev.ejws.EjwsUserTable<org.bzdev.ejws.EjwsBasicAuthenticator, org.bzdev.ejws.EjwsBasicAuthenticator.Entry>)andEjwsSecureBasicAuth.setUserTable(org.bzdev.ejws.EjwsUserTable<org.bzdev.ejws.EjwsSecureBasicAuth, org.bzdev.ejws.EjwsSecureBasicAuth.Entry>).- Parameters:
map- the map
-
setAuth
Set the authenticator that uses thisEjwsUserTable. This method is called byEjwsBasicAuthenticator.setUserTable(org.bzdev.ejws.EjwsUserTable<org.bzdev.ejws.EjwsBasicAuthenticator, org.bzdev.ejws.EjwsBasicAuthenticator.Entry>)andEjwsSecureBasicAuth.setUserTable(org.bzdev.ejws.EjwsUserTable<org.bzdev.ejws.EjwsSecureBasicAuth, org.bzdev.ejws.EjwsSecureBasicAuth.Entry>).- Parameters:
auth- the authenticator;
-
getAuthenticator
Get the authenticator that uses thisEjwsUserTable.- Returns:
- the authenticator.
-
getRoles
Get the roles for a user.- Returns:
- the roles; null or an empty set if there are no roles
-
getEntry
Get an entry. The value returned will be the entry in the map passed to the constructor. Instead of using this method, one can look up the entry directly from the map.- Parameters:
user- the user name- Returns:
- the entry
-
putEntry
Add or replace an entry. Typically, one will callgetEntry(java.lang.String), modify the entry this method returns, and then callputEntry(String,Entry)to update the value. If the operation fails this authenticator's map will be restored to its previous value.- Parameters:
user- the user nameentry- the new entry- Returns:
- true if successful; false if the operation failed.
-
makeActive
-
updateEntry
Update an entry in the map. This method should be called when data in persistent storage for the given user has changed—otherwise the persistent storage and the corresponding authentication will be inconsistent.If a new user is created by modifying persistent storage, this method will make that new user available to an authenticator. The protected method
getEntryFromDB(EjwsAuthenticator.Entry,String)is used to obtain the entry, and if that value is null, the user is removed from the map; otherwise the map is updated, either replacing an existing entry or creating a new one.- Parameters:
user- the user name
-
removeEntry
Remove an entry.- Parameters:
user- the user name- Returns:
- true on success; false on failure
-
loadEntriesFromDB
Set up the map based on information in persistent storage. This method is called bysetMap(java.util.Map<java.lang.String, E>).- Parameters:
map- the map- Throws:
Exception
-
createEntryFromDB
Create an entry corresponding to the data in persistent storage.Subclasses for which
hasDB()returnstruemust override this method.- Parameters:
user- the user name- Throws:
Exception
-
getEntryFromDB
Get an entry corresponding to the data in persistent storage.Subclasses for which
hasDB()returnstruemust override this method.- Parameters:
user- the user name- Returns:
- the entry; null if there is none in persistent storage
- Throws:
Exception
-
makeActiveInDB
- Throws:
Exception
-
copyEntryToDB
Add an entry to persistent storage. This method will be used to create a new entry and to modify an existing one.Subclasses for which
hasDB()returnstruemust override this method.- Parameters:
user- the user nameentry- the entrynewEntry- true if the local map did not have an existing entry; false if it had an existing entry- Throws:
Exception- if an error occurred, in which case the previous value in persistent storage should not be changed.
-
removeEntryFromDB
Remove an entry from persistent storage.Subclasses for which
hasDB()returnstruemust override this method.- Parameters:
user- the user name- Throws:
Exception
-
hasDB
protected boolean hasDB()Determine if persistent storage exists. For a given instance of EjwsUserTable, this method should always return the same value.- Returns:
- true if persistent storage exists; false otherwise.
-