Class DefaultJwtSource
java.lang.Object
io.spiffe.workloadapi.DefaultJwtSource
- All Implemented Interfaces:
BundleSource<JwtBundle>,JwtSvidSource,JwtSource,Closeable,AutoCloseable
Represents a source of SPIFFE JWT SVIDs and JWT bundles maintained via the Workload API.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this source, dropping the connection to the Workload API.fetchJwtSvid(SpiffeId subject, String audience, String... extraAudiences) Fetches a new JWT SVID from the Workload API for the given subject SPIFFE ID and audiences.fetchJwtSvid(String audience, String... extraAudiences) Fetches a JWT-SVID from the source with the given audiences.fetchJwtSvids(SpiffeId subject, String audience, String... extraAudiences) Fetches all new JWT SVIDs from the Workload API for the given subject SPIFFE ID and audiences.fetchJwtSvids(String audience, String... extraAudiences) Fetches all SPIFFE JWT-SVIDs on one-shot blocking call.getBundleForTrustDomain(@NonNull TrustDomain trustDomain) Returns the JWT bundle for a given trust domain.static JwtSourceCreates a new JWT source.static JwtSourcenewSource(@NonNull JwtSourceOptions options) Creates a new JWT source.
-
Method Details
-
newSource
Creates a new JWT source. It blocks until the initial update with the JWT bundles has been received from the Workload API or until the timeout configured through the system property `spiffe.newJwtSource.timeout` expires. If no timeout is configured, it blocks until it gets a JWT update from the Workload API.It uses the default address socket endpoint from the environment variable to get the Workload API address.
- Returns:
- an instance of
DefaultJwtSource, with the JWT bundles initialized - Throws:
SocketEndpointAddressException- if the address to the Workload API is not validJwtSourceException- if the source could not be initialized
-
newSource
public static JwtSource newSource(@NonNull @NonNull JwtSourceOptions options) throws SocketEndpointAddressException, JwtSourceException Creates a new JWT source. It blocks until the initial update with the JWT bundles has been received from the Workload API, doing retries with a backoff exponential policy, or until the initTimeout has expired.If the timeout is not provided in the options, the default timeout is read from the system property `spiffe.newJwtSource.timeout`. If none is configured, this method will block until the JWT bundles can be retrieved from the Workload API.
The
WorkloadApiClientcan be provided in the options, if it is not, a new client is created.- Parameters:
options-JwtSourceOptions- Returns:
- an instance of
DefaultJwtSource, with the JWT bundles initialized - Throws:
SocketEndpointAddressException- if the address to the Workload API is not validJwtSourceException- if the source could not be initialized
-
fetchJwtSvid
Description copied from interface:JwtSvidSourceFetches a JWT-SVID from the source with the given audiences.- Specified by:
fetchJwtSvidin interfaceJwtSvidSource- Parameters:
audience- the audienceextraAudiences- a list of extra audiences as an array of String- Returns:
- a
JwtSvid - Throws:
JwtSvidException- when there is an error fetching the JWT SVID
-
fetchJwtSvid
public JwtSvid fetchJwtSvid(SpiffeId subject, String audience, String... extraAudiences) throws JwtSvidException Fetches a new JWT SVID from the Workload API for the given subject SPIFFE ID and audiences.- Specified by:
fetchJwtSvidin interfaceJwtSvidSource- Parameters:
subject- aSpiffeIdaudience- the audienceextraAudiences- a list of extra audiences as an array of String- Returns:
- a
JwtSvid - Throws:
IllegalStateException- if the source is closedJwtSvidException- when there is an error fetching the JWT SVID
-
fetchJwtSvids
public List<JwtSvid> fetchJwtSvids(String audience, String... extraAudiences) throws JwtSvidException Description copied from interface:JwtSvidSourceFetches all SPIFFE JWT-SVIDs on one-shot blocking call.- Specified by:
fetchJwtSvidsin interfaceJwtSvidSource- Parameters:
audience- the audience of the JWT-SVIDextraAudiences- the extra audience for the JWT_SVID- Returns:
- all of
JwtSvidobject - Throws:
JwtSvidException- if there is an error fetching or processing the JWT from the Workload API
-
fetchJwtSvids
public List<JwtSvid> fetchJwtSvids(SpiffeId subject, String audience, String... extraAudiences) throws JwtSvidException Fetches all new JWT SVIDs from the Workload API for the given subject SPIFFE ID and audiences.- Specified by:
fetchJwtSvidsin interfaceJwtSvidSource- Parameters:
subject- a SPIFFE IDaudience- the audience of the JWT-SVIDextraAudiences- the extra audience for the JWT_SVID- Returns:
- all
JwtSvids - Throws:
IllegalStateException- if the source is closedJwtSvidException- if there is an error fetching or processing the JWT from the Workload API
-
getBundleForTrustDomain
public JwtBundle getBundleForTrustDomain(@NonNull @NonNull TrustDomain trustDomain) throws BundleNotFoundException Returns the JWT bundle for a given trust domain.- Specified by:
getBundleForTrustDomainin interfaceBundleSource<JwtBundle>- Parameters:
trustDomain- an instance of aTrustDomain- Returns:
- an instance of a
X509Bundle - Throws:
BundleNotFoundException- is there is no bundle for the trust domain providedIllegalStateException- if the source is closed
-
close
public void close()Closes this source, dropping the connection to the Workload API. Other source methods will return an error after close has been called.It is marked with
SneakyThrowsbecause it is not expected to throw the checked exception defined on theCloseableinterface.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-