Class EjwsUserTable<A extends EjwsAuthenticator,E extends EjwsAuthenticator.Entry>
- Direct Known Subclasses:
DefaultBasicUT,DefaultSecureBasicUT
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 subclass must override the following 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. -
removeEntryFromDB(java.lang.String). This method will remove an entry from persistent storage. -
makeActiveInDB(String). This method will configure persistent storage so that a user is active -
storeGPGKey(String,EjwsAuthenticator.GPGKeyIDs). This method will store a GPG key. -
storeSBLData(String,EjwsAuthenticator.AddStatus). This method will store data in persistent storage based on a string representation of an SBL file. -
storePW(String,String,boolean). This method will store a password, indicating whether the user is active or not.
String argument, if
there is one, is a string providing a user name, often an email
address.
If persistent storage is altered, either the method
updateEntry(String) or
EjwsAuthenticator's createUser methods (along with
EjwsAuthenticator.UserInfo methods) should be called so that
the authenticator will record the change.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract 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 abstract EgetEntryFromDB(E oldEntry, String user) Get an entry corresponding to the data in persistent storage.Get the roles for a user.protected abstract voidloadEntriesFromDB(Map<String, E> map) Set up the map based on information in persistent storage.final booleanmakeActive(String user) Make a user active.protected abstract voidmakeActiveInDB(String user) Make an entry active in persistent storage.final booleanmakePending(String user) Make a user pending.protected abstract voidmakePendingInDB(String user) Make an entry pending in persistent storage.final EAdd or replace an entry.final booleanremoveEntry(String user) Remove an entry.protected abstract voidremoveEntryFromDB(String user) Remove an entry from persistent storage.voidSet the authenticator that uses thisEjwsUserTable.voidSet the user-table's map.abstract voidstoreGPGKey(String value, EjwsAuthenticator.GPGKeyIDs keyids) Store a PGP/GPG key.abstract voidStore a basic-authentication password.abstract voidstoreSBLData(String s, EjwsAuthenticator.AddStatus status) Store SBL data that was provided using the string representation.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>). One of those methods should be called before an instance of this class is used.Normally, this method should be called only by subclasses of
EjwsUserTable.- 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>). One of those methods should be called before an instance of this class is used.Normally, this method should be called only by subclasses of
EjwsUserTable.- 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 an operation using this method fails the authenticator's map should be restored to its previous value.- Parameters:
user- the user nameentry- the new entry- Returns:
- true if successful; false if the operation failed.
-
makeActive
Make a user active.- Parameters:
user- the user- Returns:
- true on success; false on error or if the user was already active
-
makePending
Make a user pending.- Parameters:
user- the user- Returns:
- true on success; false on error or if the user was already pending
-
storeGPGKey
public abstract void storeGPGKey(String value, EjwsAuthenticator.GPGKeyIDs keyids) throws IllegalArgumentException, IllegalStateException, IOException Store a PGP/GPG key. The keyids argument is used for test to make sure we do not replace existing keys with unrelated ones.- Parameters:
value- an ASCII-armored PGP/GPG public key.keyids- a container for the key's email address and the key's fingerprint- Throws:
NullPointerException- if the GPG home directory had not been set (for implementations that specify a GPG home directory)IllegalArgumentException- if the key is ill-formedIllegalStateException- if the key cannot be storedIOException- if an IO error occurs while constructing a cannonical path
-
storeSBLData
Store SBL data that was provided using the string representation. If status isEjwsAuthenticator.AddStatus.REJECTED, this method should not be called by an authenticator.Implementation note: the method
EjwsAuthenticator.getUserNameFromSBL(String)can be used to find the user name. If the contents of the string s should be stored rather than s itself, the constructorConfigProperties(String,String)can be called with s as its first argument and the string "application/vnd.bzdev.sblauncher" as its second argument. This SBL file should have a single key KEY and a field named KEY.description or possibly base64.KEY.description, which can be used to determine the key KEY. Normally KEY will be the string user.- base64.keypair.publicKey. A base-64 encoded, PEM encoded public key.
- KEY.user. The user's name (email address is preferred).
- base64.KEY.password. The password.
- KEY.base. The shared prefix used by this user table's authenticator. It must end with a "/".
- KEY.uri. The URI to visit. If it starts with $(KEY.base), that will be replaced with the value of the KEY.base field.
- KEY.mode. The ordinal of an enumeration
constant defined by
SecureBasicUtilities.Mode:- 0 for DIGEST.
- 1 for SIGNATURE_WITHOUT_CERT.
- 2 for SIGNATURE_WITH_CERT.
- 3 for PASSWORD.
- Parameters:
s- SBL data in string formstatus- the status of the request (EjwsAuthenticator.AddStatus.OKorEjwsAuthenticator.AddStatus.PENDING)- Throws:
Exception- if there is an error
-
storePW
Store a basic-authentication password.- Parameters:
un- the user namepw- the passwordisActive- true if the user is active; false otherwise- Throws:
Exception- if there is an error
-
updateEntry
Update an entry in the map. This method should be called when data in persistent storage for the given user has been changed explicitly, rather than by this user table's authenticator—otherwise the persistent storage and the corresponding authenticator will be inconsistent.If there is no current entry for a user, the method
createEntryFromDB(String)will be called with the user name as its argument. The value returned will then be put into the map with the user name as the map's key.If there is an existing user, the method
getEntryFromDB(E,String)will be called to get a replacement entry, with the existing entry as its first argument and the user name as its second argument. If the replacement entry is null, the user is removed from the map; otherwise the map is updated.- Parameters:
user- the user name- Returns:
- true normally; false if there was a failure that threw an exception
-
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>).The source code for
DefaultBasicUTandDefaultSecureBasicUTare useful guides for an implementation.- Parameters:
map- the map- Throws:
Exception- if an error occurred
-
createEntryFromDB
Create an entry corresponding to the data in persistent storage.The source code for
DefaultBasicUTandDefaultSecureBasicUTare useful guides for an implementation.- Parameters:
user- the user name- Throws:
Exception- if an error occurs
-
getEntryFromDB
Get an entry corresponding to the data in persistent storage.The source code for
DefaultBasicUTandDefaultSecureBasicUTare useful guides for an implementation.- Parameters:
oldEntry- the previous map entryuser- the user name- Returns:
- the entry; null if there is none in persistent storage
- Throws:
Exception- if an error occurs
-
makeActiveInDB
Make an entry active in persistent storage.This may be called by EJWS when an admin page is used, when an account is uses an authorization code, or when any new account is accepted.
- Parameters:
user- the user name- Throws:
Exception- if there is an error
-
makePendingInDB
Make an entry pending in persistent storage.This may be called when an admin page changes an account from active to pending. The source code for
DefaultBasicUTandDefaultSecureBasicUTare useful guides for an implementation.- Parameters:
user- the user name- Throws:
Exception- if there is an error
-
removeEntryFromDB
Remove an entry from persistent storage.This may be called by EJWS when an admin page deletes an account. The source code for
DefaultBasicUTandDefaultSecureBasicUTare useful guides for an implementation.- Parameters:
user- the user name- Throws:
Exception- if an error occurs
-