Implementation of BasicAuthenticator using either an in-memory table
of user names and passwords or a user-supplied table.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.bzdev.ejws.EjwsAuthenticator
EjwsAuthenticator.AddStatus, EjwsAuthenticator.BiConsumer1, EjwsAuthenticator.BiConsumer2, EjwsAuthenticator.GPGKeyIDs, EjwsAuthenticator.UserInfoNested classes/interfaces inherited from class com.sun.net.httpserver.Authenticator
Authenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success -
Field Summary
Fields inherited from class org.bzdev.ejws.EjwsAuthenticator
authFunction, loginFunction, logoutFunction, onAccountActive, onAccountPending, onAccountRemoval, onAccountRequest, tracerFields inherited from class com.sun.net.httpserver.BasicAuthenticator
realm -
Constructor Summary
ConstructorsConstructorDescriptionEjwsBasicAuthenticator(EmbeddedWebServer ews, String realm) Constructor.EjwsBasicAuthenticator(EmbeddedWebServer ews, String realm, Map<String, EjwsBasicAuthenticator.Entry> map) Constructor providing a map. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a user name and password for this authenticator's HTTP realm.voidAdd a user name, the user's password and the user's roles for this authenticator's HTTP realm.voidAdd a user specified by an instance ofEjwsAuthenticator.UserInfo.Authenticate an HTTP request.booleancheckCredentials(String username, String password) Check credentials.protected Map<String,? extends EjwsAuthenticator.Entry> Get the authentication map association user names with authentication data..getMode()Get the mode.byte[]Get the SBL file for a usergetUsers()Get the names of all users known to this authenticator.getUsers(boolean active) Get selected users known to this authenticator.Get this authenticator's user tablevoidhandleError(HttpExchange t, Exception e) Handle exceptions by sending an error responsebooleanDetermine if a user is currently active.booleanisSBLCompressed(String user) Determine if the SBL file is compresssed using GZIP.Load user-account data obtained from GPG or an SBL directorybooleanmakeUserActive(String name) Make a user active.booleanmakeUserActive(String name, boolean gpg) Make a user active, specifying if the user is one for whom GPG is used to provide the data needed to log in.protected booleanmakeUserActiveInMap(String name) Make a user active, modifying only the authenticator's map.booleanmakeUserPending(String name) Make a user pendijng.booleanmakeUserPending(String name, boolean gpg) Make a user pending, specifying if the user is one for whom GPG is used to provide the data needed to log in.protected booleanmakeUserPendingInMap(String name) Make a user pending, modifying only the authenticator's map.voidprune()Remove cached passwords whose timeout has expired.voidremovePWInfo(String username) Remove an entry from the password map.booleanremoveUser(String name) Remove a user.booleanremoveUser(String name, boolean gpg) Remove a user.protected booleanremoveUserFromMap(String name) Remove a user, modifying only the authenticator's map.setTimeLimit(int passphraseTimeout) Set the time limit for a passphrase/password.setTimeLimits(int lowerTimeDiffLimit, int upperTimeDiffLimit, int passphraseTimeout) Set time-offset limits.Set this authenticator's user table.Methods inherited from class org.bzdev.ejws.EjwsAuthenticator
addToAdminMap, addToDeleteSet, closeSBLStore, createAuthCode, createAuthCookie, createServerCookie, createUser, createUser, createUser, createUser, createUser, deleteWithFingerprint, findAuthServerCookie, findServerCookie, generateAdminURI, generateRequestURI, getActiveGPGUsers, getAdminFingerprint, getAdminUsers, getAuthCode, getCanAddAccount, getFingerprint, getGPGUsers, getLoginAlias, getLoginPath, getPendingGPGUsers, getReverseProxy, getSBLStore, getSBLUsers, getTrustedKeyIDs, getUserNameFromSBL, getUsersExcept, getUserStatus, gpghome, hasGPGKey, inDeleteSet, isActiveDefault, isEmailAddress, isTrustedKey, processAdminRequests, readSBLData, removeFromDeleteSet, requestFromUser, setAllowLoopback, setAuthorizedFunction, setCanAddAccount, setCookie, setDefaultActive, setGPGHome, setLoginFunction, setLogoutFunction, setOnAccountActive, setOnAccountPending, setOnAccountRemoval, setOnAccountRequest, setReverseProxy, setSBLStore, setSBLStore, setSelfSigned, setThisObject, setTracer, setTruststore, setTruststorePW, setupKeySigner, setUserStatusFunction, showGPGKey, signKey, signKey, storeGPGKey, storeSBLData, trustGPGKey, validGPGUserMethods inherited from class com.sun.net.httpserver.BasicAuthenticator
getRealm
-
Constructor Details
-
EjwsBasicAuthenticator
Constructor.- Parameters:
realm- the HTTP realm
-
EjwsBasicAuthenticator
public EjwsBasicAuthenticator(EmbeddedWebServer ews, String realm, Map<String, EjwsBasicAuthenticator.Entry> map) Constructor providing a map. A user-supplied map can be implemented so as to allow one to obtain passwords and roles from a database or some other form of persistent storage. If entries can be added while a server using this authenticator is running, the map should have a thread-safe implementation.- Parameters:
realm- the HTTP realmmap- a map associating a user name with a table entry.
-
-
Method Details
-
isActive
Determine if a user is currently active. The authenticator's internal tables are tested, not values in persistent storage.- Specified by:
isActivein classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- true if the user exists and is active; false otherwise
-
getAuthMap
Get the authentication map association user names with authentication data..- Specified by:
getAuthMapin classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- the map
-
getUsers
Get the names of all users known to this authenticator. The value returned is an unmodifiable set.- Specified by:
getUsersin classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- the users
-
getUsers
Get selected users known to this authenticator.- Specified by:
getUsersin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
active- true if the users are active; false if they are not active
-
getSBL
Get the SBL file for a user- Specified by:
getSBLin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
user- the user- Returns:
- the SBL file as a byte array; null if there is none
-
isSBLCompressed
Determine if the SBL file is compresssed using GZIP.- Specified by:
isSBLCompressedin classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- true if the SBL file is compressed; false otherwise
- See Also:
-
setTimeLimit
Set the time limit for a passphrase/password.- Parameters:
passphraseTimeout- the time interval in seconds for which a password is valid (the default is 1200); 0 to disable the timeout- Returns:
- this authenticator
- Throws:
IllegalArgumentException- if the argument is less than zero.
-
setTimeLimits
public EjwsBasicAuthenticator setTimeLimits(int lowerTimeDiffLimit, int upperTimeDiffLimit, int passphraseTimeout) throws IllegalArgumentException Set time-offset limits. For the modesSecureBasicUtilities.Mode.DIGEST,SecureBasicUtilities.Mode.SIGNATURE_WITH_CERT, andSecureBasicUtilities.Mode.SIGNATURE_WITHOUT_CERT, each password that is generated contains a time stamp in units of seconds. The time difference is the difference between the current time and the time stamp associated with a password.The first argument will generally be negative to handle the case in which the clock for the client generating the password is ahead of the server's clock. The second argument will generally be positive to handle the case in which the client's clock is behind the server's clock and to additionally account for propagation delay and to limit the number of times a password has to be recomputed. To allow for software that does not implement secure basic authentication, the value should be above the expected maximum length of a user's session.
The lowerTimeDiffLimit and upperTImeDiffLimit arguments are used for the admin account, not other accounts.
- Parameters:
lowerTimeDiffLimit- the lower limit for the time difference in seconds (the default is -10 seconds).upperTimeDiffLimit- the upper limit for the time difference in seconds (the default is 150 seconds)passphraseTimeout- the time interval in seconds for which a password is valid (the default is 1200); 0 to disable this timeout- Returns:
- this authenticator
- Throws:
IllegalArgumentException- if the first argument is larger than zero, if the second argument is less than zero, or if the third argument, when not zero, is less than the second argument
-
add
public void add(String username, String password) throws UnsupportedOperationException, IllegalStateException Add a user name and password for this authenticator's HTTP realm. The new entry will use password authentication.- Parameters:
username- the user namepassword- the password- Throws:
UnsupportedOperationException- if the map does not allow entries to be added (the default map does not throw this exception)IllegalStateException- if the map already contains the user
-
add
public void add(String username, String password, Set<String> roles) throws UnsupportedOperationException, IllegalStateException Add a user name, the user's password and the user's roles for this authenticator's HTTP realm. The new entry will use password authentication.- Parameters:
username- the user namepassword- the user's passwordroles- the user's roles- Throws:
UnsupportedOperationException- if the map does not allow entries to be added (the default map does not throw this exception)IllegalStateException- if the map already contains the user
-
setUserTable
public EjwsBasicAuthenticator setUserTable(EjwsUserTable<EjwsBasicAuthenticator, EjwsBasicAuthenticator.Entry> utable) Set this authenticator's user table.- Parameters:
utable- the user table- Returns:
- this authenticator
-
getUserTable
Get this authenticator's user table- Specified by:
getUserTablein classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- the user table.
-
add
Add a user specified by an instance ofEjwsAuthenticator.UserInfo.- Specified by:
addin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
info- the user data- Throws:
IllegalStateException
-
removeUser
Remove a user.- Specified by:
removeUserin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user namegpg- true to delete GPG permanent entries; false for SBL permanent entries
-
removeUser
Remove a user.- Specified by:
removeUserin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the name of the user
-
makeUserActive
Make a user active, specifying if the user is one for whom GPG is used to provide the data needed to log in.- Specified by:
makeUserActivein classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user's namegpg- true if GPG is used; false if an SBL directory is used
-
makeUserActiveInMap
Make a user active, modifying only the authenticator's map.- Specified by:
makeUserActiveInMapin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user name- Returns:
- true on success; false if there is no such user
-
makeUserPending
Make a user pendijng.- Specified by:
makeUserPendingin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user's name
-
makeUserPending
Make a user pending, specifying if the user is one for whom GPG is used to provide the data needed to log in.- Specified by:
makeUserPendingin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user's namegpg- true if GPG is used; false if an SBL directory is used
-
makeUserPendingInMap
Make a user pending, modifying only the authenticator's map.- Specified by:
makeUserPendingInMapin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user name- Returns:
- true on success; false if there is no such user
-
removeUserFromMap
Remove a user, modifying only the authenticator's map.- Specified by:
removeUserFromMapin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user name- Returns:
- true on success; false if there is no such user
-
makeUserActive
Make a user active.- Specified by:
makeUserActivein classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
name- the user's name
-
loadFromDirs
Load user-account data obtained from GPG or an SBL directory- Overrides:
loadFromDirsin classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- this object
- Throws:
UnsupportedOperationException- See Also:
-
handleError
Handle exceptions by sending an error response- Parameters:
t- theHttpExchangebeing processede- an exception that is being handled- Throws:
IOException
-
authenticate
Authenticate an HTTP request.- Overrides:
authenticatein classBasicAuthenticator- Parameters:
t- the HTTP exchange object- Returns:
- the authentication result
- See Also:
-
removePWInfo
Remove an entry from the password map. This is called when logging out.- Overrides:
removePWInfoin classEjwsAuthenticator<EjwsBasicAuthenticator>- Parameters:
username- the user name
-
getMode
Get the mode.- Specified by:
getModein classEjwsAuthenticator<EjwsBasicAuthenticator>- Returns:
- SecureBasicUtilities.Mode.PASSWORD
-
prune
public void prune()Remove cached passwords whose timeout has expired. The method can be called periodically to eliminate passwords when a user has not explicitly logged out. -
checkCredentials
Check credentials. This method is called for each incoming request to verify the given name and password in the context of this Authenticator's realm.- Specified by:
checkCredentialsin classBasicAuthenticator- Parameters:
username- the user namepassword- the password
-