mirror of https://github.com/shred/acme4j
Code style fixes
parent
8819558b3f
commit
fdc05ba70b
|
@ -27,7 +27,7 @@ public class Problem implements Serializable {
|
|||
private static final long serialVersionUID = -8418248862966754214L;
|
||||
|
||||
private final URI baseUri;
|
||||
private final JSON problem;
|
||||
private final JSON problemJson;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Problem} object.
|
||||
|
@ -38,7 +38,7 @@ public class Problem implements Serializable {
|
|||
* Document's base {@link URI} to resolve relative URIs against
|
||||
*/
|
||||
public Problem(JSON problem, URI baseUri) {
|
||||
this.problem = problem;
|
||||
this.problemJson = problem;
|
||||
this.baseUri = baseUri;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class Problem implements Serializable {
|
|||
* Returns the problem type. It is always an absolute URI.
|
||||
*/
|
||||
public URI getType() {
|
||||
String type = problem.get("type").asString();
|
||||
String type = problemJson.get("type").asString();
|
||||
return type != null ? baseUri.resolve(type) : null;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class Problem implements Serializable {
|
|||
* Returns a human-readable description of the problem.
|
||||
*/
|
||||
public String getDetail() {
|
||||
return problem.get("detail").asString();
|
||||
return problemJson.get("detail").asString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,15 +62,17 @@ public class Problem implements Serializable {
|
|||
* an absolute URI.
|
||||
*/
|
||||
public URI getInstance() {
|
||||
String instance = problem.get("instance").asString();
|
||||
String instance = problemJson.get("instance").asString();
|
||||
return instance != null ? baseUri.resolve(instance) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the problem as {@link JSON} object, to access other fields.
|
||||
*
|
||||
* @return Problem as {@link JSON} object
|
||||
*/
|
||||
public JSON asJSON() {
|
||||
return problem;
|
||||
return problemJson;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +80,7 @@ public class Problem implements Serializable {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return problem.toString();
|
||||
return problemJson.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public final class Pebble {
|
||||
|
||||
private static final boolean PEBBLE = Boolean.getBoolean("pebble");
|
||||
private static final boolean PEBBLE_PROPERTY = Boolean.getBoolean("pebble");
|
||||
|
||||
static {
|
||||
if (PEBBLE) {
|
||||
if (PEBBLE_PROPERTY) {
|
||||
LoggerFactory.getLogger(Pebble.class).warn("Pebble workarounds enabled!");
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ public final class Pebble {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} to enable Pebble workarounds, {@code false} for strict
|
||||
* ACME specifications.
|
||||
* @return {@code true} to enable Pebble workarounds, {@code false} for strict ACME
|
||||
* specifications.
|
||||
*/
|
||||
public static boolean workaround() {
|
||||
return PEBBLE;
|
||||
return PEBBLE_PROPERTY;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,6 +53,23 @@ public class PebbleAcmeProvider extends AbstractAcmeProvider {
|
|||
URL baseUrl = new URL("http://localhost:14000/dir");
|
||||
|
||||
if (path != null && !path.isEmpty() && !"/".equals(path)) {
|
||||
baseUrl = parsePath(path);
|
||||
}
|
||||
|
||||
return baseUrl;
|
||||
} catch (MalformedURLException ex) {
|
||||
throw new IllegalArgumentException("Bad server URI " + serverUri, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the server URI path and returns the server's base URL.
|
||||
*
|
||||
* @param path
|
||||
* server URI path
|
||||
* @return URL of the server's base
|
||||
*/
|
||||
private URL parsePath(String path) throws MalformedURLException {
|
||||
Matcher m = HOST_PATTERN.matcher(path);
|
||||
if (m.matches()) {
|
||||
String host = m.group(1);
|
||||
|
@ -60,18 +77,12 @@ public class PebbleAcmeProvider extends AbstractAcmeProvider {
|
|||
if (m.group(2) != null) {
|
||||
port = Integer.parseInt(m.group(2));
|
||||
}
|
||||
baseUrl = new URL("http", host, port, "/dir");
|
||||
return new URL("http", host, port, "/dir");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid Pebble host/port: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
return baseUrl;
|
||||
} catch (MalformedURLException ex) {
|
||||
throw new IllegalArgumentException("Bad server URI " + serverUri, ex);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO PEBBLE: new-reg
|
||||
// https://github.com/letsencrypt/pebble/pull/24
|
||||
@Override
|
||||
|
|
|
@ -427,7 +427,7 @@ public final class JSON implements Serializable {
|
|||
*/
|
||||
public byte[] asBinary() {
|
||||
if (val == null) {
|
||||
return null;
|
||||
return null; //NOSONAR: we want to return null here
|
||||
}
|
||||
|
||||
return AcmeUtils.base64UrlDecode(val.toString());
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
<name>acme4j Example</name>
|
||||
<description>Example for using acme4j</description>
|
||||
|
||||
<properties>
|
||||
<sonar.exclusions>src/main/java/org/shredzone/acme4j/**</sonar.exclusions>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
<properties>
|
||||
<skipITs>true</skipITs>
|
||||
<sonar.coverage.exclusions>src/main/java/org/shredzone/acme4j/**</sonar.coverage.exclusions>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
|
|
@ -39,6 +39,7 @@ public class HttpServer {
|
|||
|
||||
private static final String TOKEN_PATH = "/.well-known/acme-challenge/";
|
||||
private static final Pattern TOKEN_PATTERN = Pattern.compile("^" + Pattern.quote(TOKEN_PATH) + "([^/]+)$");
|
||||
private static final String TYPE_TEXT_PLAIN = "text/plain";
|
||||
|
||||
private final Map<String, String> tokenMap = synchronizedMap(new HashMap<>());
|
||||
private NanoHTTPD server;
|
||||
|
@ -84,7 +85,7 @@ public class HttpServer {
|
|||
|
||||
Matcher m = TOKEN_PATTERN.matcher(path);
|
||||
if (!m.matches()) {
|
||||
return newFixedLengthResponse(Status.NOT_FOUND, "text/plain", "not found: "+ path + "\n");
|
||||
return newFixedLengthResponse(Status.NOT_FOUND, TYPE_TEXT_PLAIN, "not found: "+ path + "\n");
|
||||
}
|
||||
|
||||
String token = m.group(1);
|
||||
|
@ -92,11 +93,11 @@ public class HttpServer {
|
|||
|
||||
if (content == null) {
|
||||
LOG.warn("http-01: unknown token " + token);
|
||||
return newFixedLengthResponse(Status.NOT_FOUND, "text/plain", "unknown token: "+ token + "\n");
|
||||
return newFixedLengthResponse(Status.NOT_FOUND, TYPE_TEXT_PLAIN, "unknown token: "+ token + "\n");
|
||||
}
|
||||
|
||||
LOG.info("http-01: " + token + " -> " + content);
|
||||
return newFixedLengthResponse(Status.OK, "text/plain", content);
|
||||
return newFixedLengthResponse(Status.OK, TYPE_TEXT_PLAIN, content);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ public class TlsSniServer {
|
|||
LOG.info("tls-sni: {}", domainsToString(cert));
|
||||
|
||||
try (InputStream in = sslSocket.getInputStream()) {
|
||||
while (in.read() >= 0);
|
||||
while (in.read() >= 0); //NOSONAR: intentional empty statement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue