mirror of https://github.com/shred/acme4j
Move to Java 8
parent
e0e99850f2
commit
0ed0a9219f
|
@ -12,7 +12,7 @@ It is an independent open source implementation that is not affiliated with or e
|
||||||
|
|
||||||
* Supports ACME protocol up to [draft 02](https://tools.ietf.org/html/draft-ietf-acme-acme-02), with a few parts of [draft 03](https://tools.ietf.org/html/draft-ietf-acme-acme-03) and [draft 04](https://tools.ietf.org/html/draft-ietf-acme-acme-04)
|
* Supports ACME protocol up to [draft 02](https://tools.ietf.org/html/draft-ietf-acme-acme-02), with a few parts of [draft 03](https://tools.ietf.org/html/draft-ietf-acme-acme-03) and [draft 04](https://tools.ietf.org/html/draft-ietf-acme-acme-04)
|
||||||
* Easy to use Java API
|
* Easy to use Java API
|
||||||
* Requires JRE 7 or higher
|
* Requires JRE 8 or higher
|
||||||
* Built with maven, packages available at [Maven Central](http://search.maven.org/#search|ga|1|g%3A%22org.shredzone.acme4j%22)
|
* Built with maven, packages available at [Maven Central](http://search.maven.org/#search|ga|1|g%3A%22org.shredzone.acme4j%22)
|
||||||
* Small, only requires [jose4j](https://bitbucket.org/b_c/jose4j/wiki/Home) and [slf4j](http://www.slf4j.org/) as dependencies
|
* Small, only requires [jose4j](https://bitbucket.org/b_c/jose4j/wiki/Home) and [slf4j](http://www.slf4j.org/) as dependencies
|
||||||
* Extensive unit tests
|
* Extensive unit tests
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
*/
|
*/
|
||||||
package org.shredzone.acme4j;
|
package org.shredzone.acme4j;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration of revocation reasons.
|
* Enumeration of revocation reasons.
|
||||||
*
|
*
|
||||||
|
@ -53,12 +55,10 @@ public enum RevocationReason {
|
||||||
* @return Matching {@link RevocationReason}, or {@code null} if not known
|
* @return Matching {@link RevocationReason}, or {@code null} if not known
|
||||||
*/
|
*/
|
||||||
public static RevocationReason code(int reasonCode) {
|
public static RevocationReason code(int reasonCode) {
|
||||||
for (RevocationReason rr : values()) {
|
return Arrays.stream(values())
|
||||||
if (rr.reasonCode == reasonCode) {
|
.filter(rr -> rr.reasonCode == reasonCode)
|
||||||
return rr;
|
.findFirst()
|
||||||
}
|
.orElse(null);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
*/
|
*/
|
||||||
package org.shredzone.acme4j;
|
package org.shredzone.acme4j;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status codes of challenges and authorizations.
|
* Status codes of challenges and authorizations.
|
||||||
*/
|
*/
|
||||||
|
@ -30,12 +32,10 @@ public enum Status {
|
||||||
*/
|
*/
|
||||||
public static Status parse(String str) {
|
public static Status parse(String str) {
|
||||||
String check = str.toUpperCase();
|
String check = str.toUpperCase();
|
||||||
for (Status s : values()) {
|
return Arrays.stream(values())
|
||||||
if (s.name().equals(check)) {
|
.filter(s -> s.name().equals(check))
|
||||||
return s;
|
.findFirst()
|
||||||
}
|
.orElse(Status.UNKNOWN);
|
||||||
}
|
|
||||||
return Status.UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,11 +28,12 @@ import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.OptionalInt;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -179,10 +180,9 @@ public class DefaultConnection implements Connection {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int rc = conn.getResponseCode();
|
int rc = conn.getResponseCode();
|
||||||
for (int s : httpStatus) {
|
OptionalInt match = Arrays.stream(httpStatus).filter(s -> s == rc).findFirst();
|
||||||
if (s == rc) {
|
if (match.isPresent()) {
|
||||||
return rc;
|
return match.getAsInt();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!"application/problem+json".equals(conn.getHeaderField(CONTENT_TYPE_HEADER))) {
|
if (!"application/problem+json".equals(conn.getHeaderField(CONTENT_TYPE_HEADER))) {
|
||||||
|
@ -420,11 +420,11 @@ public class DefaultConnection implements Connection {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
|
conn.getHeaderFields().forEach((key, headers) ->
|
||||||
for (String value : entry.getValue()) {
|
headers.forEach(value ->
|
||||||
LOG.debug("HEADER {}: {}", entry.getKey(), value);
|
LOG.debug("HEADER {}: {}", key, value)
|
||||||
}
|
)
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
*/
|
*/
|
||||||
package org.shredzone.acme4j.util;
|
package org.shredzone.acme4j.util;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
import static org.shredzone.acme4j.util.AcmeUtils.parseTimestamp;
|
import static org.shredzone.acme4j.util.AcmeUtils.parseTimestamp;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -82,20 +83,12 @@ public final class JSON implements Serializable {
|
||||||
* @return {@link JSON} of the read content.
|
* @return {@link JSON} of the read content.
|
||||||
*/
|
*/
|
||||||
public static JSON parse(InputStream in) throws IOException {
|
public static JSON parse(InputStream in) throws IOException {
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"))) {
|
||||||
String line = reader.readLine();
|
String json = reader.lines().map(String::trim).collect(joining());
|
||||||
|
return parse(json);
|
||||||
while (line != null) {
|
|
||||||
sb.append(line.trim());
|
|
||||||
line = reader.readLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses JSON from a String.
|
* Parses JSON from a String.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
*/
|
*/
|
||||||
package org.shredzone.acme4j.util;
|
package org.shredzone.acme4j.util;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
import static org.shredzone.acme4j.util.AcmeUtils.toAce;
|
import static org.shredzone.acme4j.util.AcmeUtils.toAce;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -23,6 +24,7 @@ import java.security.KeyPair;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.interfaces.ECKey;
|
import java.security.interfaces.ECKey;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -86,9 +88,7 @@ public class CSRBuilder {
|
||||||
* Collection of domain names to add
|
* Collection of domain names to add
|
||||||
*/
|
*/
|
||||||
public void addDomains(Collection<String> domains) {
|
public void addDomains(Collection<String> domains) {
|
||||||
for (String domain : domains) {
|
domains.forEach(this::addDomain);
|
||||||
addDomain(domain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,9 +100,7 @@ public class CSRBuilder {
|
||||||
* Domain names to add
|
* Domain names to add
|
||||||
*/
|
*/
|
||||||
public void addDomains(String... domains) {
|
public void addDomains(String... domains) {
|
||||||
for (String domain : domains) {
|
Arrays.stream(domains).forEach(this::addDomain);
|
||||||
addDomain(domain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,9 +235,7 @@ public class CSRBuilder {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(namebuilder.build());
|
sb.append(namebuilder.build());
|
||||||
for (String domain : namelist) {
|
sb.append(namelist.stream().collect(joining(",DNS=", ",DNS=", "")));
|
||||||
sb.append(",DNS=").append(domain);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -70,8 +70,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.8</source>
|
||||||
<target>1.7</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
Loading…
Reference in New Issue