diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java
index 87373b0f..69d155e7 100644
--- a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java
+++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java
@@ -124,30 +124,39 @@ public class Authorization {
/**
* Finds a combination of {@link Challenge} types that the client supports. The client
- * has to respond to all of the {@link Challenge}s returned.
+ * has to respond to all of the {@link Challenge}s returned. However, this
+ * method attempts to find the combination with the smallest number of
+ * {@link Challenge}s.
*
* @param types
* Challenge name or names (e.g. "http-01"), in no particular order.
+ * Basically this is a collection of all challenge types supported by your
+ * implementation.
* @return Matching {@link Challenge} combination, or {@code null} if the ACME server
- * does not support this challenge combination. The challenges are returned
- * in no particular order.
+ * does not support any of your challenges. The challenges are returned in no
+ * particular order. The result may be a subset of the types you have
+ * provided, if fewer challenges are actually required for a successful
+ * validation.
*/
public Collection findCombination(String... types) {
- Collection reference = Arrays.asList(types);
+ Collection available = Arrays.asList(types);
+ Collection combinationTypes = new ArrayList<>();
+
+ Collection result = null;
for (List combination : combinations) {
- Collection combinationTypes = new ArrayList<>();
+ combinationTypes.clear();
for (Challenge c : combination) {
combinationTypes.add(c.getType());
}
- if (reference.size() == combinationTypes.size()
- && reference.containsAll(combinationTypes)) {
- return combination;
+ if (available.containsAll(combinationTypes) &&
+ (result == null || result.size() > combination.size())) {
+ result = combination;
}
}
- return null;
+ return result;
}
}