- java.lang.Object
-
- org.shredzone.acme4j.AcmeResource
-
- org.shredzone.acme4j.AcmeJsonResource
-
- org.shredzone.acme4j.challenge.Challenge
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
TokenChallenge
public class Challenge extends AcmeJsonResource
A generic challenge. It can be used as a base class for actual challenge implementations, but it is also used if the ACME server offers a proprietary challenge that is unknown to acme4j.Subclasses must override
acceptable(String)
so it only accepts its own type.prepareResponse(JSONBuilder)
can be overridden to put all required data to the challenge response.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
KEY_ERROR
protected static String
KEY_STATUS
protected static String
KEY_TYPE
protected static String
KEY_URL
protected static String
KEY_VALIDATED
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
acceptable(String type)
Checks if the type is acceptable to this challenge.Optional<Problem>
getError()
Returns a reason why the challenge has failed in the past, if returned by the server.Status
getStatus()
Returns the current status of the challenge.String
getType()
Returns the challenge type by name (e.g.Optional<Instant>
getValidated()
Returns the validation date, if returned by the server.protected void
prepareResponse(JSONBuilder response)
Prepares the response message for triggering the challenge.protected void
setJSON(JSON json)
Sets the JSON representation of the resource data.void
trigger()
Triggers thisChallenge
.-
Methods inherited from class org.shredzone.acme4j.AcmeJsonResource
fetch, getJSON, getRetryAfter, invalidate, isValid, setRetryAfter, update
-
Methods inherited from class org.shredzone.acme4j.AcmeResource
finalize, getLocation, getLogin, getSession, rebind
-
-
-
-
Field Detail
-
KEY_TYPE
protected static final String KEY_TYPE
- See Also:
- Constant Field Values
-
KEY_URL
protected static final String KEY_URL
- See Also:
- Constant Field Values
-
KEY_STATUS
protected static final String KEY_STATUS
- See Also:
- Constant Field Values
-
KEY_VALIDATED
protected static final String KEY_VALIDATED
- See Also:
- Constant Field Values
-
KEY_ERROR
protected static final String KEY_ERROR
- See Also:
- Constant Field Values
-
-
Method Detail
-
getStatus
public Status getStatus()
Returns the current status of the challenge.Possible values are:
Status.PENDING
,Status.PROCESSING
,Status.VALID
,Status.INVALID
.A challenge is only completed when it reaches either status
Status.VALID
orStatus.INVALID
.
-
getValidated
public Optional<Instant> getValidated()
Returns the validation date, if returned by the server.
-
getError
public Optional<Problem> getError()
Returns a reason why the challenge has failed in the past, if returned by the server. If there are multiple errors, they can be found inProblem.getSubProblems()
.
-
prepareResponse
protected void prepareResponse(JSONBuilder response)
Prepares the response message for triggering the challenge. Subclasses can add fields to theJSONBuilder
as required by the challenge. Implementations of subclasses should make sure thatprepareResponse(JSONBuilder)
of the superclass is invoked.- Parameters:
response
-JSONBuilder
to write the response to
-
acceptable
protected boolean acceptable(String type)
Checks if the type is acceptable to this challenge. This generic class only checks if the type is not blank. Subclasses should instead check if the given type matches expected challenge type.- Parameters:
type
- Type to check- Returns:
true
if acceptable,false
if not
-
setJSON
protected void setJSON(JSON json)
Description copied from class:AcmeJsonResource
Sets the JSON representation of the resource data.- Overrides:
setJSON
in classAcmeJsonResource
- Parameters:
json
- NewJSON
data, must not benull
.
-
trigger
public void trigger() throws AcmeException
Triggers thisChallenge
. The ACME server is requested to validate the response. Note that the validation is performed asynchronously by the ACME server.After a challenge is triggered, it changes to
Status.PENDING
. As soon as validation takes place, it changes toStatus.PROCESSING
. After validation the status changes toStatus.VALID
orStatus.INVALID
, depending on the outcome of the validation.If the challenge requires a resource to be set on your side (e.g. a DNS record or an HTTP file), it must be reachable from public before
trigger()
is invoked, and must not be taken down until the challenge has reachedStatus.VALID
orStatus.INVALID
.If this method is invoked a second time, the ACME server is requested to retry the validation. This can be useful if the client state has changed, for example after a firewall rule has been updated.
- Throws:
AcmeException
-
-