/** * Finds a {@link Challenge} of the given type. Responding to this {@link Challenge} * is sufficient for authorization. * * @param type * Challenge name (e.g. "http-01") * @return {@link Challenge} matching that name, or {@code null} if there is no such * challenge, or if the challenge alone is not sufficient for authorization. * @throws ClassCastException * if the type does not match the expected Challenge class type */ @SuppressWarnings("unchecked") @CheckForNull public <T extends Challenge> T findChallenge(final String type) { return (T) getChallenges().stream() .filter(ch -> type.equals(ch.getType())) .reduce((a, b) -> {throw new AcmeProtocolException("Found more than one challenge of type " + type);}) .orElse(null); }
/** * Finds a {@link Challenge} of the given type. Responding to this {@link Challenge} * is sufficient for authorization. * * @param type * Challenge name (e.g. "http-01") * @return {@link Challenge} matching that name, or {@code null} if there is no such * challenge, or if the challenge alone is not sufficient for authorization. * @throws ClassCastException * if the type does not match the expected Challenge class type */ @SuppressWarnings("unchecked") @CheckForNull public <T extends Challenge> T findChallenge(final String type) { return (T) getChallenges().stream() .filter(ch -> type.equals(ch.getType())) .reduce((a, b) -> {throw new AcmeProtocolException("Found more than one challenge of type " + type);}) .orElse(null); }
@Override public Tuple2<Order, Dns01Challenge> challengeInit(String domainName) { AssertTools.assertNotNull(account, "You need to log in first"); Order order; try { order = account.newOrder() // .domains(domainName) // .create(); } catch (AcmeException e) { LOGGER.error("Could not ask for domain {}", domainName, e); throw new LetsencryptException("Could not ask for domain " + domainName, e); } // Get the DNS challenge Dns01Challenge challenge = null; List<String> availableChallenges = new ArrayList<>(); for (Authorization auth : order.getAuthorizations()) { auth.getChallenges().stream().map(it -> it.getType()).forEach(it -> availableChallenges.add(it)); challenge = auth.findChallenge(Dns01Challenge.TYPE); } if (challenge == null) { throw new LetsencryptException("DNS Challenge not found for " + domainName + " ; Available challenges are: [" + Joiner.on(", ").join(availableChallenges) + "]"); } return new Tuple2<>(order, challenge); }