java.lang.Object
com.sun.net.httpserver.Authenticator
com.sun.net.httpserver.BasicAuthenticator
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 SummaryNested classes/interfaces declared in class com.sun.net.httpserver.AuthenticatorAuthenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionBasicAuthenticator(String realm) Creates aBasicAuthenticatorfor the given HTTP realm.BasicAuthenticator(String realm, Charset charset) Creates aBasicAuthenticatorfor the given HTTP realm and using the givenCharsetto decode the Basic authentication credentials (username and password).
- 
Method SummaryModifier and TypeMethodDescriptionCalled to authenticate each incoming request.abstract booleancheckCredentials(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 thisBasicAuthenticatorwas created with.
- 
Field Details- 
realmThe HTTP Basic authentication realm.
 
- 
- 
Constructor Details- 
BasicAuthenticatorCreates aBasicAuthenticatorfor 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 is- null
- IllegalArgumentException- if realm is an empty string
 
- 
BasicAuthenticatorCreates aBasicAuthenticatorfor the given HTTP realm and using the givenCharsetto decode the Basic authentication credentials (username and password).- API Note:
- UTF-8is 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 realm
- charset- the- Charsetto decode incoming credentials from the client
- Throws:
- NullPointerException- if realm or charset are- null
- IllegalArgumentException- if realm is an empty string
 
 
- 
- 
Method Details- 
getRealmReturns the realm thisBasicAuthenticatorwas created with.- Returns:
- the authenticator's realm string
 
- 
authenticateDescription copied from class:AuthenticatorCalled to authenticate each incoming request. The implementation must return aAuthenticator.Failure,Authenticator.SuccessorAuthenticator.Retryobject as appropriate:-  Failuremeans the authentication has completed, but has failed due to invalid credentials.
-  Successmeans that the authentication has succeeded, and aPrincipalobject representing the user can be retrieved by callingAuthenticator.Success.getPrincipal().
-  Retrymeans that another HTTP exchange is required. Any response headers needing to be sent back to the client are set in the givenHttpExchange. The response code to be returned must be provided in theRetryobject.Retrymay occur multiple times.
 - Specified by:
- authenticatein class- Authenticator
- Parameters:
- t- the- HttpExchangeupon which authenticate is called
- Returns:
- the result
 
-  
- 
checkCredentialsCalled 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 request
- password- the password from the request
- Returns:
- trueif the credentials are valid,- falseotherwise
 
 
-