diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java index 799d7ac5..89463a08 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java @@ -123,6 +123,18 @@ public class Login { return new Order(this, requireNonNull(location, "location")); } + /** + * Creates a new instance of {@link Challenge} and binds it to this login. + * + * @param location + * Location URL of the challenge + * @return + * {@link Challenge} bound to the login + */ + public Challenge bindChallenge(URL location) { + return new Challenge(this, requireNonNull(location, "location")); + } + /** * Creates a {@link Challenge} instance for the given challenge data. * diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java index 55d1fbda..36c6480b 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java @@ -13,6 +13,7 @@ */ package org.shredzone.acme4j.challenge; +import java.net.URL; import java.time.Instant; import javax.annotation.CheckForNull; @@ -51,6 +52,11 @@ public class Challenge extends AcmeJsonResource { protected static final String KEY_VALIDATED = "validated"; protected static final String KEY_ERROR = "error"; + public Challenge(Login login, URL location) { + super(login, location); + } + + /** * Creates a new generic {@link Challenge} object. * diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java index 79d94df9..fc60c0d9 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java @@ -83,6 +83,11 @@ public class LoginTest { assertThat(order, is(notNullValue())); assertThat(order.getLogin(), is(login)); assertThat(order.getLocation(), is(resourceUrl)); + + Challenge challenge = login.bindChallenge(resourceUrl); + assertThat(challenge, is(notNullValue())); + assertThat(challenge.getLogin(), is(login)); + assertThat(challenge.getLocation(), is(resourceUrl)); } /**