Class WorkloadIdentityFederationAuthenticationDetailProvider
- java.lang.Object
-
- com.oracle.bmc.auth.WorkloadIdentityFederationAuthenticationDetailProvider
-
- All Implemented Interfaces:
AbstractAuthenticationDetailsProvider,BasicAuthenticationDetailsProvider,ProvidesConfigurableRefresh,RefreshableOnNotAuthenticatedProvider<String>,RegionProvider,AutoCloseable
public class WorkloadIdentityFederationAuthenticationDetailProvider extends Object implements BasicAuthenticationDetailsProvider, RegionProvider, RefreshableOnNotAuthenticatedProvider<String>, ProvidesConfigurableRefresh, AutoCloseable
ABasicAuthenticationDetailsProviderimplementation that uses workload identity federation to authenticate with Oracle Cloud Infrastructure.This provider exchanges a subject token (e.g., a Kubernetes service account token) for an OCI session token, which is then used to sign API requests.
This provider offers two key features for robust authentication in long-running applications:
- Asynchronous Initialization with buildAsync():
Thebuilder()provides a buildAsync() method that pre-fetches the first authentication token upon initialization. This "fail-fast" approach ensures that authentication issues are discovered at startup rather than during the first API call, and it eliminates the initial authentication delay. - Automatic Proactive Token Refresh with retryConfiguration():
For applications that make continuous API calls, this provider offers automatic proactive token refresh when retry configuration is provided viaWorkloadIdentityFederationAuthenticationDetailProvider.WorkloadIdentityFederationAuthenticationDetailProviderBuilder.retryConfiguration(RetryConfiguration). When retry configuration is set, the provider uses a background thread to automatically refresh the session token before it expires, preventing the calling thread from being blocked by token refresh operations and ensuring consistent API call performance. When no retry configuration is provided, proactive refresh is disabled to conserve resources.
When proactive refresh is enabled (via retry configuration), it is crucial to call
close()(orshutdown()) * when the provider is no longer needed to release the background scheduling thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWorkloadIdentityFederationAuthenticationDetailProvider.WorkloadIdentityFederationAuthenticationDetailProviderBuilder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WorkloadIdentityFederationAuthenticationDetailProvider.WorkloadIdentityFederationAuthenticationDetailProviderBuilderbuilder()Creates a new WorkloadIdentityFederationAuthenticationDetailProviderBuilder.voidclose()StringgetKeyId()Returns the keyId used to sign requests.StringgetPassPhrase()Returns the optional pass phrase for the (encrypted) private key.char[]getPassphraseCharacters()Returns the optional pass phrase for the (encrypted) private key, as a character array.InputStreamgetPrivateKey()Returns a new InputStream to the private key.RegiongetRegion()Returns the region.Stringrefresh()Refreshes the authentication data used by the providerStringrefreshAndGetSecurityTokenIfExpiringWithin(Duration duration)Gets a security token from the federation endpoint if the security token expires within the provided duration.StringrefreshAndGetSecurityTokenIfExpiringWithin(Duration duration, boolean refreshKeys)Gets a security token from the federation endpoint if the security token expires within the provided duration and allows to enable/disable refresh of keys.voidshutdown()Shuts down the authentication provider and releases resources.
-
-
-
Method Detail
-
builder
public static WorkloadIdentityFederationAuthenticationDetailProvider.WorkloadIdentityFederationAuthenticationDetailProviderBuilder builder()
Creates a new WorkloadIdentityFederationAuthenticationDetailProviderBuilder.- Returns:
- A new builder instance.
-
refresh
public String refresh()
Description copied from interface:RefreshableOnNotAuthenticatedProviderRefreshes the authentication data used by the provider- Specified by:
refreshin interfaceRefreshableOnNotAuthenticatedProvider<String>- Returns:
- the refreshed authentication data
-
refreshAndGetSecurityTokenIfExpiringWithin
public String refreshAndGetSecurityTokenIfExpiringWithin(Duration duration)
Description copied from interface:ProvidesConfigurableRefreshGets a security token from the federation endpoint if the security token expires within the provided duration.This will always retrieve a new token from the federation endpoint and does not use a cached token.
- Specified by:
refreshAndGetSecurityTokenIfExpiringWithinin interfaceProvidesConfigurableRefresh- Parameters:
duration- the duration to check- Returns:
- A security token that can be used to authenticate requests.
-
refreshAndGetSecurityTokenIfExpiringWithin
public String refreshAndGetSecurityTokenIfExpiringWithin(Duration duration, boolean refreshKeys)
Description copied from interface:ProvidesConfigurableRefreshGets a security token from the federation endpoint if the security token expires within the provided duration and allows to enable/disable refresh of keys.This will always retrieve a new token from the federation endpoint and does not use a cached token.
- Specified by:
refreshAndGetSecurityTokenIfExpiringWithinin interfaceProvidesConfigurableRefresh- Parameters:
duration- the duration to checkrefreshKeys- boolean value to enable/disable refresh of keys- Returns:
- A security token that can be used to authenticate requests.
-
getRegion
public Region getRegion()
Description copied from interface:RegionProviderReturns the region.- Specified by:
getRegionin interfaceRegionProvider- Returns:
- Region object.
-
getKeyId
public String getKeyId()
Description copied from interface:BasicAuthenticationDetailsProviderReturns the keyId used to sign requests.- Specified by:
getKeyIdin interfaceBasicAuthenticationDetailsProvider- Returns:
- The keyId.
-
getPrivateKey
public InputStream getPrivateKey()
Description copied from interface:BasicAuthenticationDetailsProviderReturns a new InputStream to the private key.This stream should be closed by the caller, implementations should return new streams each time.
- Specified by:
getPrivateKeyin interfaceBasicAuthenticationDetailsProvider- Returns:
- A new InputStream.
-
getPassPhrase
public String getPassPhrase()
Description copied from interface:BasicAuthenticationDetailsProviderReturns the optional pass phrase for the (encrypted) private key.- Specified by:
getPassPhrasein interfaceBasicAuthenticationDetailsProvider- Returns:
- The pass phrase, or null if not applicable
-
getPassphraseCharacters
public char[] getPassphraseCharacters()
Description copied from interface:BasicAuthenticationDetailsProviderReturns the optional pass phrase for the (encrypted) private key, as a character array.- Specified by:
getPassphraseCharactersin interfaceBasicAuthenticationDetailsProvider- Returns:
- The pass phrase as character array, or null if not applicable
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
shutdown
public void shutdown()
Shuts down the authentication provider and releases resources.This method delegates to the federation client’s shutdown method to ensure proper cleanup of the proactive refresh scheduler.
-
-