Package com.ibm.cloud.sdk.core.security
Class BearerTokenAuthenticator
- java.lang.Object
-
- com.ibm.cloud.sdk.core.security.AuthenticatorBase
-
- com.ibm.cloud.sdk.core.security.BearerTokenAuthenticator
-
- All Implemented Interfaces:
Authenticator
public class BearerTokenAuthenticator extends AuthenticatorBase implements Authenticator
This class provides an Authenticator implementation that supports a user-supplied Bear Token value. The main purpose of this authenticator is to construct the Authorization header with the user-supplied token, then add the header to each outgoing REST API request.
-
-
Field Summary
-
Fields inherited from class com.ibm.cloud.sdk.core.security.AuthenticatorBase
ERRORMSG_ACCOUNTID_PROP_ERROR, 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_IAM_ASSUME, AUTHTYPE_MCSP, 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_ACCOUNT_ID, 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 BearerTokenAuthenticator(java.lang.String bearerToken)
Construct a BearerTokenAuthenticator instance with the specified access token.BearerTokenAuthenticator(java.util.Map<java.lang.String,java.lang.String> config)
Deprecated.As of 9.7.0, use BearerTokenAuthenticator.fromConfiguration() instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
authenticate(okhttp3.Request.Builder builder)
This method is called to authenticate an outgoing REST API request.java.lang.String
authenticationType()
Returns the authentication type associated with the Authenticator instance.static BearerTokenAuthenticator
fromConfiguration(java.util.Map<java.lang.String,java.lang.String> config)
Construct a BearerTokenAuthenticator instance using properties retrieved from the specified Map.java.lang.String
getBearerToken()
void
setBearerToken(java.lang.String bearerToken)
Sets the bearer token value to be used by this Authenticator.void
validate()
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
-
BearerTokenAuthenticator
public BearerTokenAuthenticator(java.lang.String bearerToken)
Construct a BearerTokenAuthenticator instance with the specified access token. The token value will be used to construct an Authorization header that will be included in outgoing REST API requests.- Parameters:
bearerToken
- the access token value
-
BearerTokenAuthenticator
public BearerTokenAuthenticator(java.util.Map<java.lang.String,java.lang.String> config)
Deprecated.As of 9.7.0, use BearerTokenAuthenticator.fromConfiguration() instead.Construct a BearerTokenAuthenticator using properties retrieved from the specified Map.- Parameters:
config
- a map containing the access token value
-
-
Method Detail
-
fromConfiguration
public static BearerTokenAuthenticator fromConfiguration(java.util.Map<java.lang.String,java.lang.String> config)
Construct a BearerTokenAuthenticator instance using properties retrieved from the specified Map.- Parameters:
config
- a map containing the configuration properties- Returns:
- the BearerTokenAuthenticator instance
-
validate
public void validate()
Description copied from interface:Authenticator
Validates the current set of configuration information in the Authenticator.- Specified by:
validate
in interfaceAuthenticator
-
authenticationType
public java.lang.String authenticationType()
Description copied from interface:Authenticator
Returns the authentication type associated with the Authenticator instance.- Specified by:
authenticationType
in interfaceAuthenticator
- Returns:
- a string representing the authentication type (e.g. "iam", "basic", "icp4d", etc.)
-
getBearerToken
public java.lang.String getBearerToken()
- Returns:
- the access token configured for this Authenticator
-
setBearerToken
public void setBearerToken(java.lang.String bearerToken)
Sets the bearer token value to be used by this Authenticator.- Parameters:
bearerToken
- the new bearer token value
-
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:
authenticate
in interfaceAuthenticator
- Parameters:
builder
- theRequest.Builder
instance to authenticate
-
-