- 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 ofcheckCredentials(String,String)
which is called to verify each incoming request.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.sun.net.httpserver.Authenticator
Authenticator.Failure, Authenticator.Result, Authenticator.Retry, Authenticator.Success
-
-
Constructor Summary
Constructors Constructor Description BasicAuthenticator(String realm)
Creates a BasicAuthenticator for the given HTTP realm
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Authenticator.Result
authenticate(HttpExchange t)
called to authenticate each incoming request.abstract 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.String
getRealm()
returns the realm this BasicAuthenticator was created with
-
-
-
Field Detail
-
realm
protected String realm
-
-
Constructor Detail
-
BasicAuthenticator
public BasicAuthenticator(String realm)
Creates a BasicAuthenticator for the given HTTP realm- Parameters:
realm
- The HTTP Basic authentication realm- Throws:
NullPointerException
- if the realm is an empty string
-
-
Method Detail
-
getRealm
public String getRealm()
returns the realm this BasicAuthenticator was created with- Returns:
- the authenticator's realm string.
-
authenticate
public Authenticator.Result authenticate(HttpExchange t)
Description copied from class:Authenticator
called to authenticate each incoming request. The implementation must return a Failure, Success or Retry object as appropriate :-Failure means the authentication has completed, but has failed due to invalid credentials.
Sucess means that the authentication has succeeded, and a Principal object representing the user can be retrieved by calling Sucess.getPrincipal() .
Retry means that another HTTP exchange is required. Any response headers needing to be sent back to the client are set in the given HttpExchange. The response code to be returned must be provided in the Retry object. Retry may occur multiple times.
- Specified by:
authenticate
in classAuthenticator
-
checkCredentials
public abstract 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. 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.
-
-