mirror of https://github.com/shred/acme4j
Remove unused AcmeConflictException
parent
e748df364d
commit
94ee501811
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -221,7 +221,8 @@ public final class AcmeUtils {
|
|||
/**
|
||||
* Strips the acme error prefix from the error string.
|
||||
* <p>
|
||||
* 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.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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,20 +189,9 @@ public class ClientTest {
|
|||
acceptAgreement(tos);
|
||||
}
|
||||
|
||||
Registration reg;
|
||||
|
||||
try {
|
||||
// Try to create a new Registration.
|
||||
reg = new RegistrationBuilder().agreeToTermsOfService().create(session);
|
||||
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);
|
||||
}
|
||||
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue