mirror of https://github.com/shred/acme4j
Bind on RegistrationBuilder.create
parent
434b349d20
commit
13c2ba9169
|
@ -34,29 +34,8 @@ import org.slf4j.LoggerFactory;
|
||||||
public class RegistrationBuilder {
|
public class RegistrationBuilder {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(RegistrationBuilder.class);
|
private static final Logger LOG = LoggerFactory.getLogger(RegistrationBuilder.class);
|
||||||
|
|
||||||
private final Session session;
|
|
||||||
private List<URI> contacts = new ArrayList<>();
|
private List<URI> contacts = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of {@link RegistrationBuilder} and binds it to the
|
|
||||||
* {@link Session}.
|
|
||||||
*
|
|
||||||
* @param session
|
|
||||||
* {@link Session} to be used
|
|
||||||
*/
|
|
||||||
public static RegistrationBuilder bind(Session session) {
|
|
||||||
return new RegistrationBuilder(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link RegistrationBuilder}.
|
|
||||||
*
|
|
||||||
* @param session {@link Session} to bind to
|
|
||||||
*/
|
|
||||||
private RegistrationBuilder(Session session) {
|
|
||||||
this.session = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a contact URI to the list of contacts.
|
* Add a contact URI to the list of contacts.
|
||||||
*
|
*
|
||||||
|
@ -86,13 +65,15 @@ public class RegistrationBuilder {
|
||||||
/**
|
/**
|
||||||
* Creates a new account.
|
* Creates a new account.
|
||||||
*
|
*
|
||||||
|
* @param session
|
||||||
|
* {@link Session} to be used for registration
|
||||||
* @return {@link Registration} referring to the new account
|
* @return {@link Registration} referring to the new account
|
||||||
* @throws AcmeConflictException
|
* @throws AcmeConflictException
|
||||||
* if there is already an account for the connection's key pair.
|
* if there is already an account for the connection's key pair.
|
||||||
* {@link AcmeConflictException#getLocation()} contains the registration's
|
* {@link AcmeConflictException#getLocation()} contains the registration's
|
||||||
* location URI.
|
* location URI.
|
||||||
*/
|
*/
|
||||||
public Registration create() throws AcmeException {
|
public Registration create(Session session) throws AcmeException {
|
||||||
LOG.debug("create");
|
LOG.debug("create");
|
||||||
|
|
||||||
try (Connection conn = session.provider().connect()) {
|
try (Connection conn = session.provider().connect()) {
|
||||||
|
|
|
@ -65,10 +65,10 @@ public class RegistrationBuilderTest {
|
||||||
|
|
||||||
provider.putTestResource(Resource.NEW_REG, resourceUri);
|
provider.putTestResource(Resource.NEW_REG, resourceUri);
|
||||||
|
|
||||||
RegistrationBuilder builder = RegistrationBuilder.bind(provider.createSession());
|
RegistrationBuilder builder = new RegistrationBuilder();
|
||||||
builder.addContact("mailto:foo@example.com");
|
builder.addContact("mailto:foo@example.com");
|
||||||
|
|
||||||
Registration registration = builder.create();
|
Registration registration = builder.create(provider.createSession());
|
||||||
|
|
||||||
assertThat(registration.getLocation(), is(locationUri));
|
assertThat(registration.getLocation(), is(locationUri));
|
||||||
assertThat(registration.getAgreement(), is(agreementUri));
|
assertThat(registration.getAgreement(), is(agreementUri));
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class ClientTest {
|
||||||
// Register a new user
|
// Register a new user
|
||||||
Registration reg = null;
|
Registration reg = null;
|
||||||
try {
|
try {
|
||||||
reg = RegistrationBuilder.bind(session).create();
|
reg = new RegistrationBuilder().create(session);
|
||||||
LOG.info("Registered a new user, URI: " + reg.getLocation());
|
LOG.info("Registered a new user, URI: " + reg.getLocation());
|
||||||
} catch (AcmeConflictException ex) {
|
} catch (AcmeConflictException ex) {
|
||||||
reg = Registration.bind(session, ex.getLocation());
|
reg = Registration.bind(session, ex.getLocation());
|
||||||
|
|
|
@ -28,7 +28,7 @@ You must know your account's location URI. Use a `RegistrationBuilder` if you do
|
||||||
Registration registration;
|
Registration registration;
|
||||||
try {
|
try {
|
||||||
// Try to create a new Registration...
|
// Try to create a new Registration...
|
||||||
registration = RegistrationBuilder.bind(session).create();
|
registration = new RegistrationBuilder().create(session);
|
||||||
} catch (AcmeConflictException ex) {
|
} catch (AcmeConflictException ex) {
|
||||||
// It failed because your key was already registered.
|
// It failed because your key was already registered.
|
||||||
// Retrieve the registration location URI from the exception.
|
// Retrieve the registration location URI from the exception.
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
If it is the first time you connect to the ACME server, you need to register your account key.
|
If it is the first time you connect to the ACME server, you need to register your account key.
|
||||||
|
|
||||||
To do so, bind a `RegistrationBuilder`, optionally add some contact information, then invoke `create()`. If the account was successfully created, you will get a `Registration` object in return. Invoking its `getLocation()` method will return the location URI of your account. You should store it somewhere, because you will need it later. Unlike your key pair, the location is a public information that does not need security precautions.
|
To do so, create a `RegistrationBuilder`, optionally add some contact information, then invoke `create()`. If the account was successfully created, you will get a `Registration` object in return. Invoking its `getLocation()` method will return the location URI of your account. You should store it somewhere, because you will need it later. Unlike your key pair, the location is a public information that does not need security precautions.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
RegistrationBuilder builder = RegistrationBuilder.bind(session);
|
RegistrationBuilder builder = new RegistrationBuilder();
|
||||||
builder.addContact("mailto:acme@example.com");
|
builder.addContact("mailto:acme@example.com");
|
||||||
|
|
||||||
Registration registration = builder.create();
|
Registration registration = builder.create(session);
|
||||||
|
|
||||||
URI accountLocationUri = registration.getLocation();
|
URI accountLocationUri = registration.getLocation();
|
||||||
```
|
```
|
||||||
|
@ -20,7 +20,7 @@ The following example will create a new `Registration` and restore an existing `
|
||||||
```java
|
```java
|
||||||
Registration registration;
|
Registration registration;
|
||||||
try {
|
try {
|
||||||
registration = RegistrationBuilder.bind(session).create();
|
registration = new RegistrationBuilder().create(session);
|
||||||
} catch (AcmeConflictException ex) {
|
} catch (AcmeConflictException ex) {
|
||||||
registration = Registration.bind(session, ex.getLocation());
|
registration = Registration.bind(session, ex.getLocation());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue