mirror of https://github.com/shred/acme4j
Account returns a list of orders
parent
4b96878688
commit
e192f300b4
|
@ -37,6 +37,7 @@ import org.shredzone.acme4j.exception.AcmeException;
|
||||||
import org.shredzone.acme4j.exception.AcmeLazyLoadingException;
|
import org.shredzone.acme4j.exception.AcmeLazyLoadingException;
|
||||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||||
import org.shredzone.acme4j.exception.AcmeRetryAfterException;
|
import org.shredzone.acme4j.exception.AcmeRetryAfterException;
|
||||||
|
import org.shredzone.acme4j.provider.pebble.Pebble;
|
||||||
import org.shredzone.acme4j.util.JSON;
|
import org.shredzone.acme4j.util.JSON;
|
||||||
import org.shredzone.acme4j.util.JSONBuilder;
|
import org.shredzone.acme4j.util.JSONBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -50,16 +51,14 @@ public class Registration extends AcmeResource {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Registration.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Registration.class);
|
||||||
|
|
||||||
private static final String KEY_TOS_AGREED = "terms-of-service-agreed";
|
private static final String KEY_TOS_AGREED = "terms-of-service-agreed";
|
||||||
private static final String KEY_AUTHORIZATIONS = "authorizations";
|
private static final String KEY_ORDERS = "orders";
|
||||||
private static final String KEY_CERTIFICATES = "certificates";
|
|
||||||
private static final String KEY_CONTACT = "contact";
|
private static final String KEY_CONTACT = "contact";
|
||||||
private static final String KEY_STATUS = "status";
|
private static final String KEY_STATUS = "status";
|
||||||
|
|
||||||
private final List<URI> contacts = new ArrayList<>();
|
private final List<URI> contacts = new ArrayList<>();
|
||||||
private Status status;
|
private Status status;
|
||||||
private Boolean termsOfServiceAgreed;
|
private Boolean termsOfServiceAgreed;
|
||||||
private URL authorizations;
|
private URL orders;
|
||||||
private URL certificates;
|
|
||||||
private boolean loaded = false;
|
private boolean loaded = false;
|
||||||
|
|
||||||
protected Registration(Session session, URL location) {
|
protected Registration(Session session, URL location) {
|
||||||
|
@ -109,37 +108,20 @@ public class Registration extends AcmeResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an {@link Iterator} of all {@link Authorization} belonging to this
|
* Returns an {@link Iterator} of all {@link Order} belonging to this
|
||||||
* {@link Registration}.
|
* {@link Registration}.
|
||||||
* <p>
|
* <p>
|
||||||
* Using the iterator will initiate one or more requests to the ACME server.
|
* Using the iterator will initiate one or more requests to the ACME server.
|
||||||
*
|
*
|
||||||
* @return {@link Iterator} instance that returns {@link Authorization} objects.
|
* @return {@link Iterator} instance that returns {@link Order} objects.
|
||||||
* {@link Iterator#hasNext()} and {@link Iterator#next()} may throw
|
* {@link Iterator#hasNext()} and {@link Iterator#next()} may throw
|
||||||
* {@link AcmeProtocolException} if a batch of authorization URIs could not be
|
* {@link AcmeProtocolException} if a batch of authorization URIs could not be
|
||||||
* fetched from the server.
|
* fetched from the server.
|
||||||
*/
|
*/
|
||||||
public Iterator<Authorization> getAuthorizations() throws AcmeException {
|
public Iterator<Order> getOrders() throws AcmeException {
|
||||||
LOG.debug("getAuthorizations");
|
LOG.debug("getOrders");
|
||||||
load();
|
load();
|
||||||
return new ResourceIterator<>(getSession(), KEY_AUTHORIZATIONS, authorizations, Authorization::bind);
|
return new ResourceIterator<>(getSession(), KEY_ORDERS, orders, Order::bind);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an {@link Iterator} of all {@link Certificate} belonging to this
|
|
||||||
* {@link Registration}.
|
|
||||||
* <p>
|
|
||||||
* Using the iterator will initiate one or more requests to the ACME server.
|
|
||||||
*
|
|
||||||
* @return {@link Iterator} instance that returns {@link Certificate} objects.
|
|
||||||
* {@link Iterator#hasNext()} and {@link Iterator#next()} may throw
|
|
||||||
* {@link AcmeProtocolException} if a batch of certificate URIs could not be
|
|
||||||
* fetched from the server.
|
|
||||||
*/
|
|
||||||
public Iterator<Certificate> getCertificates() throws AcmeException {
|
|
||||||
LOG.debug("getCertificates");
|
|
||||||
load();
|
|
||||||
return new ResourceIterator<>(getSession(), KEY_CERTIFICATES, certificates, Certificate::bind);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -329,8 +311,10 @@ public class Registration extends AcmeResource {
|
||||||
.forEach(contacts::add);
|
.forEach(contacts::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.authorizations = json.get(KEY_AUTHORIZATIONS).asURL();
|
// TODO PEBBLE: returns an empty string as URL
|
||||||
this.certificates = json.get(KEY_CERTIFICATES).asURL();
|
if (!Pebble.workaround()) {
|
||||||
|
this.orders = json.get(KEY_ORDERS).asURL();
|
||||||
|
}
|
||||||
|
|
||||||
if (json.contains(KEY_STATUS)) {
|
if (json.contains(KEY_STATUS)) {
|
||||||
this.status = Status.parse(json.get(KEY_STATUS).asString());
|
this.status = Status.parse(json.get(KEY_STATUS).asString());
|
||||||
|
|
|
@ -74,17 +74,9 @@ public class RegistrationTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRequest(URL url, Session session) {
|
public void sendRequest(URL url, Session session) {
|
||||||
if (url("https://example.com/acme/reg/1/authz").equals(url)) {
|
if (url("https://example.com/acme/acct/1/orders").equals(url)) {
|
||||||
jsonResponse = new JSONBuilder()
|
jsonResponse = new JSONBuilder()
|
||||||
.array("authorizations", "https://example.com/acme/auth/1")
|
.array("orders", "https://example.com/acme/order/1")
|
||||||
.toJSON();
|
|
||||||
response = HttpURLConnection.HTTP_OK;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url("https://example.com/acme/reg/1/cert").equals(url)) {
|
|
||||||
jsonResponse = new JSONBuilder()
|
|
||||||
.array("certificates", "https://example.com/acme/cert/1")
|
|
||||||
.toJSON();
|
.toJSON();
|
||||||
response = HttpURLConnection.HTTP_OK;
|
response = HttpURLConnection.HTTP_OK;
|
||||||
return;
|
return;
|
||||||
|
@ -134,15 +126,10 @@ public class RegistrationTest {
|
||||||
assertThat(registration.getContacts().get(0), is(URI.create("mailto:foo2@example.com")));
|
assertThat(registration.getContacts().get(0), is(URI.create("mailto:foo2@example.com")));
|
||||||
assertThat(registration.getStatus(), is(Status.VALID));
|
assertThat(registration.getStatus(), is(Status.VALID));
|
||||||
|
|
||||||
Iterator<Authorization> authIt = registration.getAuthorizations();
|
Iterator<Order> orderIt = registration.getOrders();
|
||||||
assertThat(authIt, not(nullValue()));
|
assertThat(orderIt, not(nullValue()));
|
||||||
assertThat(authIt.next().getLocation(), is(url("https://example.com/acme/auth/1")));
|
assertThat(orderIt.next().getLocation(), is(url("https://example.com/acme/order/1")));
|
||||||
assertThat(authIt.hasNext(), is(false));
|
assertThat(orderIt.hasNext(), is(false));
|
||||||
|
|
||||||
Iterator<Certificate> certIt = registration.getCertificates();
|
|
||||||
assertThat(certIt, not(nullValue()));
|
|
||||||
assertThat(certIt.next().getLocation(), is(url("https://example.com/acme/cert/1")));
|
|
||||||
assertThat(certIt.hasNext(), is(false));
|
|
||||||
|
|
||||||
provider.close();
|
provider.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
{
|
{
|
||||||
|
"status": "valid",
|
||||||
"contact": [
|
"contact": [
|
||||||
"mailto:foo2@example.com"
|
"mailto:foo2@example.com"
|
||||||
],
|
],
|
||||||
"status": "valid",
|
|
||||||
"terms-of-service-agreed": true,
|
"terms-of-service-agreed": true,
|
||||||
"authorizations": "https://example.com/acme/reg/1/authz",
|
"orders": "https://example.com/acme/acct/1/orders"
|
||||||
"certificates": "https://example.com/acme/reg/1/cert"
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue