001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2015 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.provider;
015
016import java.net.MalformedURLException;
017import java.net.URI;
018import java.net.URL;
019
020/**
021 * A generic {@link AcmeProvider}. It should be working for all ACME servers complying to
022 * the ACME specifications.
023 * <p>
024 * The {@code serverUri} is either a http or https URI to the server's directory service.
025 */
026public class GenericAcmeProvider extends AbstractAcmeProvider {
027
028    @Override
029    public boolean accepts(URI serverUri) {
030        return "http".equals(serverUri.getScheme())
031                        || "https".equals(serverUri.getScheme());
032    }
033
034    @Override
035    public URL resolve(URI serverUri) {
036        try {
037            return serverUri.toURL();
038        } catch (MalformedURLException ex) {
039            throw new IllegalArgumentException("Bad generic server URI", ex);
040        }
041    }
042
043}