Class FileBearerTokenProvider
java.lang.Object
org.apache.polaris.extension.auth.opa.token.FileBearerTokenProvider
- All Implemented Interfaces:
AutoCloseable,BearerTokenProvider
A token provider that reads tokens from a file and automatically reloads them based on a
configurable refresh interval or JWT expiration timing.
This is particularly useful in Kubernetes environments where tokens are mounted as files and refreshed by external systems (e.g., service account tokens, projected volumes, etc.).
The token file is expected to contain the bearer token as plain text. Leading and trailing whitespace will be trimmed.
If JWT expiration refresh is enabled and the token is a valid JWT with an 'exp' claim, the provider will automatically refresh the token based on the expiration time minus a configurable buffer, rather than using the fixed refresh interval.
-
Constructor Summary
ConstructorsConstructorDescriptionFileBearerTokenProvider(Path tokenFilePath, Duration refreshInterval, boolean jwtExpirationRefresh, Duration jwtExpirationBuffer, Duration initialTokenWait, org.apache.polaris.nosql.async.AsyncExec asyncExec, Supplier<Instant> clock) Create a new file-based token provider with JWT expiration support. -
Method Summary
-
Constructor Details
-
FileBearerTokenProvider
public FileBearerTokenProvider(Path tokenFilePath, Duration refreshInterval, boolean jwtExpirationRefresh, Duration jwtExpirationBuffer, Duration initialTokenWait, org.apache.polaris.nosql.async.AsyncExec asyncExec, Supplier<Instant> clock) Create a new file-based token provider with JWT expiration support.- Parameters:
tokenFilePath- path to the file containing the bearer tokenrefreshInterval- how often to check for token file changes (fallback for non-JWT tokens)jwtExpirationRefresh- whether to use JWT expiration for refresh timingjwtExpirationBuffer- buffer time before JWT expiration to refresh the tokenclock- clock instance for time operations- Throws:
IllegalStateException- if the initial token cannot be loaded from the file
-
-
Method Details
-
getToken
Description copied from interface:BearerTokenProviderGet the current bearer token.- Specified by:
getTokenin interfaceBearerTokenProvider- Returns:
- the bearer token, or null if no token is available
-
close
public void close()Description copied from interface:BearerTokenProviderClean up any resources used by this token provider. Should be called when the provider is no longer needed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBearerTokenProvider
-