mirror of https://github.com/shred/acme4j
Move generic challenge generation to AbstractAcmeProvider
parent
3f8299c004
commit
1eb56ed8d6
|
@ -27,9 +27,9 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.shredzone.acme4j.challenge.Challenge;
|
||||
import org.shredzone.acme4j.challenge.TokenChallenge;
|
||||
import org.shredzone.acme4j.connector.Resource;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||
import org.shredzone.acme4j.provider.AcmeProvider;
|
||||
import org.shredzone.acme4j.toolbox.JSON;
|
||||
|
||||
|
@ -174,15 +174,9 @@ public class Session {
|
|||
* @return {@link Challenge} instance
|
||||
*/
|
||||
public Challenge createChallenge(JSON data) {
|
||||
Objects.requireNonNull(data, "data");
|
||||
|
||||
Challenge challenge = provider().createChallenge(this, data);
|
||||
if (challenge == null) {
|
||||
if (data.contains("token")) {
|
||||
challenge = new TokenChallenge(this, data);
|
||||
} else {
|
||||
challenge = new Challenge(this, data);
|
||||
}
|
||||
throw new AcmeProtocolException("Could not create challenge for: " + data);
|
||||
}
|
||||
return challenge;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.shredzone.acme4j.challenge.Challenge;
|
|||
import org.shredzone.acme4j.challenge.Dns01Challenge;
|
||||
import org.shredzone.acme4j.challenge.Http01Challenge;
|
||||
import org.shredzone.acme4j.challenge.TlsSni02Challenge;
|
||||
import org.shredzone.acme4j.challenge.TokenChallenge;
|
||||
import org.shredzone.acme4j.connector.Connection;
|
||||
import org.shredzone.acme4j.connector.DefaultConnection;
|
||||
import org.shredzone.acme4j.connector.HttpConnector;
|
||||
|
@ -72,6 +73,9 @@ public abstract class AbstractAcmeProvider implements AcmeProvider {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* This implementation handles the standard challenge types. For unknown types,
|
||||
* generic {@link Challenge} or {@link TokenChallenge} instances are created.
|
||||
* <p>
|
||||
* Custom provider implementations may override this method to provide challenges that
|
||||
* are unique to the provider.
|
||||
*/
|
||||
|
@ -83,11 +87,15 @@ public abstract class AbstractAcmeProvider implements AcmeProvider {
|
|||
String type = data.get("type").required().asString();
|
||||
|
||||
BiFunction<Session, JSON, Challenge> constructor = CHALLENGES.get(type);
|
||||
if (constructor == null) {
|
||||
return null;
|
||||
if (constructor != null) {
|
||||
return constructor.apply(session, data);
|
||||
}
|
||||
|
||||
return constructor.apply(session, data);
|
||||
if (data.contains("token")) {
|
||||
return new TokenChallenge(session, data);
|
||||
} else {
|
||||
return new Challenge(session, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -155,7 +155,8 @@ public class AbstractAcmeProviderTest {
|
|||
.put("url", "https://example.com/some/challenge")
|
||||
.toJSON();
|
||||
Challenge c6 = provider.createChallenge(session, json6);
|
||||
assertThat(c6, is(nullValue()));
|
||||
assertThat(c6, not(nullValue()));
|
||||
assertThat(c6, instanceOf(Challenge.class));
|
||||
|
||||
try {
|
||||
JSON json7 = new JSONBuilder()
|
||||
|
|
Loading…
Reference in New Issue