mirror of https://github.com/shred/acme4j
Also accept 'urn:ietf:params:acme:error' error responses
parent
b8bfc5fa0f
commit
19787f4c00
|
@ -25,7 +25,8 @@ public class AcmeRateLimitExceededException extends AcmeServerException {
|
||||||
* Creates a new {@link AcmeRateLimitExceededException}.
|
* Creates a new {@link AcmeRateLimitExceededException}.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* System readable error type (here {@code "urn:acme:error:rateLimited"})
|
* System readable error type (here
|
||||||
|
* {@code "urn:ietf:params:acme:error:rateLimited"})
|
||||||
* @param detail
|
* @param detail
|
||||||
* Human readable error message
|
* Human readable error message
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,7 +22,8 @@ package org.shredzone.acme4j.exception;
|
||||||
public class AcmeServerException extends AcmeException {
|
public class AcmeServerException extends AcmeException {
|
||||||
private static final long serialVersionUID = 5971622508467042792L;
|
private static final long serialVersionUID = 5971622508467042792L;
|
||||||
|
|
||||||
private static final String ACME_ERROR_PREFIX = "urn:acme:error:";
|
private static final String ACME_ERROR_PREFIX = "urn:ietf:params:acme:error:";
|
||||||
|
private static final String ACME_ERROR_PREFIX_DEPRECATED = "urn:acme:error:";
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
@ -30,7 +31,8 @@ public class AcmeServerException extends AcmeException {
|
||||||
* Creates a new {@link AcmeServerException}.
|
* Creates a new {@link AcmeServerException}.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* System readable error type (e.g. {@code "urn:acme:error:malformed"})
|
* System readable error type (e.g.
|
||||||
|
* {@code "urn:ietf:params:acme:error:malformed"})
|
||||||
* @param detail
|
* @param detail
|
||||||
* Human readable error message
|
* Human readable error message
|
||||||
*/
|
*/
|
||||||
|
@ -51,13 +53,16 @@ public class AcmeServerException extends AcmeException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ACME error type. This is the last part of the type URN, e.g.
|
* Returns the ACME error type. This is the last part of the type URN, e.g.
|
||||||
* {@code "malformed"} on {@code "urn:acme:error:malformed"}.
|
* {@code "malformed"} on {@code "urn:ietf:params:acme:error:malformed"}.
|
||||||
*
|
*
|
||||||
* @return ACME error type, or {@code null} if this is not an {@code "urn:acme:error"}
|
* @return ACME error type, or {@code null} if this is not an
|
||||||
|
* {@code "urn:ietf:params:acme:error"}
|
||||||
*/
|
*/
|
||||||
public String getAcmeErrorType() {
|
public String getAcmeErrorType() {
|
||||||
if (type.startsWith(ACME_ERROR_PREFIX)) {
|
if (type.startsWith(ACME_ERROR_PREFIX)) {
|
||||||
return type.substring(ACME_ERROR_PREFIX.length());
|
return type.substring(ACME_ERROR_PREFIX.length());
|
||||||
|
} else if (type.startsWith(ACME_ERROR_PREFIX_DEPRECATED)) {
|
||||||
|
return type.substring(ACME_ERROR_PREFIX_DEPRECATED.length());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ public class AcmeUnauthorizedException extends AcmeServerException {
|
||||||
* Creates a new {@link AcmeUnauthorizedException}.
|
* Creates a new {@link AcmeUnauthorizedException}.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* System readable error type (here {@code "urn:acme:error:unauthorized"})
|
* System readable error type (here
|
||||||
|
* {@code "urn:ietf:params:acme:error:unauthorized"})
|
||||||
* @param detail
|
* @param detail
|
||||||
* Human readable error message
|
* Human readable error message
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,8 +42,8 @@ import org.shredzone.acme4j.connector.HttpConnector;
|
||||||
import org.shredzone.acme4j.connector.Resource;
|
import org.shredzone.acme4j.connector.Resource;
|
||||||
import org.shredzone.acme4j.connector.Session;
|
import org.shredzone.acme4j.connector.Session;
|
||||||
import org.shredzone.acme4j.exception.AcmeException;
|
import org.shredzone.acme4j.exception.AcmeException;
|
||||||
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException;
|
|
||||||
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
import org.shredzone.acme4j.exception.AcmeProtocolException;
|
||||||
|
import org.shredzone.acme4j.exception.AcmeRateLimitExceededException;
|
||||||
import org.shredzone.acme4j.exception.AcmeServerException;
|
import org.shredzone.acme4j.exception.AcmeServerException;
|
||||||
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
|
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
|
||||||
import org.shredzone.acme4j.util.ClaimBuilder;
|
import org.shredzone.acme4j.util.ClaimBuilder;
|
||||||
|
@ -322,9 +322,11 @@ public class DefaultConnection implements Connection {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "urn:acme:error:unauthorized":
|
case "urn:acme:error:unauthorized":
|
||||||
|
case "urn:ietf:params:acme:error:unauthorized":
|
||||||
throw new AcmeUnauthorizedException(type, detail);
|
throw new AcmeUnauthorizedException(type, detail);
|
||||||
|
|
||||||
case "urn:acme:error:rateLimited":
|
case "urn:acme:error:rateLimited":
|
||||||
|
case "urn:ietf:params:acme:error:rateLimited":
|
||||||
throw new AcmeRateLimitExceededException(type, detail);
|
throw new AcmeRateLimitExceededException(type, detail);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class DefaultConnectionTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testThrowException() throws Exception {
|
public void testThrowException() throws Exception {
|
||||||
String jsonData = "{\"type\":\"urn:acme:error:unauthorized\",\"detail\":\"Invalid response: 404\"}";
|
String jsonData = "{\"type\":\"urn:ietf:params:acme:error:unauthorized\",\"detail\":\"Invalid response: 404\"}";
|
||||||
|
|
||||||
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/problem+json");
|
when(mockUrlConnection.getHeaderField("Content-Type")).thenReturn("application/problem+json");
|
||||||
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
|
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_FORBIDDEN);
|
||||||
|
@ -205,7 +205,7 @@ public class DefaultConnectionTest {
|
||||||
conn.throwAcmeException();
|
conn.throwAcmeException();
|
||||||
fail("Expected to fail");
|
fail("Expected to fail");
|
||||||
} catch (AcmeServerException ex) {
|
} catch (AcmeServerException ex) {
|
||||||
assertThat(ex.getType(), is("urn:acme:error:unauthorized"));
|
assertThat(ex.getType(), is("urn:ietf:params:acme:error:unauthorized"));
|
||||||
assertThat(ex.getMessage(), is("Invalid response: 404"));
|
assertThat(ex.getMessage(), is("Invalid response: 404"));
|
||||||
assertThat(ex.getAcmeErrorType(), is("unauthorized"));
|
assertThat(ex.getAcmeErrorType(), is("unauthorized"));
|
||||||
} catch (AcmeException ex) {
|
} catch (AcmeException ex) {
|
||||||
|
|
Loading…
Reference in New Issue