- Direct Known Subclasses:
EjwsBasicAuthenticator,EjwsSecureBasicAuth
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe status of user with regard to adding the user to an authenticator.static interfaceType safe BiConsumer<String,AddStatus>.static interface/** Type safe BiConsumer<String,Boolean>.static classBase class entries in a map whose key is a user name.static classContainer class for key ids.static classClass to generate user info.Nested classes/interfaces inherited from class com.sun.net.httpserver.Authenticator
Authenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BiConsumer<EjwsPrincipal,HttpExchange> The authorization function.protected BiConsumer<EjwsPrincipal,HttpExchange> The login function.protected BiConsumer<EjwsPrincipal,HttpExchange> The logout function.protected EjwsAuthenticator.BiConsumer2The account-active monitoring function.protected EjwsAuthenticator.BiConsumer2The account-pending monitoring function.protected EjwsAuthenticator.BiConsumer2The account-removal monitoring function.protected EjwsAuthenticator.BiConsumer1The account-request monitoring function.protected AppendableTheAppendableused for tracing.Fields inherited from class com.sun.net.httpserver.BasicAuthenticator
realm -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEjwsAuthenticator(EmbeddedWebServer ews, String realm) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidAdd a user specified by an instance ofEjwsAuthenticator.UserInfo.addToAdminMap(String email, String fingerprint) Add an entry to the map associating email addresses with the fingerprint of a corresponding GPG key.protected voidaddToDeleteSet(String uname) Add a user to the set of users that will be deleted.voidClose persistent storage.createAuthCode(String secret) Add an authorization code.protected ServerCookiecreateAuthCookie(HttpExchange t, String username) Create an authentication cookie given a user name.protected static ServerCookieCreate a server cookieCreate an instance ofEjwsAuthenticator.UserInfo.Create an instance ofEjwsAuthenticator.UserInfobased on a public key provided by a remote user.createUser(String email, String title, Set<String> roles) Create an instance ofEjwsAuthenticator.UserInfo.createUser(String propsString, Set<String> roles) Create an instance ofEjwsAuthenticator.UserInfobased on a string representing aConfigPropertiesobject provided by a remote user.createUser(ConfigProperties props, Set<String> roles) Create an instance ofEjwsAuthenticator.UserInfobased on aConfigPropertiesobject provided by a remote user.voidDelete a GPG key given the key's fingerprint.protected static ServerCookieFind an authorization server cookie.protected static ServerCookieFind a server cookie.protected StringgenerateAdminURI(String username) Generate a URI for an admin page.protected StringgenerateRequestURI(String username) Generate a URI for a login request that will provide an SBL file for a user.Get GPG users in the active state.getAdminFingerprint(String email) Get the PGP fingerprint for an email address associated with the admin accountGet the users' email addresses for those users associated with the admin accountprotected AuthCodeGet the current authorization-code generator.protected abstract Map<String,? extends EjwsAuthenticator.Entry> Get the authentication map association user names with authentication data..booleanDetermine if this authenticator can add a new user account.getFingerprint(String email) Get the GPG fingerprint for an email address.getGPGUsers(boolean signed) Get GPG user names.Get the login alias.Get the login path.abstract SecureBasicUtilities.ModegetMode()Get a user's authentication mode.Get GPG users that are in the pending state.Get the reverse proxy.abstract byte[]Get the SBL file for a userGet the SBL store.getSBLUsers(boolean active) Get the users whose data is kept in the SBL directory The methodsetSBLStore(File)orsetSBLStore(SBLStore)should be called before this method is used.Get the GPG key IDs for ultimately trusted users.static StringgetUserNameFromSBL(String propsString) Get the name of a user from an SBL file.getUsers()Get the names of all users known to this authenticator.getUsers(boolean active) Get selected users known to this authenticator.getUsersExcept(Set<String> exceptions) Get all users except those in an exception set.protected EjwsAuthenticator.AddStatusgetUserStatus(String username) Get the status for a request to set up an account.abstract EjwsUserTable<? extends EjwsAuthenticator,? extends EjwsAuthenticator.Entry> Get this authenticator's user table.protected Filegpghome()Get the GPG home directory.booleanDetermine if there is a GPG Key for a specified user.booleaninDeleteSet(String uname) Determine if a user is in the set of users that will be deleted.abstract booleanDetermine if a user is currently active.booleanGet the default value for whether or not a user account is active or not.static booleanisEmailAddress(String string) Determine if a string is a syntactically valid email address.abstract booleanisSBLCompressed(String user) Determine if the SBL file is compresssed using GZIP.booleanisTrustedKey(String name) Determine if a user is ultimately trusted.Load user-account data obtained from GPG or an SBL directoryabstract booleanmakeUserActive(String name) Make a user active.abstract 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 abstract booleanmakeUserActiveInMap(String name) Make a user active, modifying only the authenticator's map.abstract booleanmakeUserPending(String name) Make a user pendijng.abstract 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 abstract booleanmakeUserPendingInMap(String name) Make a user pending, modifying only the authenticator's map.voidprocessAdminRequests(Map<String, String> deleteMap, Map<String, String> activateMap, Map<String, String> pendingMap) Process a request to remove or active user accounts EitherremoveUser(String,String)ormakeUserActive(String,String)will be called to remove or active a user respectively.protected StringRead SBL data from an input stream, storing it as a stringvoidremoveFromDeleteSet(String uname) Remove a user to the set of users that will be deleted.voidremovePWInfo(String username) Remove an entry from the password map.abstract booleanremoveUser(String name) Remove a user.abstract booleanremoveUser(String name, boolean gpg) Remove a user, specifying if the user is one for whom GPG is used to provide the data needed to log in.protected abstract booleanremoveUserFromMap(String name) Remove a user, modifying only the authenticator's map.protected byte[]requestFromUser(String username, String type, String auth) Generate a sequence of bytes containing an SBL file that instructs the SBL program as to how to download data needed to create an account.setAllowLoopback(boolean allowLoopback) Set if a loopback interface may be used for secure connections The value may be sent to clients setting up an account.setAuthorizedFunction(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the authorized function.setCanAddAccount(boolean value) Set whether or not this authenticator can add a user account.protected static voidsetCookie(HttpExchange t, ServerCookie cookie) Set a server cookie.setDefaultActive(boolean value) Set the default for whether new users are active or not.setGPGHome(File gpghome) Set the GPG home directory.setLoginFunction(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the login function.setLogoutFunction(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the logout function.Set the function called when an account becomes active.Set the function called when an account becomes pending explicitly.Set the function called when an account is removed.Set the function called when a user requests an account.protected voidsetReverseProxy(URI proxy) Set the reverse proxy.setSBLStore(File file) Set persistent storage for SBL files and/or passwords given a file.setSBLStore(SBLStore store) Set persistent storage for SBL files and/or passwords.setSelfSigned(boolean selfSigned) Set whether or not certificats may be self signed The value may be sent to clients setting up an account.protected voidsetThisObject(E thisObject) Set this object so that we can always get the actual type.setTracer(Appendable tracer) Set an Appendable for tracing.setTruststore(String truststore) Set the name of the truststore file.setTruststorePW(char[] pw) Set the truststore password.protected booleanSet up a key signer.Set the user-status function.showGPGKey(String key) Show an ASCII-armored GPG public key for use by this authenticator.booleanSign a key given an email address.protected booleanSign a key given an email address and target.voidstoreGPGKey(String key, EjwsAuthenticator.GPGKeyIDs keyids) Store an ASCII-armored GPG public key for use by this authenticator.protected voidstoreSBLData(String s, EjwsAuthenticator.AddStatus status) Store SBL data.voidtrustGPGKey(String email, boolean trust) Configure a GPG public key's trust level for this authenticator.booleanvalidGPGUser(String email) Determine if a user has a key that was signed by a key recognized by this authenticator.Methods inherited from class com.sun.net.httpserver.BasicAuthenticator
authenticate, checkCredentials, getRealm
-
Field Details
-
tracer
TheAppendableused for tracing. -
onAccountRequest
The account-request monitoring function. This function is called when a user requests an account on this server. -
onAccountActive
The account-active monitoring function. This function is called when an account is made active -
onAccountPending
The account-pending monitoring function. This function is called when an account is explicitly made pending -
onAccountRemoval
The account-removal monitoring function. This function is called when an account is removed from the server. -
loginFunction
The login function. This function is called when a login is successful. -
logoutFunction
The logout function. This function is called when a logout is successful. -
authFunction
The authorization function. This function is called when a request is authorized and the login function or logout function was not called during the same transaction.
-
-
Constructor Details
-
EjwsAuthenticator
Constructor. Realms are strings denoting a name space for users.- Parameters:
ews- theEmbeddedWebServerrealm- the realm
-
-
Method Details
-
setThisObject
Set this object so that we can always get the actual type.- Parameters:
thisObject- this object
-
gpghome
Get the GPG home directory.- Returns:
- the GPG home directory; null if one has not been set
-
setGPGHome
Set the GPG home directory. If the directory does not exist, it will be created and its POSIX file permissions (if applicable) will be set to read, write, execute for the owner with no group or other permissions. A key named keysigner will be automatically added if it does not already exist.The methods
createUser(String,String,String[],Set),createUser(String,String,Set),storeGPGKey(String,EjwsAuthenticator.GPGKeyIDs), andtrustGPGKey(String,boolean)will throw aNullPointerExceptionif this method is not called with a non-null argument.- Parameters:
gpghome- the home directory that GPG will use- Returns:
- this object
- Throws:
IOException- if an IO error occurs
-
setSBLStore
Set persistent storage for SBL files and/or passwords.- Parameters:
store- theSBLStore- Returns:
- this object
-
setSBLStore
Set persistent storage for SBL files and/or passwords given a file.- Parameters:
file- the file used for storage- Returns:
- this object
- Throws:
IOException- if an an IO exception occurred- See Also:
-
closeSBLStore
public void closeSBLStore()Close persistent storage.This method has no effect if
setSBLStore(java.io.File)orsetSBLStore(java.io.File)has not been called.- See Also:
-
getSBLStore
Get the SBL store. An SBL store is persistent storage for passwords and SBL files, with a user as a key and an indication of whether or not a user is active.- Returns:
- the SBL store; null if one has not been configured
-
getUserTable
public abstract EjwsUserTable<? extends EjwsAuthenticator,? extends EjwsAuthenticator.Entry> getUserTable()Get this authenticator's user table.- Returns:
- this authenticator's user table
-
readSBLData
Read SBL data from an input stream, storing it as a string- Parameters:
is- the input stream- Returns:
- the SBL data; null if there is an error
-
storeSBLData
Store SBL data.- Parameters:
s- the SBL data as aStringstatus-EjwsAuthenticator.AddStatus.OKif the corresponding account will be active;EjwsAuthenticator.AddStatus.PENDINGif the corresponding account will be pending;EjwsAuthenticator.AddStatus.REJECTEDif the account is immediately rejected- Throws:
Exception
-
createAuthCode
Add an authorization code. This method will create an object that can generate authorization codes, which are useful when users are emailed links to allow them to set up accounts.- Parameters:
secret- an initialization string.- Returns:
- this object
-
getAuthCode
Get the current authorization-code generator.- Returns:
- an instance of
AuthCode; null if one was not configured.
-
isActiveDefault
public boolean isActiveDefault()Get the default value for whether or not a user account is active or not. An account is active if the user is allowed to log in.- Returns:
- true if the account is active; false otherwise
-
setDefaultActive
Set the default for whether new users are active or not. The value is used by the createUser methods.- Parameters:
value- true if new users are active by default; false if not active by default- Returns:
- this object
-
getCanAddAccount
public boolean getCanAddAccount()Determine if this authenticator can add a new user account.- Returns:
- true if an account can be added; false otherwise.
-
setCanAddAccount
Set whether or not this authenticator can add a user account.- Parameters:
value- true if an account can be added; false otherwise.- Returns:
- this object
-
setTruststore
Set the name of the truststore file. The value may be sent to clients setting up an account.- Parameters:
truststore- the name of the truststore file- Returns:
- this object
-
setTruststorePW
Set the truststore password. The value may be sent to clients setting up an account.- Parameters:
pw- the password- Returns:
- this object
-
setSelfSigned
Set whether or not certificats may be self signed The value may be sent to clients setting up an account.- Parameters:
selfSigned- true if certificates can be self-signed; false if a certificate chain ends at a root certificate- Returns:
- this object
-
setAllowLoopback
Set if a loopback interface may be used for secure connections The value may be sent to clients setting up an account.- Parameters:
allowLoopback- true if a looback interface may be used; false otherwise- Returns:
- this object
-
getLoginAlias
Get the login alias. This is a convenience method.- Returns:
- the login alias
- See Also:
-
getLoginPath
Get the login path.- Returns:
- the login path; null if one was not configured
-
createUser
public EjwsAuthenticator.UserInfo createUser(String userName, String title, String[] recipients, Set<String> roles) throws IllegalStateException, IOException, NullPointerException Create an instance ofEjwsAuthenticator.UserInfo. For example,
In this example, the order of the calls toEmbeddedWebServer ews = ...; File gpghome = ...; EjwsSecureBasicAuth auth = new EjwsSecureBasicAuth(ews, "test-realm"); auth.setGPGHome(gpghome); String recipients[] = { "user@example.com" }; URI logoutURI = ...; auth.add(auth.createUser("user@example.com", "Example", recipients, roles) .setURI("/docs/login.html") .addUser(true)); ews.add("/", DirWebMap.class, dir, auth, true, true, true) .setWelcome("/index.html") .setLoginAlias("login.html", "", true) .setLogoutAlias("logout.html", logoutURI);auth.addandews.addcan be swapped.Each recipient must be a string that can be used with the gpg -r option.
- Parameters:
userName- the user nametitle- A title for an SBL filerecipients- the GPG recipientsroles- the user's roles- Throws:
NullPointerException- if the GPG home directory had not been setIllegalStateException- if the recipient does not have a known GPG public key or if there was a certificate errorIOException- if an IO error occurs while constructing a cannonical path- See Also:
-
createUser
public EjwsAuthenticator.UserInfo createUser(String email, String title, Set<String> roles) throws IllegalStateException, IOException, NullPointerException Create an instance ofEjwsAuthenticator.UserInfo. For example,
In this example, the order of the calls toEmbeddedWebServer ews = ...; File gpghome = ...; EjwsSecureBasicAuth auth = new EjwsSecureBasicAuth(ews, "test-realm"); URI logoutURI = ...; auth.add(auth.createUser("user@example.com", "Example", roles) .setURI("/docs/login.html") .addUser(true)); ews.add("/", DirWebMap.class, dir, auth, true, true, true) .setWelcome("/index.html") .setLoginAlias("login.html", "", true) .setLogoutAlias("logout.html", logoutURI);auth.addandews.addcan be swapped.Each recipient must be a string that can be used with the gpg -r option.
- Parameters:
email- the user's email addresstitle- A title for an SBL fileroles- the user's roles- Throws:
NullPointerException- if the GPG home directory had not been setIllegalStateException- if the recipient does not have a known GPG public key or if there was a certificate errorIOException- if an IO error occurs while constructing a cannonical path- See Also:
-
createUser
public EjwsAuthenticator.UserInfo createUser(String userName, String password, String publicKeyPEM, Set<String> roles) Create an instance ofEjwsAuthenticator.UserInfobased on a public key provided by a remote user. For example,
In this example, the order of the calls toEmbeddedWebServer ews = ...; String user = ...; String password = ...; String publickeyPEM = ...; EjwsSecureBasicAuth auth = new EjwsSecureBasicAuth(ews, "test-realm"); String recipients[] = { URI logoutURI = ...; auth.add(auth.createUser(ews, user, password, publicKeyPEM, null) ews.add("/", DirWebMap.class, dir, auth, true, true, true) .setWelcome("/index.html") .setLoginAlias("login.html", "", true) .setLogoutAlias("logout.html", logoutURI);auth.addandews.addcan be swapped.- Parameters:
userName- the user namepassword- the user's passwordpublicKeyPEM- the user's publicKey in PEM formatroles- the user's roles; null if there are none
-
createUser
public EjwsAuthenticator.UserInfo createUser(ConfigProperties props, Set<String> roles) throws IllegalStateException, IllegalArgumentException Create an instance ofEjwsAuthenticator.UserInfobased on aConfigPropertiesobject provided by a remote user.- Parameters:
props-roles- a set of roles; null if there are none- Throws:
IllegalStateException- if the recipient does not have a known GPG public key or if there was a certificate errorIllegalArgumentException- if the property file was ill formed
-
createUser
public EjwsAuthenticator.UserInfo createUser(String propsString, Set<String> roles) throws IOException, IllegalArgumentException Create an instance ofEjwsAuthenticator.UserInfobased on a string representing aConfigPropertiesobject provided by a remote user. The first argument is a string that was in effect created by the following steps:- store a
Propertiesobject by using the methodProperties.store(Writer,String)with theWriterargument set to aWriterthat uses the UTF-8 character set with CRLF line separators. The first line in this file will be "#(M.T application/vnd.bzdev.sblauncher)", which is used to determine the File's media type. - Compress the byte stream produced in the first step using GZIP.
- Finally Base-64 encode the compressed byte stream
The easiest way to create this string is to use the program SBL to create an SBL file, select a site (listed by keys), and then select the "Copy Server SBL to Clipboard" menu item under the File menu.
- Parameters:
propsString- a string representing anConfigPropertiesobjectroles- a set of roles; null if there are none- Throws:
IOException- if the media type does not match that of the Base-64 encoded representationIllegalArgumentException- if the property file was ill formed
- store a
-
getUserNameFromSBL
Get the name of a user from an SBL file.- Parameters:
propsString- the string representation of an SBL file- Returns:
- the user name
- Throws:
Exception- if there is an error
-
generateRequestURI
Generate a URI for a login request that will provide an SBL file for a user. The host name in the URI will be preferentially taken from the server's certificate when SSL is used.- Parameters:
username- the user name; null for just the login URL- Returns:
- the URL
-
generateAdminURI
Generate a URI for an admin page. The host name in the URI will be preferentially taken from the server's certificate when SSL is used.- Parameters:
username- the user name; null for just the login URL- Returns:
- the URL
-
requestFromUser
Generate a sequence of bytes containing an SBL file that instructs the SBL program as to how to download data needed to create an account. The format is a UTF-8 encoded string, where the string is produced byConfigPropUtilities.store(Properities,String)(which describes the string format in detail).- Parameters:
username- the user nametype- "pgpkey" when a PGP/GPG public key should be downloaded; "sbl" if an SBL file should be downloadedauth- the authorization string; null if there is none- Returns:
- the SBL file's contents
-
getReverseProxy
Get the reverse proxy. When a reverse proxy is configured, the ".base" field in an SBL file provided by the server will be a URI whose host name and port matches that of the reverse proxy and whose path starts with the reverse proxy's path.- Returns:
- the reverse proxy; null if there isn't one
-
setReverseProxy
Set the reverse proxy. When a reverse proxy is configured, the ".base" field in an SBL file provided by the server will be a URI whose host name and port matches that of the reverse proxy and whose path starts with the reverse proxy's path.- Parameters:
proxy- the reverse proxy; null if there isn't one
-
storeGPGKey
public void storeGPGKey(String key, EjwsAuthenticator.GPGKeyIDs keyids) throws IllegalArgumentException, IllegalStateException, IOException Store an ASCII-armored GPG public key for use by this authenticator. The program SBL has an option under the File menu to copy the key to the system clipboard. Alternatively, if a login alias is configured, a URL referencing the login alias with a query containing- user=EMAIL_ADDRESS
- uploadtype=pgpkey
will return an SBL file that triggers a series of events that will
download the corresponding public key and possibly set up a user
account.
The second argument should be computed by calling
showGPGKey(key)
- Parameters:
key- the public keykeyids- and object containing the key's email address and fingerprint- Throws:
NullPointerException- if the GPG home directory had not been setIllegalArgumentException- if the key is ill-formedIllegalStateException- if the key cannot be storedIOException- if an IO error occurs while constructing a cannonical path- See Also:
-
showGPGKey
public EjwsAuthenticator.GPGKeyIDs showGPGKey(String key) throws IllegalArgumentException, IllegalStateException, IOException Show an ASCII-armored GPG public key for use by this authenticator. The program SBL has an option under the File menu to copy the key to the system clipboard. Alternatively, if a login alias is configured, a URL referencing the login alias with a query containing- user=EMAIL_ADDRESS
- uploadtype=pgpkey will return an SBL file that triggers a series of events that will download the corresponding public key and possibly set up a user account.
- Parameters:
key- the public key- Returns:
- an object containing the key's email address and fingerprint
- Throws:
NullPointerException- if the GPG home directory had not been setIllegalArgumentException- if the key is ill-formedIllegalStateException- if the key cannot be storedIOException- if an IO error occurs while constructing a cannonical path- See Also:
-
trustGPGKey
public void trustGPGKey(String email, boolean trust) throws IllegalArgumentException, IllegalStateException, IOException Configure a GPG public key's trust level for this authenticator. The choice for a key's trust level is binary because the key is not being distributed. When the third argument is false, the key's trust is "unknown" and when true, the key's trust is "ultimate".Normally this method is not needed because of the use of the TOFU (Trust On First Use) GPG trust policy.
- Parameters:
email- the public key's email fieldtrust- true if the key is "ultimately" trusted; false if the key is not trusted- Throws:
NullPointerException- if the GPG home directory had not been setIllegalArgumentException- if the key is ill-formedIllegalStateException- if the key cannot be storedIOException- if an IO error occurs while constructing a cannonical path- See Also:
-
getSBL
Get the SBL file for a user- 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.- Returns:
- true if the SBL file is compressed; false otherwise
- See Also:
-
isActive
Determine if a user is currently active. The authenticator's internal tables are tested, not values in persistent storage.- Returns:
- true if the user exists and is active; false otherwise
-
removeUser
Remove a user.- Parameters:
name- the user's name
-
makeUserActive
Make a user active.- Parameters:
name- the user's name
-
makeUserPending
Make a user pendijng.- Parameters:
name- the user's name
-
makeUserActiveInMap
Make a user active, modifying only the authenticator's map.- Parameters:
name- the user name- Returns:
- true on success; false if there is no such user
-
makeUserPendingInMap
Make a user pending, modifying only the authenticator's map.- 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.- Parameters:
name- the user name- Returns:
- true on success; false if there is no such user
-
removeUser
Remove a user, specifying if the user is one for whom GPG is used to provide the data needed to log in.- Parameters:
name- the user's namegpg- true if GPG is used; false if an SBL directory is used
-
makeUserActive
Make a user active, specifying if the user is one for whom GPG is used to provide the data needed to log in.- Parameters:
name- the user's namegpg- true if GPG is used; false if an SBL directory is used
-
makeUserPending
Make a user pending, specifying if the user is one for whom GPG is used to provide the data needed to log in.- Parameters:
name- the user's namegpg- true if GPG is used; false if an SBL directory is used
-
loadFromDirs
Load user-account data obtained from GPG or an SBL directory- Returns:
- this object
- Throws:
UnsupportedOperationException- See Also:
-
setTracer
Set an Appendable for tracing. This method should be used only for debugging.- Parameters:
tracer- the Appendable for tracing request and responses- Returns:
- this object
-
setOnAccountRequest
Set the function called when a user requests an account. This function will be called when a request to add an account is processed. Its first argument is the name of the user. Its second argument is the status of the request (OK, PENDING, or REJECTED).- Parameters:
function- the function; null to disable- Returns:
- this object
-
setOnAccountActive
Set the function called when an account becomes active. This function will be called when a request to make an account active is processed. Its first argument is the name of the user. Its second argument is the status this operation (true for success; false for failure).- Parameters:
function- the function; null to disable- Returns:
- this object
-
setOnAccountPending
Set the function called when an account becomes pending explicitly. This function will be called when a request to make an account pending is processed. Its first argument is the name of the user. Its second argument is the status this operation (true for success; false for failure).- Parameters:
function- the function; null to disable- Returns:
- this object
-
setOnAccountRemoval
Set the function called when an account is removed. This function will be called when a request to make an account active is processed. Its first argument is the name of the user. Its second argument is the status this operation (true for success; false for failure).- Parameters:
function- the function; null to disable- Returns:
- this object
-
setLoginFunction
Set the login function. This function will be called using the current HttpExchange when a login is (a) successful and (b) the function is not null. It can be used to set headers or perform other operations as required by an application.The function will be called when the request URI matches a designated login URI, with the current
EjwsPrincipalandHttpExchangeas its arguments In any transaction, at most one of the login, logout, and authorized functions will be called.- Parameters:
function- the function; null to disable- Returns:
- this object
- See Also:
-
setAuthorizedFunction
Set the authorized function. This function will be called when a request is authorized. Its arguments are a principal and the HTTP exchange. The later can be used to set cookies or perform other operations. In any transaction, at most one of the login, logout, and authorized functions will be called.- Parameters:
function- the 'authorized' function.- Returns:
- this object
-
setLogoutFunction
Set the logout function. This function will be called using the current HttpExchange when a logout is (a) successful and (b) the function is not null. It can be used to set headers or perform other operations as required by an application.The function will be called when the request URI matches a designated logout URI, with the current
EjwsPrincipalandHttpExchangeas its arguments. TheHttpExchangewill be null if the login session has timed out. In any transaction, at most one of the login, logout, and authorized functions will be called.- Parameters:
function- the function; null to disable- Returns:
- this object
- See Also:
-
getMode
Get a user's authentication mode.- Returns:
- the mode
-
add
Add a user specified by an instance ofEjwsAuthenticator.UserInfo.- Parameters:
info- the user data
-
setUserStatusFunction
Set the user-status function. A user status function takes a user name as its argument and returns- AddStatus.OK if the user's account is to be added and will be active.
- AddStatus.PENDING if the user's account is to be added but will not be active.
- AddStatus.REJECTED if the user may not have an account at this time.
- null if all users will be active or pending,
depending on the value returned by
isActiveDefault().
isActiveDefault().- Parameters:
function- the user-status function; null for the default- Returns:
- this object
- See Also:
-
addToAdminMap
Add an entry to the map associating email addresses with the fingerprint of a corresponding GPG key.Note: normally this is called explicitly as the web server is being configured. The method
FileHandler.setAdminAlias(String), which is called byWebMap.setAdminAlias(String), will add an entry for "admin".- Parameters:
email- the email addressfingerprint- the corresponding GPG key's fingerprint- Returns:
- this object
-
getAdminFingerprint
Get the PGP fingerprint for an email address associated with the admin account- Parameters:
email- the email address- Returns:
- the fingerprint; null if there isn't one associated with the admin account
-
getAdminUsers
Get the users' email addresses for those users associated with the admin account- Returns:
- the email addresses
-
getUserStatus
Get the status for a request to set up an account. When a function has been provided by callingsetUserStatusFunction(Function), the value returned by the provided function will be used unless the value returned is null, in which caseisActiveDefault()determines the result (either active or pending).- Parameters:
username- the name (typically the email address) of a user- Returns:
EjwsAuthenticator.AddStatus.REJECTEDif the account will definitely not be allowed;EjwsAuthenticator.AddStatus.PENDINGif the account request requires further processing;EjwsAuthenticator.AddStatus.OKif the account request is immediately accepted- See Also:
-
addToDeleteSet
Add a user to the set of users that will be deleted.- Parameters:
uname- the user name (e.g., the user's email address)
-
removeFromDeleteSet
Remove a user to the set of users that will be deleted.- Parameters:
uname- the user name (e.g., the user's email address)
-
inDeleteSet
Determine if a user is in the set of users that will be deleted.- Parameters:
uname- the user name (e.g., the user's email address)
-
getTrustedKeyIDs
Get the GPG key IDs for ultimately trusted users. The values returned are in the format used for keysigning (the last 16 characters in the full fingerprint).- Returns:
- a set of the key IDs
- Throws:
Exception
-
isTrustedKey
Determine if a user is ultimately trusted.setGPGHome(File)must have been called before this method is used.- Parameters:
name- the user name- Returns:
- true if the user is ultimately trusted; false otherwise
- See Also:
-
hasGPGKey
Determine if there is a GPG Key for a specified user.setGPGHome(File)must have been called before this method is used.- Parameters:
name- the user name- Returns:
- true if there is an associated GPG key; false otherwise
-
setupKeySigner
protected boolean setupKeySigner()Set up a key signer. If not already available, a key named keysigner will be created.setGPGHome(File)must have been called before this method is used. -
getFingerprint
Get the GPG fingerprint for an email address.setGPGHome(File)must have been called before this method is used.- Parameters:
email- the email address- Returns:
- the fingerpint; null if there is none
-
isEmailAddress
Determine if a string is a syntactically valid email address. The email address must be the local part of an email address, followed by an '@', in turn followed by a domain. For example,user@example.com. This is often delimited by "&tl;" and ">". Those delimiters must not be included.- Parameters:
string- the string to check- Returns:
- true if the argument is a syntactically valid email address; false otherwise
-
signKey
Sign a key given an email address. The methodssetGPGHome(File)and/orsetSBLStore(File)should be called before this method is used.- Parameters:
email- the email addressgpg- true if a GPG key will be signed; false if a directory containing SBL data will be manipulated- Returns:
- true if successful; false otherwise
- See Also:
-
signKey
Sign a key given an email address and target. The methodssetGPGHome(File)and/orsetSBLStore(File)should be called before this method is used. This is a convenience method.- Parameters:
email- the email addresstarget- the email address if GPG is used; a file name for a file in the SBL directory otherwise.- See Also:
-
validGPGUser
Determine if a user has a key that was signed by a key recognized by this authenticator.setGPGHome(File)must have been called before this method is used.- Parameters:
email- the user's email address- Returns:
- true if the user is valid (e.g., the user's GPG key has been signed); false otherwise
- See Also:
-
getUsers
Get the names of all users known to this authenticator. The value returned is an unmodifiable set.- Returns:
- the users
-
getUsers
Get selected users known to this authenticator.- Parameters:
active- true if the users are active; false if they are not active
-
getUsersExcept
Get all users except those in an exception set. Users that are in the admin map are ignored.- Parameters:
exceptions- a set of users to ignore- Returns:
- the names of users not in the exception set
-
getPendingGPGUsers
Get GPG users that are in the pending state.- Returns:
- the GPG users that are in a pending state
-
getActiveGPGUsers
Get GPG users in the active state.- Returns:
- the names of GPG users in the active state
-
getGPGUsers
Get GPG user names.setGPGHome(File)must have been called before this method is used.- Parameters:
signed- true if the corresponding keys were signed; false otherwise- Returns:
- the user names (typically email addresses)
-
getAuthMap
Get the authentication map association user names with authentication data..- Returns:
- the map
-
getSBLUsers
Get the users whose data is kept in the SBL directory The methodsetSBLStore(File)orsetSBLStore(SBLStore)should be called before this method is used.- Parameters:
active- true to list active users; false to list inactive ones- Returns:
- the user names
-
deleteWithFingerprint
Delete a GPG key given the key's fingerprint.setGPGHome(File)must have been called before this method is used.- Parameters:
fpr- the fingerprint- See Also:
-
createServerCookie
Create a server cookie- Parameters:
t- the instance ofHttpExchangeused for the current connection- Returns:
- the new cookie
-
createAuthCookie
Create an authentication cookie given a user name.- Parameters:
t- theHttpExchangefor an HTTP trasactionusername- the user name
-
findServerCookie
Find a server cookie.- Parameters:
t- the instance ofHttpExchangeused for the current connection- Returns:
- the cookie
-
findAuthServerCookie
Find an authorization server cookie. This is used for password-authentication account creation, where the browser handles the request directly.- Parameters:
t- the instance ofHttpExchangeused for the current connection- Returns:
- the cookie
-
setCookie
Set a server cookie.- Parameters:
t- the instance ofHttpExchangeused for the current connectioncookie- the cookie
-
removePWInfo
Remove an entry from the password map. This is called when logging out.- Parameters:
username- the user name
-
processAdminRequests
public void processAdminRequests(Map<String, String> deleteMap, Map<String, String> activateMap, Map<String, String> pendingMap) Process a request to remove or active user accounts EitherremoveUser(String,String)ormakeUserActive(String,String)will be called to remove or active a user respectively.This method is called by
FileHandlerto implement a simple account manager.- Parameters:
deleteMap- a map whose keys are user names or email addresses and whose values are either the same or a file name, where the map is used to determine which users shoudl be deletedactivateMap- a map whose keys are user names or email addresses and whose values are either the same or a file name, where the map is used to determine which users should be activatedpendingMap- a map whose keys are user names or email addresses and whose values are either the same or a file name, where the map is used to determine which active users should be made pending
-