diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/RegistrationBuilder.java b/acme4j-client/src/main/java/org/shredzone/acme4j/RegistrationBuilder.java index 91744f47..bb15526b 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/RegistrationBuilder.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/RegistrationBuilder.java @@ -21,7 +21,6 @@ import java.util.List; import org.shredzone.acme4j.connector.Connection; import org.shredzone.acme4j.connector.Resource; -import org.shredzone.acme4j.exception.AcmeConflictException; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.util.JSONBuilder; import org.slf4j.Logger; @@ -80,10 +79,6 @@ public class RegistrationBuilder { * @param session * {@link Session} to be used for registration * @return {@link Registration} referring to the new account - * @throws AcmeConflictException - * if there is already an account for the connection's key pair. - * {@link AcmeConflictException#getLocation()} contains the registration's - * location URI. */ public Registration create(Session session) throws AcmeException { LOG.debug("create"); diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java index ef2fe83f..430d0aa4 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/DefaultConnection.java @@ -44,8 +44,6 @@ import org.jose4j.jwk.PublicJsonWebKey; import org.jose4j.jws.JsonWebSignature; import org.jose4j.lang.JoseException; import org.shredzone.acme4j.Session; -import org.shredzone.acme4j.exception.AcmeUserActionRequiredException; -import org.shredzone.acme4j.exception.AcmeConflictException; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeNetworkException; import org.shredzone.acme4j.exception.AcmeProtocolException; @@ -53,6 +51,7 @@ import org.shredzone.acme4j.exception.AcmeRateLimitExceededException; import org.shredzone.acme4j.exception.AcmeRetryAfterException; import org.shredzone.acme4j.exception.AcmeServerException; import org.shredzone.acme4j.exception.AcmeUnauthorizedException; +import org.shredzone.acme4j.exception.AcmeUserActionRequiredException; import org.shredzone.acme4j.provider.pebble.Pebble; import org.shredzone.acme4j.util.AcmeUtils; import org.shredzone.acme4j.util.JSON; @@ -238,13 +237,7 @@ public class DefaultConnection implements Connection { throw new AcmeException("HTTP " + rc + ": " + conn.getResponseMessage()); } - JSON json = readJsonResponse(); - - if (rc == HttpURLConnection.HTTP_CONFLICT) { - throw new AcmeConflictException(json.get("detail").asString(), getLocation()); - } - - throw createAcmeException(json); + throw createAcmeException(readJsonResponse()); } catch (IOException ex) { throw new AcmeNetworkException(ex); } diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeConflictException.java b/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeConflictException.java deleted file mode 100644 index b276441d..00000000 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeConflictException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * acme4j - Java ACME client - * - * Copyright (C) 2015 Richard "Shred" Körber - * http://acme4j.shredzone.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ -package org.shredzone.acme4j.exception; - -import java.net.URL; -import java.util.Objects; - -/** - * An exception that is thrown when there is a conflict with the request. For example, - * this exception is thrown when a registration already exists. - */ -public class AcmeConflictException extends AcmeException { - private static final long serialVersionUID = 7454201988845449591L; - - private final URL location; - - /** - * Creates a new {@link AcmeConflictException}. - * - * @param msg - * Details about the conflicting resource - * @param location - * {@link URL} of the conflicting resource - */ - public AcmeConflictException(String msg, URL location) { - super(msg); - this.location = Objects.requireNonNull(location, "location"); - } - - /** - * Location of the conflicting resource. - */ - public URL getLocation() { - return location; - } - -} diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/util/AcmeUtils.java b/acme4j-client/src/main/java/org/shredzone/acme4j/util/AcmeUtils.java index badf4b58..df2c8e17 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/util/AcmeUtils.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/util/AcmeUtils.java @@ -221,7 +221,8 @@ public final class AcmeUtils { /** * Strips the acme error prefix from the error string. *

- * For example, for "urn:ietf:params:acme:error:conflict", "conflict" is returned. + * For example, for "urn:ietf:params:acme:error:unauthorized", "unauthorized" is + * returned. * * @param type * Error type to strip the prefix from. {@code null} is safe. diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeConflictExceptionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeConflictExceptionTest.java deleted file mode 100644 index 6e647b27..00000000 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/exception/AcmeConflictExceptionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * acme4j - Java ACME client - * - * Copyright (C) 2016 Richard "Shred" Körber - * http://acme4j.shredzone.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ -package org.shredzone.acme4j.exception; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.junit.Test; - -/** - * Unit tests for {@link AcmeConflictException}. - */ -public class AcmeConflictExceptionTest { - - @Test - public void testAcmeConflictException() throws MalformedURLException { - String msg = "Account already exists"; - URL locationUrl = new URL("http://example.com/location/123"); - - AcmeConflictException ex - = new AcmeConflictException(msg, locationUrl); - - assertThat(ex.getMessage(), is(msg)); - assertThat(ex.getLocation(), is(locationUrl)); - } - -} diff --git a/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java b/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java index ff1a78e4..fb03884b 100644 --- a/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java +++ b/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java @@ -33,7 +33,6 @@ import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.challenge.Dns01Challenge; import org.shredzone.acme4j.challenge.Http01Challenge; import org.shredzone.acme4j.challenge.TlsSni02Challenge; -import org.shredzone.acme4j.exception.AcmeConflictException; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.util.AcmeUtils; import org.shredzone.acme4j.util.CSRBuilder; @@ -190,19 +189,8 @@ public class ClientTest { acceptAgreement(tos); } - Registration reg; - - try { - // Try to create a new Registration. - reg = new RegistrationBuilder().agreeToTermsOfService().create(session); - LOG.info("Registered a new user, URI: " + reg.getLocation()); - - } catch (AcmeConflictException ex) { - // The Key Pair is already registered. getLocation() contains the - // URL of the existing registration's location. Bind it to the session. - reg = Registration.bind(session, ex.getLocation()); - LOG.info("Account does already exist, URI: " + reg.getLocation(), ex); - } + Registration reg = new RegistrationBuilder().agreeToTermsOfService().create(session); + LOG.info("Registered a new user, URI: " + reg.getLocation()); return reg; } diff --git a/src/site/markdown/usage/register.md b/src/site/markdown/usage/register.md index 6cf2d5e7..9fa5ef0b 100644 --- a/src/site/markdown/usage/register.md +++ b/src/site/markdown/usage/register.md @@ -14,19 +14,6 @@ Registration registration = builder.create(session); URL accountLocationUrl = registration.getLocation(); ``` -`create()` will fail and throw an `AcmeConflictException` if your key was already registered with the CA. The `AcmeConflictException` contains the location of the registration. This may be helpful if you forgot your account URL and need to recover it. - -The following example will create a new `Registration` and restore an existing `Registration`. - -```java -Registration registration; -try { - registration = new RegistrationBuilder().agreeToTermsOfService().create(session); -} catch (AcmeConflictException ex) { - registration = Registration.bind(session, ex.getLocation()); -} -``` - ## Update your Registration At some point, you may want to update your registration. For example your contact address might have changed. To do so, invoke `Registration.modify()`, perform the changes, and invoke `commit()` to make them permanent.