java.lang.Object
com.sun.net.httpserver.Authenticator
com.sun.net.httpserver.BasicAuthenticator
public abstract class BasicAuthenticator extends Authenticator
BasicAuthenticator provides an implementation of HTTP Basic
authentication. It is an abstract class and must be extended
to provide an implementation of
checkCredentials(String,String)
which is called to verify each incoming request.-
Nested Class Summary
Nested classes/interfaces declared in class com.sun.net.httpserver.Authenticator
Authenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success
-
Field Summary
-
Constructor Summary
ConstructorDescriptionBasicAuthenticator(String realm)
Creates aBasicAuthenticator
for the given HTTP realm.BasicAuthenticator(String realm, Charset charset)
Creates aBasicAuthenticator
for the given HTTP realm and using the givenCharset
to decode the Basic authentication credentials (username and password). -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
checkCredentials(String username, String password)
Called for each incoming request to verify the given name and password in the context of this authenticator's realm.getRealm()
Returns the realm thisBasicAuthenticator
was created with.Methods declared in class com.sun.net.httpserver.Authenticator
authenticate
-
Field Details
-
realm
The HTTP Basic authentication realm.
-
-
Constructor Details
-
BasicAuthenticator
Creates aBasicAuthenticator
for the given HTTP realm. The Basic authentication credentials (username and password) are decoded using the platform'sdefault character set
.- Parameters:
realm
- the HTTP Basic authentication realm- Throws:
NullPointerException
- if realm isnull
IllegalArgumentException
- if realm is an empty string
-
BasicAuthenticator
Creates aBasicAuthenticator
for the given HTTP realm and using the givenCharset
to decode the Basic authentication credentials (username and password).- API Note:
UTF-8
is the recommended charset because its usage is communicated to the client, and therefore more likely to be used also by the client.- Parameters:
realm
- the HTTP Basic authentication realmcharset
- theCharset
to decode incoming credentials from the client- Throws:
NullPointerException
- if realm or charset arenull
IllegalArgumentException
- if realm is an empty string
-
-
Method Details
-
getRealm
Returns the realm thisBasicAuthenticator
was created with.- Returns:
- the authenticator's realm string
-
checkCredentials
Called for each incoming request to verify the given name and password in the context of this authenticator's realm. Any caching of credentials must be done by the implementation of this method.- Parameters:
username
- the username from the requestpassword
- the password from the request- Returns:
true
if the credentials are valid,false
otherwise
-