An Order contains Authorization objects (retrieved via getAuthorizations()), one for each domain. You must process all authorizations in a PENDING state before finalizing the order.
To authorize a domain, you must complete a Challenge. An Authorization offers multiple challenges via getChallenges(), but you only need to complete one to succeed.
Use findChallenge() to select a challenge by its class type (preferred for compile-time safety) or by its name. Once your infrastructure is ready to respond to the challenge (e.g., DNS or HTTP setup), call challenge.trigger().
Important:
- Ensure your server is ready to respond before calling
trigger(). - Keep the challenge response available until the authorization status changes to
VALID or INVALID, as the CA may perform multiple checks from different IPs. - Poll the status using
auth.fetch() until the status is no longer PENDING.
// 1. Find the pending authorizations
for (Authorization auth : order.getAuthorizations()) {
if (auth.getStatus() == Status.PENDING) {
log.info("Authorizing " + auth.getIdentifier());
// 2. Find a challenge type your system supports (e.g., HTTP-01)
Optional<Http01Challenge> challenge = auth.findChallenge(Http01Challenge.class);
if (challenge.isPresent()) {
// 3. Trigger the challenge after setting up your server response
challenge.get().trigger();
// 4. Poll for completion
while (!EnumSet.of(Status.VALID, Status.INVALID).contains(auth.getStatus())) {
Thread.sleep(3000L);
auth.fetch();
}
}
}
}