Package com.ibm.cloud.sdk.core.security
Class BasicAuthenticator
- java.lang.Object
-
- com.ibm.cloud.sdk.core.security.AuthenticatorBase
-
- com.ibm.cloud.sdk.core.security.BasicAuthenticator
-
- All Implemented Interfaces:
Authenticator
public class BasicAuthenticator extends AuthenticatorBase implements Authenticator
This class implements support for Basic Authentication. The main purpose of this authenticator is to construct the Authorization header, and then add it to each outgoing REST API request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBasicAuthenticator.BuilderThis Builder class is used to construct BasicAuthenticator instances.
-
Field Summary
-
Fields inherited from class com.ibm.cloud.sdk.core.security.AuthenticatorBase
ERRORMSG_ATLEAST_ONE_PROP_ERROR, ERRORMSG_ATMOST_ONE_PROP_ERROR, ERRORMSG_EXCLUSIVE_PROP_ERROR, ERRORMSG_PROP_INVALID, ERRORMSG_PROP_INVALID_INTEGER_VALUE, ERRORMSG_PROP_MISSING, ERRORMSG_REQ_FAILED
-
Fields inherited from interface com.ibm.cloud.sdk.core.security.Authenticator
AUTHTYPE_BASIC, AUTHTYPE_BEARER_TOKEN, AUTHTYPE_CONTAINER, AUTHTYPE_CP4D, AUTHTYPE_CP4D_SERVICE, AUTHTYPE_CP4D_SERVICE_INSTANCE, AUTHTYPE_IAM, AUTHTYPE_NOAUTH, AUTHTYPE_VPC, PROPNAME_APIKEY, PROPNAME_AUTH_TYPE, PROPNAME_BEARER_TOKEN, PROPNAME_CLIENT_ID, PROPNAME_CLIENT_SECRET, PROPNAME_CR_TOKEN_FILENAME, PROPNAME_DISABLE_SSL, PROPNAME_DISPLAY_NAME, PROPNAME_EXPIRATION_TIME, PROPNAME_IAM_PROFILE_CRN, PROPNAME_IAM_PROFILE_ID, PROPNAME_IAM_PROFILE_NAME, PROPNAME_PASSWORD, PROPNAME_PERMISSIONS, PROPNAME_SCOPE, PROPNAME_SERVICE_BROKER_SECRET, PROPNAME_SERVICE_INSTANCE_ID, PROPNAME_UID, PROPNAME_URL, PROPNAME_USERNAME
-
-
Constructor Summary
Constructors Constructor Description BasicAuthenticator(java.lang.String username, java.lang.String password)Deprecated.As of 9.7.0, use the Builder class instead.BasicAuthenticator(java.util.Map<java.lang.String,java.lang.String> config)Deprecated.As of 9.7.0, use BasicAuthenticator.fromConfiguration() instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidauthenticate(okhttp3.Request.Builder builder)This method is called to authenticate an outgoing REST API request.java.lang.StringauthenticationType()Returns the authentication type associated with the Authenticator instance.static BasicAuthenticatorfromConfiguration(java.util.Map<java.lang.String,java.lang.String> config)Construct a BasicAuthenticator instance using properties retrieved from the specified Map.java.lang.StringgetPassword()java.lang.StringgetUsername()BasicAuthenticator.BuildernewBuilder()Returns a new Builder instance pre-loaded with the configuration from "this".voidvalidate()Validates the current set of configuration information in the Authenticator.-
Methods inherited from class com.ibm.cloud.sdk.core.security.AuthenticatorBase
constructBasicAuthHeader, constructBearerTokenAuthHeader
-
-
-
-
Constructor Detail
-
BasicAuthenticator
@Deprecated public BasicAuthenticator(java.lang.String username, java.lang.String password)Deprecated.As of 9.7.0, use the Builder class instead.Construct a BasicAuthenticator instance with the specified username and password. These values are used to construct an Authorization header value that will be included in outgoing REST API requests.- Parameters:
username- the basic auth usernamepassword- the basic auth password
-
BasicAuthenticator
@Deprecated public BasicAuthenticator(java.util.Map<java.lang.String,java.lang.String> config)
Deprecated.As of 9.7.0, use BasicAuthenticator.fromConfiguration() instead.Construct a BasicAuthenticator using properties retrieved from the specified Map.- Parameters:
config- a map containing the username and password values
-
-
Method Detail
-
newBuilder
public BasicAuthenticator.Builder newBuilder()
Returns a new Builder instance pre-loaded with the configuration from "this".- Returns:
- the builder
-
fromConfiguration
public static BasicAuthenticator fromConfiguration(java.util.Map<java.lang.String,java.lang.String> config)
Construct a BasicAuthenticator instance using properties retrieved from the specified Map.- Parameters:
config- a map containing the configuration properties- Returns:
- the BasicAuthenticator instance
-
validate
public void validate()
Description copied from interface:AuthenticatorValidates the current set of configuration information in the Authenticator.- Specified by:
validatein interfaceAuthenticator
-
authenticationType
public java.lang.String authenticationType()
Description copied from interface:AuthenticatorReturns the authentication type associated with the Authenticator instance.- Specified by:
authenticationTypein interfaceAuthenticator- Returns:
- a string representing the authentication type (e.g. "iam", "basic", "icp4d", etc.)
-
getUsername
public java.lang.String getUsername()
- Returns:
- the username configured on this Authenticator
-
getPassword
public java.lang.String getPassword()
- Returns:
- the password configured on this Authenticator
-
authenticate
public void authenticate(okhttp3.Request.Builder builder)
This method is called to authenticate an outgoing REST API request. Here, we'll just set the Authorization header to provide the necessary authentication info.- Specified by:
authenticatein interfaceAuthenticator- Parameters:
builder- theRequest.Builderinstance to authenticate
-
-