From 8819558b3f11037aa3d39976424f52fa05f566b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 1 May 2017 15:39:18 +0200 Subject: [PATCH] Authorization returns scope Order --- .../java/org/shredzone/acme4j/Authorization.java | 15 +++++++++++++++ .../org/shredzone/acme4j/AuthorizationTest.java | 1 + .../json/updateAuthorizationResponse.json | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java index 588c32a5..976d52f1 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java @@ -43,6 +43,7 @@ public class Authorization extends AcmeResource { private String domain; private Status status; private Instant expires; + private Order scope; private List challenges; private boolean loaded = false; @@ -89,6 +90,15 @@ public class Authorization extends AcmeResource { return expires; } + /** + * Gets the scope of the {@link Authorization}. If not {@code null}, this + * {@link Authorization} is only valid for the returned {@link Order}. + */ + public Order getScope() { + load(); + return scope; + } + /** * Gets a list of all challenges offered by the server. */ @@ -193,6 +203,11 @@ public class Authorization extends AcmeResource { domain = jsonIdentifier.get("value").asString(); } + URL scopeUrl = json.get("scope").asURL(); + if (scopeUrl != null) { + scope = Order.bind(getSession(), scopeUrl); + } + challenges = fetchChallenges(json); loaded = true; diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java index ef104cc5..e83a7238 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java @@ -127,6 +127,7 @@ public class AuthorizationTest { assertThat(auth.getStatus(), is(Status.VALID)); assertThat(auth.getExpires(), is(parseTimestamp("2016-01-02T17:12:40Z"))); assertThat(auth.getLocation(), is(locationUrl)); + assertThat(auth.getScope().getLocation(), is(url("https://example.com/order/123"))); assertThat(auth.getChallenges(), containsInAnyOrder( (Challenge) httpChallenge, (Challenge) dnsChallenge)); diff --git a/acme4j-client/src/test/resources/json/updateAuthorizationResponse.json b/acme4j-client/src/test/resources/json/updateAuthorizationResponse.json index 543f0b54..54bec07b 100644 --- a/acme4j-client/src/test/resources/json/updateAuthorizationResponse.json +++ b/acme4j-client/src/test/resources/json/updateAuthorizationResponse.json @@ -18,5 +18,6 @@ "uri": "https://example.com/authz/asdf/1", "token": "DGyRejmCefe7v4NfDGDKfA" } - ] + ], + "scope": "https://example.com/order/123" }