java.lang.Object
com.sun.net.httpserver.Authenticator
com.sun.net.httpserver.BasicAuthenticator
org.bzdev.ejws.EjwsBasicAuthenticator
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 com.sun.net.httpserver.Authenticator
Authenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success
-
Field Summary
Fields inherited from class com.sun.net.httpserver.BasicAuthenticator
realm
-
Constructor Summary
ConstructorsConstructorDescriptionEjwsBasicAuthenticator
(String realm) Constructor.EjwsBasicAuthenticator
(String realm, Map<String, EjwsBasicAuthenticator.Entry> map) Constructor providing a map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a user name and password for this authenticator's HTTP realm.void
Add a user name, the user's password and the user's roles for this authenticator's HTTP realm.boolean
checkCredentials
(String username, String password) Check credentials.void
setAuthorizedFunction
(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the authorized function.void
setLoginFunction
(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the login function.void
setLogoutFunction
(BiConsumer<EjwsPrincipal, HttpExchange> function) Set the logout function.void
setTracer
(Appendable tracer) Set an Appendable for tracing.Methods inherited from class com.sun.net.httpserver.BasicAuthenticator
getRealm
-
Constructor Details
-
EjwsBasicAuthenticator
Constructor.- Parameters:
realm
- the HTTP realm
-
EjwsBasicAuthenticator
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
-
setTracer
Set an Appendable for tracing. This method should be used only for debugging.- Parameters:
tracer
- the Appendable for tracing requests and responses
-
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
EjwsPrincipal
andHttpExchange
as 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- 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.
-
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
EjwsPrincipal
andHttpExchange
as its arguments. TheHttpExchange
will 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- See Also:
-
add
Add a user name and password for this authenticator's HTTP realm.- 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)
-
add
public void add(String username, String password, Set<String> roles) throws UnsupportedOperationException Add a user name, the user's password and the user's roles for this authenticator's HTTP realm.- 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)
-
authenticate
- Overrides:
authenticate
in classBasicAuthenticator
-
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:
checkCredentials
in classBasicAuthenticator
- Parameters:
username
- the user namepassword
- the password
-