Class SuppliedTokenSource
- All Implemented Interfaces:
TokenSource,AutoCloseable
TokenSource works identically whether the SDK obtained the token or was
handed one.
This is not a credential kind and it takes no part in TokenSourceChain. It presents
nothing and proves nothing: some other component - a sidecar, a broker, an outer application
layer that authenticated once for many SDK instances - did the proving, and this simply carries
the result. The SDK has always had that door open, in the constructor that accepts a manual
access token; what it lacked was a way for the door to lead to the same place as every other one.
It cannot re-mint, and says so rather than pretending
There is no credential here to mint from. invalidate() therefore ends the session:
the token is discarded, the transport is unbound, and the next call fails with a message that
names the situation. The alternative - returning the same dead token forever - would turn one
clear failure into an unbounded run of opaque 401s.
-
Constructor Summary
ConstructorsConstructorDescriptionSuppliedTokenSource(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient client, String token) -
Method Summary
Modifier and TypeMethodDescriptionReturns a token that is valid now, minting one if none is cached or the cached one is inside the refresh window, and binding whatever it returns to the transport.voidclose()Releases any credential this source retains for re-minting, and discards the cached token.voidDiscards the cached token and unbinds it from the transport, so the nextTokenSource.accessToken()mints a fresh one.Names the credential kind this source presents.toString()The wrapper redacts; at most a six-character prefix of the token can appear.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface co.ankatech.ankasecure.sdk.auth.TokenSource
currentTokenExpiry
-
Constructor Details
-
SuppliedTokenSource
public SuppliedTokenSource(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient client, String token) - Parameters:
client- the transport to bind the token totoken- the access token; copied, so the caller may keep or clear their own- Throws:
NullPointerException- if either argument isnullIllegalArgumentException- iftokenis blank
-
-
Method Details
-
accessToken
Description copied from interface:TokenSourceReturns a token that is valid now, minting one if none is cached or the cached one is inside the refresh window, and binding whatever it returns to the transport.Concurrent callers of a stale source do not stampede the token endpoint: exactly one mints and the rest observe its result.
- Specified by:
accessTokenin interfaceTokenSource- Returns:
- the ANKASecure access token; never
nulland never blank - Throws:
AnkaSecureSdkException- if a token cannot be obtained. A failure leaves any previously cached token untouched rather than poisoning the cache with the failure.
-
invalidate
public void invalidate()Description copied from interface:TokenSourceDiscards the cached token and unbinds it from the transport, so the nextTokenSource.accessToken()mints a fresh one.This is what a caller does on a
401it did not expect. A token can be refused while still unexpired locally - revoked at logout, superseded by a revocation epoch, or invalidated by a role change - and the localexpclaim cannot see any of that.Idempotent, and safe to call on a source that has never minted.
- Specified by:
invalidatein interfaceTokenSource
-
close
public void close()Description copied from interface:TokenSourceReleases any credential this source retains for re-minting, and discards the cached token.Idempotent. Overridden to drop the checked exception
AutoCloseabledeclares, so a try-with-resources over a token source needs no catch clause.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTokenSource
-
mechanism
Description copied from interface:TokenSourceNames the credential kind this source presents. Diagnostic only; nothing branches on it.- Specified by:
mechanismin interfaceTokenSource- Returns:
- the mechanism; never
null
-
toString
The wrapper redacts; at most a six-character prefix of the token can appear.
-