mirror of https://github.com/shred/acme4j
Extend findCombination behavior.
The mandant passes in all challenge types it supports, and the method returns the shortest combination required for validation.pull/17/merge
parent
5459676431
commit
3ee7a06e6f
|
@ -124,30 +124,39 @@ public class Authorization {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a combination of {@link Challenge} types that the client supports. The client
|
* Finds a combination of {@link Challenge} types that the client supports. The client
|
||||||
* has to respond to <em>all</em> of the {@link Challenge}s returned.
|
* has to respond to <em>all</em> of the {@link Challenge}s returned. However, this
|
||||||
|
* method attempts to find the combination with the smallest number of
|
||||||
|
* {@link Challenge}s.
|
||||||
*
|
*
|
||||||
* @param types
|
* @param types
|
||||||
* Challenge name or names (e.g. "http-01"), in no particular order.
|
* 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
|
* @return Matching {@link Challenge} combination, or {@code null} if the ACME server
|
||||||
* does not support this challenge combination. The challenges are returned
|
* does not support any of your challenges. The challenges are returned in no
|
||||||
* in no particular order.
|
* 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<Challenge> findCombination(String... types) {
|
public Collection<Challenge> findCombination(String... types) {
|
||||||
Collection<String> reference = Arrays.asList(types);
|
Collection<String> available = Arrays.asList(types);
|
||||||
|
Collection<String> combinationTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
Collection<Challenge> result = null;
|
||||||
|
|
||||||
for (List<Challenge> combination : combinations) {
|
for (List<Challenge> combination : combinations) {
|
||||||
Collection<String> combinationTypes = new ArrayList<>();
|
combinationTypes.clear();
|
||||||
for (Challenge c : combination) {
|
for (Challenge c : combination) {
|
||||||
combinationTypes.add(c.getType());
|
combinationTypes.add(c.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reference.size() == combinationTypes.size()
|
if (available.containsAll(combinationTypes) &&
|
||||||
&& reference.containsAll(combinationTypes)) {
|
(result == null || result.size() > combination.size())) {
|
||||||
return combination;
|
result = combination;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue