Package org.attribyte.api.http.impl
Class BasicAuthScheme
java.lang.Object
org.attribyte.api.http.AuthScheme
org.attribyte.api.http.impl.BasicAuthScheme
The Standard (insecure) "Basic" scheme.
-
Field Summary
FieldsFields inherited from class org.attribyte.api.http.AuthScheme
AUTHENTICATE_RESPONSE_HEADER, authenticateResponseHeader, DEFAULT_UNAUTHORIZED_MESSAGE, realm, scheme -
Constructor Summary
ConstructorsConstructorDescriptionCreate a scheme with no realm.BasicAuthScheme(String realm) Create a scheme with a realm. -
Method Summary
Modifier and TypeMethodDescriptionAdds authentication credentials to a request.authenticate(Request request, String userId, String secret) Authenticates the request.static final StringbuildAuthHeaderValue(String username, String password) Builds an auth header.Gets the user id from the request, if possible.booleanhasCredentials(Request request) Determines if the request has any (invalid or valid) credentials for this scheme.Methods inherited from class org.attribyte.api.http.AuthScheme
equals, getAuthenticateResponseHeader, getRealm, getScheme, getUnauthorizedResponse, hashCode
-
Field Details
-
AUTH_HEADER
- See Also:
-
-
Constructor Details
-
BasicAuthScheme
public BasicAuthScheme()Create a scheme with no realm. -
BasicAuthScheme
Create a scheme with a realm.- Parameters:
realm- The realm.
-
-
Method Details
-
addAuth
Description copied from class:AuthSchemeAdds authentication credentials to a request.- Specified by:
addAuthin classAuthScheme- Parameters:
request- The request to which credentials are added.id- 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.
-
hasCredentials
Description copied from class:AuthSchemeDetermines if the request has any (invalid or valid) credentials for this scheme.- Specified by:
hasCredentialsin classAuthScheme- Parameters:
request- The request.- Returns:
- Does the request appear to have appropriate credentials?
-
getUserId
Description copied from class:AuthSchemeGets the user id from the request, if possible.- Specified by:
getUserIdin classAuthScheme- Parameters:
request- The request.- Returns:
- The user id, or
nullif none. - Throws:
GeneralSecurityException- on security-related error getting user id.
-
authenticate
public Response authenticate(Request request, String userId, String secret) throws GeneralSecurityException Description copied from class:AuthSchemeAuthenticates the request.- Specified by:
authenticatein classAuthScheme- 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.
-
buildAuthHeaderValue
Builds an auth header.- Parameters:
username- The username.password- The password.- Returns:
- The auth header value.
-