Package com.ibm.cloud.sdk.core.security
Class TokenRequestBasedAuthenticator<T extends AbstractToken,R extends TokenServerResponse>
- java.lang.Object
-
- com.ibm.cloud.sdk.core.security.AuthenticatorBase
-
- com.ibm.cloud.sdk.core.security.TokenRequestBasedAuthenticator<T,R>
-
- All Implemented Interfaces:
Authenticator
- Direct Known Subclasses:
CloudPakForDataAuthenticator,CloudPakForDataServiceAuthenticator,CloudPakForDataServiceInstanceAuthenticator,IamRequestBasedAuthenticator,VpcInstanceAuthenticator
public abstract class TokenRequestBasedAuthenticator<T extends AbstractToken,R extends TokenServerResponse> extends AuthenticatorBase implements Authenticator
This class serves as a common base class for Authenticator implementations that interact with a token service via a REST interface. This base class allows for the configuration of the following properties:- disableSSLVerification - a flag that indicates whether or not client-side SSL verification should be disabled.
- headers - a Map of keys/values that will be set as HTTP headers on requests sent to the token service.
- proxy - a java.net.Proxy instance that will be set on the OkHttpClient instance used to interact with the token service.
- proxyAuthenticator - an okhttp3.Authenticator instance to be set on the OkHttpClient instance used to interact with the token service.
- client - a fully-configured OkHttpClient instance to be used to interact with the token service.
-
-
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 TokenRequestBasedAuthenticator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidauthenticate(okhttp3.Request.Builder builder)Authenticate the specified request by adding an Authorization header containing a "Bearer" access token.abstract java.lang.StringauthenticationType()Returns the authentication type associated with this Authenticator.okhttp3.OkHttpClientgetClient()Returns the OkHttpClient instance to be used when interacting with the token service.booleangetDisableSSLVerification()java.util.Map<java.lang.String,java.lang.String>getHeaders()Returns the set of user-supplied headers configured for this Authenticator.java.net.ProxygetProxy()okhttp3.AuthenticatorgetProxyAuthenticator()java.lang.StringgetToken()This function returns the access token fetched from the token service.abstract TrequestToken()Builds and invokes the REST request to fetch a new token from the token service.voidsetClient(okhttp3.OkHttpClient client)Sets the OkHttpClient instance to be used when interacting with the token service.voidsetDisableSSLVerification(boolean disableSSLVerification)Sets the disableSSLVerification flag.voidsetHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Sets a Map of key/value pairs which will be sent as HTTP headers in any interactions with the token service.voidsetProxy(java.net.Proxy proxy)Sets a Proxy object on this Authenticator.voidsetProxyAuthenticator(okhttp3.Authenticator proxyAuthenticator)Sets a proxy authenticator on this Authenticator instance.abstract voidvalidate()Validates the configuration properties associated with the Authenticator.-
Methods inherited from class com.ibm.cloud.sdk.core.security.AuthenticatorBase
constructBasicAuthHeader, constructBearerTokenAuthHeader
-
-
-
-
Method Detail
-
setClient
public void setClient(okhttp3.OkHttpClient client)
Sets the OkHttpClient instance to be used when interacting with the token service.- Parameters:
client- the OkHttpClient instance to use
-
getClient
public okhttp3.OkHttpClient getClient()
Returns the OkHttpClient instance to be used when interacting with the token service.- Returns:
- the client instance or null if a client insance has not yet been set
-
validate
public abstract void validate()
Validates the configuration properties associated with the Authenticator. Each concrete subclass must implement this method.- Specified by:
validatein interfaceAuthenticator
-
authenticationType
public abstract java.lang.String authenticationType()
Returns the authentication type associated with this Authenticator. Each concrete subclass must implement this method.- Specified by:
authenticationTypein interfaceAuthenticator- Returns:
- the authentication type
-
getDisableSSLVerification
public boolean getDisableSSLVerification()
- Returns:
- the disableSSLVerification flag
-
setDisableSSLVerification
public void setDisableSSLVerification(boolean disableSSLVerification)
Sets the disableSSLVerification flag.- Parameters:
disableSSLVerification- a flag indicating whether SSL host verification should be disabled
-
getHeaders
public java.util.Map<java.lang.String,java.lang.String> getHeaders()
Returns the set of user-supplied headers configured for this Authenticator.- Returns:
- a Map containing the configured headers
-
setHeaders
public void setHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Sets a Map of key/value pairs which will be sent as HTTP headers in any interactions with the token service.- Parameters:
headers- the user-supplied headers to be included in token service interactions
-
getProxy
public java.net.Proxy getProxy()
- Returns:
- the Proxy configured for this Authenticator
-
setProxy
public void setProxy(java.net.Proxy proxy)
Sets a Proxy object on this Authenticator.- Parameters:
proxy- the proxy object to be associated with the Client used to interact with the token service.
-
getProxyAuthenticator
public okhttp3.Authenticator getProxyAuthenticator()
- Returns:
- the proxy authenticator configured for this Authenticator
-
setProxyAuthenticator
public void setProxyAuthenticator(okhttp3.Authenticator proxyAuthenticator)
Sets a proxy authenticator on this Authenticator instance.- Parameters:
proxyAuthenticator- the proxy authenticator
-
authenticate
public void authenticate(okhttp3.Request.Builder builder)
Authenticate the specified request by adding an Authorization header containing a "Bearer" access token.- Specified by:
authenticatein interfaceAuthenticator- Parameters:
builder- theRequest.Builderinstance to authenticate
-
requestToken
public abstract T requestToken()
Builds and invokes the REST request to fetch a new token from the token service. Each concrete subclass must implement this method.- Returns:
- the token object
-
getToken
public java.lang.String getToken()
This function returns the access token fetched from the token service. If no token currently exists or the current token has expired, a new token is fetched from the token service.- Returns:
- the access token
-
-