Package org.attribyte.api.http
Class AuthScheme
java.lang.Object
org.attribyte.api.http.AuthScheme
- Direct Known Subclasses:
BasicAuthScheme
Defines a HTTP authentication scheme.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAuthScheme(String scheme, String realm) Creates an authentication scheme. -
Method Summary
Modifier and TypeMethodDescriptionabstract RequestAdds authentication credentials to a request.abstract Responseauthenticate(Request request, String userId, String secret) Authenticates the request.booleanGets the value for theWWW-Authenticateheader.getRealm()Gets the realm.Gets the scheme.getUnauthorizedResponse(String message) Creates a challenge response.abstract StringGets the user id from the request, if possible.abstract booleanhasCredentials(Request request) Determines if the request has any (invalid or valid) credentials for this scheme.inthashCode()
-
Field Details
-
DEFAULT_UNAUTHORIZED_MESSAGE
The default message sent when unauthorized ('Authorization Required').- See Also:
-
AUTHENTICATE_RESPONSE_HEADER
The authenticate response header name ('WWW-Authenticate').- See Also:
-
scheme
-
realm
-
authenticateResponseHeader
-
-
Constructor Details
-
AuthScheme
Creates an authentication scheme.Must not contain the quote character.
- Parameters:
scheme- The scheme name.realm- The realm.- Throws:
UnsupportedOperationException- if the realm contains the quote character.
-
-
Method Details
-
hasCredentials
Determines if the request has any (invalid or valid) credentials for this scheme.- Parameters:
request- The request.- Returns:
- Does the request appear to have appropriate credentials?
-
addAuth
public abstract Request addAuth(Request request, String userId, String secret) throws GeneralSecurityException Adds authentication credentials to a request.- Parameters:
request- The request to which credentials are added.userId- An id that uniquely identifies the user (e.g. 'username').secret- The authentication secret for the username.- Returns:
- The request with authentication credentials added.
- Throws:
GeneralSecurityException- on security-related error adding auth.
-
getUserId
Gets the user id from the request, if possible.- Parameters:
request- The request.- Returns:
- The user id, or
nullif none. - Throws:
GeneralSecurityException- on security-related error getting user id.
-
authenticate
public abstract Response authenticate(Request request, String userId, String secret) throws GeneralSecurityException Authenticates the request.- Parameters:
request- The request.userId- The user id for the secret.secret- The secret data.- Returns:
- The HTTP "Unauthorized" response if request is not authorized, otherwise
null. - Throws:
GeneralSecurityException- on security-related error during authentication.
-
getUnauthorizedResponse
Creates a challenge response.By default, returns the standard HTTP challenge response.
- Parameters:
message- A message returned with the response. Ifnull, a standard message is returned.- Returns:
- The response.
-
getScheme
Gets the scheme.- Returns:
- The scheme.
-
getRealm
Gets the realm.- Returns:
- The realm.
-
getAuthenticateResponseHeader
Gets the value for theWWW-Authenticateheader.- Returns:
- The header value.
-
hashCode
public int hashCode() -
equals
-