mirror of https://github.com/shred/acme4j
Evaluate terms-of-service header. Agreement property is now type URI.
parent
7ecf5674c9
commit
5fc97fab34
|
@ -24,22 +24,22 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class Registration {
|
public class Registration {
|
||||||
|
|
||||||
private String agreementUrl;
|
|
||||||
private List<String> contacts = new ArrayList<>();
|
private List<String> contacts = new ArrayList<>();
|
||||||
|
private URI agreement;
|
||||||
private URI location;
|
private URI location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URL of the agreement document the user is required to accept.
|
* Returns the URI of the agreement document the user is required to accept.
|
||||||
*/
|
*/
|
||||||
public String getAgreementUrl() {
|
public URI getAgreement() {
|
||||||
return agreementUrl;
|
return agreement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the URL of the agreement document the user is required to accept.
|
* Sets the URI of the agreement document the user is required to accept.
|
||||||
*/
|
*/
|
||||||
public void setAgreementUrl(String agreementUrl) {
|
public void setAgreement(URI agreement) {
|
||||||
this.agreementUrl = agreementUrl;
|
this.agreement = agreement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,8 +81,6 @@ public abstract class AbstractAcmeClient implements AcmeClient {
|
||||||
if (!registration.getContacts().isEmpty()) {
|
if (!registration.getContacts().isEmpty()) {
|
||||||
claims.put("contact", registration.getContacts());
|
claims.put("contact", registration.getContacts());
|
||||||
}
|
}
|
||||||
if (registration.getAgreementUrl() != null) {
|
|
||||||
claims.put("agreement", registration.getAgreementUrl());
|
|
||||||
|
|
||||||
int rc = conn.sendSignedRequest(resourceUri(Resource.NEW_REG), claims, session, account);
|
int rc = conn.sendSignedRequest(resourceUri(Resource.NEW_REG), claims, session, account);
|
||||||
if (rc != HttpURLConnection.HTTP_CREATED && rc != HttpURLConnection.HTTP_CONFLICT) {
|
if (rc != HttpURLConnection.HTTP_CREATED && rc != HttpURLConnection.HTTP_CONFLICT) {
|
||||||
|
@ -94,6 +92,11 @@ public abstract class AbstractAcmeClient implements AcmeClient {
|
||||||
registration.setLocation(location);
|
registration.setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URI tos = conn.getLink("terms-of-service");
|
||||||
|
if (tos != null) {
|
||||||
|
registration.setAgreement(tos);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc == HttpURLConnection.HTTP_CONFLICT) {
|
if (rc == HttpURLConnection.HTTP_CONFLICT) {
|
||||||
throw new AcmeConflictException("Account is already registered", location);
|
throw new AcmeConflictException("Account is already registered", location);
|
||||||
}
|
}
|
||||||
|
@ -113,8 +116,8 @@ public abstract class AbstractAcmeClient implements AcmeClient {
|
||||||
if (!registration.getContacts().isEmpty()) {
|
if (!registration.getContacts().isEmpty()) {
|
||||||
claims.put("contact", registration.getContacts());
|
claims.put("contact", registration.getContacts());
|
||||||
}
|
}
|
||||||
if (registration.getAgreementUrl() != null) {
|
if (registration.getAgreement() != null) {
|
||||||
claims.put("agreement", registration.getAgreementUrl());
|
claims.put("agreement", registration.getAgreement());
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = conn.sendSignedRequest(registration.getLocation(), claims, session, account);
|
int rc = conn.sendSignedRequest(registration.getLocation(), claims, session, account);
|
||||||
|
@ -123,6 +126,11 @@ public abstract class AbstractAcmeClient implements AcmeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
registration.setLocation(conn.getLocation());
|
registration.setLocation(conn.getLocation());
|
||||||
|
|
||||||
|
URI tos = conn.getLink("terms-of-service");
|
||||||
|
if (tos != null) {
|
||||||
|
registration.setAgreement(tos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,16 +35,16 @@ public class RegistrationTest {
|
||||||
public void testGetterAndSetter() throws URISyntaxException {
|
public void testGetterAndSetter() throws URISyntaxException {
|
||||||
Registration registration = new Registration();
|
Registration registration = new Registration();
|
||||||
|
|
||||||
assertThat(registration.getAgreementUrl(), is(nullValue()));
|
assertThat(registration.getAgreement(), is(nullValue()));
|
||||||
assertThat(registration.getLocation(), is(nullValue()));
|
assertThat(registration.getLocation(), is(nullValue()));
|
||||||
assertThat(registration.getContacts(), is(empty()));
|
assertThat(registration.getContacts(), is(empty()));
|
||||||
|
|
||||||
registration.setAgreementUrl("http://example.com/agreement.pdf");
|
registration.setAgreement(new URI("http://example.com/agreement.pdf"));
|
||||||
registration.setLocation(new URI("http://example.com/acme/12345"));
|
registration.setLocation(new URI("http://example.com/acme/12345"));
|
||||||
registration.getContacts().add("mailto:foo@example.com");
|
registration.getContacts().add("mailto:foo@example.com");
|
||||||
registration.getContacts().add("mailto:bar@example.com");
|
registration.getContacts().add("mailto:bar@example.com");
|
||||||
|
|
||||||
assertThat(registration.getAgreementUrl(), is("http://example.com/agreement.pdf"));
|
assertThat(registration.getAgreement(), is(new URI("http://example.com/agreement.pdf")));
|
||||||
assertThat(registration.getLocation(), is(new URI("http://example.com/acme/12345")));
|
assertThat(registration.getLocation(), is(new URI("http://example.com/acme/12345")));
|
||||||
assertThat(registration.getContacts(), contains("mailto:foo@example.com", "mailto:bar@example.com"));
|
assertThat(registration.getContacts(), contains("mailto:foo@example.com", "mailto:bar@example.com"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import org.shredzone.acme4j.challenge.Challenge;
|
import org.shredzone.acme4j.challenge.Challenge;
|
||||||
import org.shredzone.acme4j.challenge.HttpChallenge;
|
import org.shredzone.acme4j.challenge.HttpChallenge;
|
||||||
|
import org.shredzone.acme4j.exception.AcmeConflictException;
|
||||||
import org.shredzone.acme4j.exception.AcmeException;
|
import org.shredzone.acme4j.exception.AcmeException;
|
||||||
import org.shredzone.acme4j.util.CSRBuilder;
|
import org.shredzone.acme4j.util.CSRBuilder;
|
||||||
import org.shredzone.acme4j.util.CertificateUtils;
|
import org.shredzone.acme4j.util.CertificateUtils;
|
||||||
|
@ -60,10 +61,10 @@ public class ClientTest {
|
||||||
*
|
*
|
||||||
* @param domains
|
* @param domains
|
||||||
* Domains to get a common certificate for
|
* Domains to get a common certificate for
|
||||||
* @param agreementUrl
|
* @param agreement
|
||||||
* Agreement URL to be used for creating an account
|
* Agreement URI to be used for creating an account
|
||||||
*/
|
*/
|
||||||
public void fetchCertificate(Collection<String> domains, String agreementUrl)
|
public void fetchCertificate(Collection<String> domains, URI agreement)
|
||||||
throws IOException, AcmeException {
|
throws IOException, AcmeException {
|
||||||
// Load or create a key pair for the user's account
|
// Load or create a key pair for the user's account
|
||||||
KeyPair userKeyPair;
|
KeyPair userKeyPair;
|
||||||
|
@ -87,10 +88,12 @@ public class ClientTest {
|
||||||
|
|
||||||
// Register a new user
|
// Register a new user
|
||||||
Registration reg = new Registration();
|
Registration reg = new Registration();
|
||||||
reg.setAgreementUrl(agreementUrl);
|
reg.setAgreement(agreement);
|
||||||
try {
|
try {
|
||||||
client.newRegistration(account, reg);
|
client.newRegistration(account, reg);
|
||||||
LOG.info("Registered a new user, URI: " + reg.getLocation());
|
LOG.info("Registered a new user, URI: " + reg.getLocation());
|
||||||
|
} catch (AcmeConflictException ex) {
|
||||||
|
LOG.info("Account does already exist, URI: " + reg.getLocation());
|
||||||
} catch (AcmeException ex) {
|
} catch (AcmeException ex) {
|
||||||
LOG.warn("Registration failed", ex);
|
LOG.warn("Registration failed", ex);
|
||||||
|
|
||||||
|
@ -198,7 +201,7 @@ public class ClientTest {
|
||||||
Collection<String> domains = Arrays.asList(args);
|
Collection<String> domains = Arrays.asList(args);
|
||||||
try {
|
try {
|
||||||
ClientTest ct = new ClientTest();
|
ClientTest ct = new ClientTest();
|
||||||
ct.fetchCertificate(domains, AGREEMENT_URL);
|
ct.fetchCertificate(domains, new URI(AGREEMENT_URL));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Failed to get a certificate for domains " + domains, ex);
|
LOG.error("Failed to get a certificate for domains " + domains, ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue