From 5cbb45abec31d6d8cc54bf82ff11477c1841536b Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 11 Nov 2024 14:35:06 -0500 Subject: [PATCH] Allow ManagedWebAccess to fetch specific server types for auth --- .../convertors/analytics/PackageVisitor.java | 11 +++----- .../hl7/fhir/convertors/misc/CKMImporter.java | 3 ++- .../fhir/convertors/misc/ICD11Generator.java | 3 ++- .../fhir/r4/conformance/ProfileComparer.java | 9 ++----- .../TerminologyCacheManager.java | 5 ++-- .../hl7/fhir/r5/elementmodel/SHLParser.java | 4 +-- .../TerminologyCacheManager.java | 5 ++-- .../http/ManagedFhirWebAccessor.java | 5 ++-- .../fhir/utilities/http/ManagedWebAccess.java | 26 +++++++++---------- .../utilities/http/ManagedWebAccessUtils.java | 12 +++++---- .../utilities/http/ManagedWebAccessor.java | 12 ++++----- .../http/ManagedWebAccessorBase.java | 6 ++--- .../utilities/json/JsonTrackingParser.java | 5 ++-- .../utilities/json/parser/JsonParser.java | 3 ++- .../npm/FilesystemPackageCacheManager.java | 7 ++--- .../hl7/fhir/utilities/npm/NpmPackage.java | 12 ++------- .../hl7/fhir/utilities/npm/PackageClient.java | 9 +++---- .../hl7/fhir/utilities/npm/PackageServer.java | 2 +- .../utilities/settings/ServerDetailsPOJO.java | 18 +++++++++---- .../http/ManagedWebAccessAuthTests.java | 3 --- .../utilities/settings/FhirSettingsTests.java | 2 +- .../resources/settings/settings-example.json | 2 +- .../org/hl7/fhir/validation/IgLoader.java | 9 ++++--- .../java/org/hl7/fhir/validation/Scanner.java | 10 ++----- .../hl7/fhir/validation/ValidationEngine.java | 8 ++---- .../validation/cli/utils/ProfileLoader.java | 3 ++- .../hl7/fhir/validation/ipa/IPAValidator.java | 3 ++- .../validation/tests/ValidationTests.java | 13 ++-------- 28 files changed, 95 insertions(+), 115 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java index c8263ed960..232db1642a 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java @@ -3,12 +3,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import javax.xml.parsers.ParserConfigurationException; @@ -241,7 +236,7 @@ private void processCurrentPackage(String url, String pid, Set cpidSet, File co = ManagedFileAccess.file(Utilities.path(cache, pid+"."+manifest.asString("date")+".tgz")); if (!co.exists()) { - HTTPResult res = ManagedWebAccess.get("web", repo+"/package.tgz?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), repo+"/package.tgz?nocache=" + System.currentTimeMillis()); res.checkThrowException(); TextFile.bytesToFile(res.getContent(), co); } @@ -338,7 +333,7 @@ private void processFeed(Set list, String str) throws IOException, Parse System.out.println("Feed "+str); try { - HTTPResult res = ManagedWebAccess.get("web", str+"?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), str+"?nocache=" + System.currentTimeMillis()); res.checkThrowException(); Document xml = XMLUtil.parseToDom(res.getContent()); for (Element channel : XMLUtil.getNamedChildren(xml.getDocumentElement(), "channel")) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/CKMImporter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/CKMImporter.java index e6581f81e4..7aeddc01dc 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/CKMImporter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/CKMImporter.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.xml.parsers.DocumentBuilder; @@ -126,7 +127,7 @@ private void processArchetype(String id) throws Exception { private Document loadXml(String address) throws Exception { - HTTPResult res = ManagedWebAccess.get("web", address, "application/xml"); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), address, "application/xml"); res.checkThrowException(); InputStream xml = new ByteArrayInputStream(res.getContent()); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ICD11Generator.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ICD11Generator.java index 564f882b72..78713b0991 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ICD11Generator.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ICD11Generator.java @@ -1,6 +1,7 @@ package org.hl7.fhir.convertors.misc; import java.io.IOException; +import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -394,7 +395,7 @@ private CodeSystem makeEntityCodeSystem() { private JsonObject fetchJson(String source) throws IOException { - HTTPResult res = ManagedWebAccess.accessor("web").withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source,"application/json"); + HTTPResult res = ManagedWebAccess.accessor(Arrays.asList("web")).withHeader("API-Version", "v2").withHeader("Accept-Language", "en").get(source,"application/json"); res.checkThrowException(); return JsonParser.parseObject(res.getContent()); } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileComparer.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileComparer.java index 32b490c2e0..0f770bce44 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileComparer.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileComparer.java @@ -31,12 +31,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRFormatError; @@ -1384,7 +1379,7 @@ private String cachedFetch(String id, String source) throws IOException { if (f.exists()) return TextFile.fileToString(f); - HTTPResult res = ManagedWebAccess.get("web", source); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source); res.checkThrowException(); String result = TextFile.bytesToString(res.getContent()); TextFile.stringToFile(result, f); diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java index f06a762bff..2a211f7ba8 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.Date; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -79,7 +80,7 @@ private void fillCache(String source) throws IOException { try { System.out.println("Initialise terminology cache from " + source); - HTTPResult res = ManagedWebAccess.get("web", source + "?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source + "?nocache=" + System.currentTimeMillis()); res.checkThrowException(); unzip(new ByteArrayInputStream(res.getContent()), cacheFolder); } catch (Exception e) { @@ -148,7 +149,7 @@ public void commit(String token) throws IOException { String url = "https://tx.fhir.org/post/tx-cache/" + ghOrg + "/" + ghRepo + "/" + ghBranch + ".zip"; System.out.println("Sending tx-cache to " + url + " (" + Utilities.describeSize(bs.toByteArray().length) + ")"); - HTTPResult res = ManagedWebAccess.accessor("web") + HTTPResult res = ManagedWebAccess.accessor(Arrays.asList("web")) .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) .put(url, bs.toByteArray(), null, "application/zip"); if (res.getCode() >= 300) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java index ffdd2560ac..971e060901 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java @@ -287,7 +287,7 @@ private ValidatedFragment addNamedElement(List res, String na private HTTPResult fetchFile(String url, String ct) throws IOException { - HTTPResult res = ManagedWebAccess.get("web", url, ct); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), url, ct); res.checkThrowException(); return res; } @@ -299,7 +299,7 @@ private HTTPResult fetchManifest() throws IOException { JsonObject j = new JsonObject(); j.add("recipient", "FHIR Validator"); - HTTPResult res = ManagedWebAccess.post("web", url, org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(j), "application/json", "application/json"); + HTTPResult res = ManagedWebAccess.post(Arrays.asList("web"), url, org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(j), "application/json", "application/json"); res.checkThrowException(); return res; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java index 3cc569e68f..1428815f17 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.Date; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -78,7 +79,7 @@ private void fillCache(String source) throws IOException { try { System.out.println("Initialise terminology cache from "+source); - HTTPResult res = ManagedWebAccess.get("web", source+"?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source+"?nocache=" + System.currentTimeMillis()); res.checkThrowException(); unzip(new ByteArrayInputStream(res.getContent()), cacheFolder); } catch (Exception e) { @@ -148,7 +149,7 @@ public void commit(String token) throws IOException { // post it to String url = "https://tx.fhir.org/post/tx-cache/"+ghOrg+"/"+ghRepo+"/"+ghBranch+".zip"; System.out.println("Sending tx-cache to "+url+" ("+Utilities.describeSize(bs.toByteArray().length)+")"); - HTTPResult res = ManagedWebAccess.accessor("web") + HTTPResult res = ManagedWebAccess.accessor(Arrays.asList("web")) .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) .put(url, bs.toByteArray(), null, "application/zip"); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedFhirWebAccessor.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedFhirWebAccessor.java index 501ad5fa5a..cdc1989e1f 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedFhirWebAccessor.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedFhirWebAccessor.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -45,7 +46,7 @@ public ManagedFhirWebAccessor withLogger(ToolingClientLogger logger) { public ManagedFhirWebAccessor(String userAgent, List serverAuthDetails) { - super("fhir", userAgent, serverAuthDetails); + super(Arrays.asList("fhir"), userAgent, serverAuthDetails); this.timeout = 5000; this.timeoutUnit = TimeUnit.MILLISECONDS; } @@ -88,7 +89,7 @@ protected HTTPRequest requestWithManagedHeaders(HTTPRequest httpRequest) { } } } else { - ServerDetailsPOJO settings = ManagedWebAccessUtils.getServer(getMode(), httpRequest.getUrl().toString(), getServerAuthDetails()); + ServerDetailsPOJO settings = ManagedWebAccessUtils.getServer(getServerTypes(), httpRequest.getUrl().toString(), getServerAuthDetails()); if (settings != null) { switch (settings.getAuthenticationType()) { case "basic": diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java index df80a2dc3d..7d1bbc8b40 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java @@ -52,9 +52,9 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS public class ManagedWebAccess { public interface IWebAccessor { - HTTPResult get(String mode, String url, String accept, Map headers) throws IOException; - HTTPResult post(String mode, String url, byte[] bytes, String contentType, String accept, Map headers) throws IOException; - HTTPResult put(String mode, String url, byte[] bytes, String contentType, String accept, Map headers) throws IOException; + HTTPResult get(Iterable serverTypes, String url, String accept, Map headers) throws IOException; + HTTPResult post(Iterable serverTypes, String url, byte[] bytes, String contentType, String accept, Map headers) throws IOException; + HTTPResult put(Iterable serverTypes, String url, byte[] bytes, String contentType, String accept, Map headers) throws IOException; } public interface IFhirWebAccessor { @@ -104,28 +104,28 @@ public static void setUserAgent(String userAgent) { ManagedWebAccess.userAgent = userAgent; } - public static ManagedWebAccessor accessor(String mode) { - return new ManagedWebAccessor(mode, userAgent, serverAuthDetails); + public static ManagedWebAccessor accessor(Iterable serverTypes) { + return new ManagedWebAccessor(serverTypes, userAgent, serverAuthDetails); } public static ManagedFhirWebAccessor fhirAccessor() { return new ManagedFhirWebAccessor(userAgent, serverAuthDetails); } - public static HTTPResult get(String mode, String url) throws IOException { - return accessor(mode).get(url); + public static HTTPResult get(Iterable serverTypes, String url) throws IOException { + return accessor(serverTypes).get(url); } - public static HTTPResult get(String mode, String url, String accept) throws IOException { - return accessor(mode).get(url, accept); + public static HTTPResult get(Iterable serverTypes, String url, String accept) throws IOException { + return accessor(serverTypes).get(url, accept); } - public static HTTPResult post(String mode, String url, byte[] content, String contentType, String accept) throws IOException { - return accessor(mode).post(url, content, contentType, accept); + public static HTTPResult post(Iterable serverTypes, String url, byte[] content, String contentType, String accept) throws IOException { + return accessor(serverTypes).post(url, content, contentType, accept); } - public static HTTPResult put(String mode, String url, byte[] content, String contentType, String accept) throws IOException { - return accessor(mode).put(url, content, contentType, accept); + public static HTTPResult put(Iterable serverTypes, String url, byte[] content, String contentType, String accept) throws IOException { + return accessor(serverTypes).put(url, content, contentType, accept); } public static HTTPResult httpCall(HTTPRequest httpRequest) throws IOException { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessUtils.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessUtils.java index ba82a3c1c9..f377973141 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessUtils.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessUtils.java @@ -4,18 +4,20 @@ public class ManagedWebAccessUtils { - public static ServerDetailsPOJO getServer(String mode, String url, Iterable serverAuthDetails) { + public static ServerDetailsPOJO getServer(Iterable serverTypes, String url, Iterable serverAuthDetails) { if (serverAuthDetails != null) { - for (ServerDetailsPOJO t : serverAuthDetails) { - if (url.startsWith(t.getUrl()) && modesMatch(mode, t.getMode())) { - return t; + for (ServerDetailsPOJO serverDetails : serverAuthDetails) { + for (String serverType : serverTypes) { + if (url.startsWith(serverDetails.getUrl()) && typesMatch(serverType, serverDetails.getType())) { + return serverDetails; + } } } } return null; } - private static boolean modesMatch(String criteria, String value) { + private static boolean typesMatch(String criteria, String value) { return criteria == null || value == null || criteria.equals(value); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessor.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessor.java index e2b6d64391..10fdb5d1e5 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessor.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessor.java @@ -14,8 +14,8 @@ */ public class ManagedWebAccessor extends ManagedWebAccessorBase { - public ManagedWebAccessor(String mode, String userAgent, List serverAuthDetails) { - super(mode, userAgent, serverAuthDetails); + public ManagedWebAccessor(Iterable serverTypes, String userAgent, List serverAuthDetails) { + super(serverTypes, userAgent, serverAuthDetails); } private Map newHeaders() { @@ -66,7 +66,7 @@ private SimpleHTTPClient setupClient(String url) throws IOException { } } } else { - ServerDetailsPOJO settings = ManagedWebAccessUtils.getServer(getMode(), url, getServerAuthDetails()); + ServerDetailsPOJO settings = ManagedWebAccessUtils.getServer(getServerTypes(), url, getServerAuthDetails()); if (settings != null) { switch (settings.getAuthenticationType()) { case "basic" : @@ -101,7 +101,7 @@ public HTTPResult get(String url, String accept) throws IOException { SimpleHTTPClient client = setupClient(url); return client.get(url, accept); case MANAGED: - return ManagedWebAccess.getAccessor().get(getMode(), url, accept, newHeaders()); + return ManagedWebAccess.getAccessor().get(getServerTypes(), url, accept, newHeaders()); case PROHIBITED: throw new IOException("Access to the internet is not allowed by local security policy"); default: @@ -119,7 +119,7 @@ public HTTPResult post(String url, byte[] content, String contentType, String ac SimpleHTTPClient client = setupClient(url); return client.post(url, contentType, content, accept); case MANAGED: - return ManagedWebAccess.getAccessor().post(getMode(), url, content, contentType, accept, newHeaders()); + return ManagedWebAccess.getAccessor().post(getServerTypes(), url, content, contentType, accept, newHeaders()); case PROHIBITED: throw new IOException("Access to the internet is not allowed by local security policy"); default: @@ -137,7 +137,7 @@ public HTTPResult put(String url, byte[] content, String contentType, String acc SimpleHTTPClient client = setupClient(url); return client.put(url, contentType, content, accept); case MANAGED: - return ManagedWebAccess.getAccessor().put(getMode(), url, content, contentType, accept, newHeaders()); + return ManagedWebAccess.getAccessor().put(getServerTypes(), url, content, contentType, accept, newHeaders()); case PROHIBITED: throw new IOException("Access to the internet is not allowed by local security policy"); default: diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessorBase.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessorBase.java index f7ac120e1d..3aec0edaa3 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessorBase.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessorBase.java @@ -9,7 +9,7 @@ public abstract class ManagedWebAccessorBase> { @Getter - private final String mode; + private final Iterable serverTypes; @Getter private final String userAgent; @@ -27,8 +27,8 @@ public abstract class ManagedWebAccessorBase @Getter private final Map headers = new HashMap<>(); - public ManagedWebAccessorBase(String mode, String userAgent, List serverAuthDetails) { - this.mode = mode; + public ManagedWebAccessorBase(Iterable serverTypes, String userAgent, List serverAuthDetails) { + this.serverTypes = serverTypes; this.userAgent = userAgent; this.serverAuthDetails = serverAuthDetails; } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/JsonTrackingParser.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/JsonTrackingParser.java index f787357e89..aa46b74e0f 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/JsonTrackingParser.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/JsonTrackingParser.java @@ -37,6 +37,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS import java.io.InputStream; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.Map; import java.util.Stack; @@ -724,13 +725,13 @@ public static byte[] writeBytes(JsonObject json, boolean pretty) { } public static JsonObject fetchJson(String source) throws IOException { - HTTPResult res = ManagedWebAccess.get("web", source+"?nocache=" + System.currentTimeMillis(), "application/json, application/fhir+json"); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source+"?nocache=" + System.currentTimeMillis(), "application/json, application/fhir+json"); res.checkThrowException(); return parseJson(res.getContent()); } public static JsonArray fetchJsonArray(String source) throws IOException { - HTTPResult res = ManagedWebAccess.get("web",source+"?nocache=" + System.currentTimeMillis(), "application/json, application/fhir+json"); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"),source+"?nocache=" + System.currentTimeMillis(), "application/json, application/fhir+json"); res.checkThrowException(); return parseJsonArray(res.getContent()); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/parser/JsonParser.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/parser/JsonParser.java index c1e8e61044..ddd245065d 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/parser/JsonParser.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/json/parser/JsonParser.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.List; import org.hl7.fhir.utilities.TextFile; @@ -692,7 +693,7 @@ private void write(StringBuilder b, JsonElement e, boolean pretty, int indent) { private static byte[] fetch(String source) throws IOException { String murl = source.contains("?") ? source+"&nocache=" + System.currentTimeMillis() : source+"?nocache=" + System.currentTimeMillis(); - HTTPResult res = ManagedWebAccess.get("web", murl, "application/json, application/fhir+json"); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), murl, "application/json, application/fhir+json"); res.checkThrowException(); return res.getContent(); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java index fb5df4aa7c..8cde2c8044 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java @@ -729,7 +729,8 @@ private InputStreamWithSrc fetchSourceFromUrlSpecific(String url) { private InputStream fetchFromUrlSpecific(String source, boolean optional) throws FHIRException { try { - HTTPResult res = ManagedWebAccess.get("web", source); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source); res.checkThrowException(); return new ByteArrayInputStream(res.getContent()); } catch (Exception e) { @@ -862,8 +863,8 @@ private void checkBuildLoaded() { } private void loadFromBuildServer() throws IOException { - - HTTPResult res = ManagedWebAccess.get("web", "https://build.fhir.org/ig/qas.json?nocache=" + System.currentTimeMillis()); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), "https://build.fhir.org/ig/qas.json?nocache=" + System.currentTimeMillis()); res.checkThrowException(); buildInfo = (JsonArray) JsonParser.parse(TextFile.bytesToString(res.getContent())); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java index 6dad79d3bf..3627576507 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java @@ -44,15 +44,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.zip.Deflater; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -1480,7 +1472,7 @@ public Date dateAsDate() { } public static NpmPackage fromUrl(String source) throws IOException { - HTTPResult res = ManagedWebAccess.get("npm", source+"?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("npm-package", "fhir-package"), source+"?nocache=" + System.currentTimeMillis()); res.checkThrowException(); return fromPackage(new ByteArrayInputStream(res.getContent())); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java index 9c44e81b74..5b36c435c1 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java @@ -8,11 +8,7 @@ import java.text.SimpleDateFormat; import java.time.Instant; import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; +import java.util.*; import javax.annotation.Nullable; @@ -175,7 +171,8 @@ public Date getNewPackages(Date lastCalled, List updates) { } private InputStream fetchUrl(String source, String accept) throws IOException { - ManagedWebAccessor webAccessor = ManagedWebAccess.accessor("web"); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + ManagedWebAccessor webAccessor = ManagedWebAccess.accessor(Arrays.asList("web")); if (server.getAuthenticationMode() == HTTPAuthenticationMode.TOKEN) { webAccessor.withToken(server.getToken()); } else if (server.getAuthenticationMode() == HTTPAuthenticationMode.BASIC) { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageServer.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageServer.java index 7ad221a1f0..d4d6069632 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageServer.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageServer.java @@ -69,7 +69,7 @@ public static PackageServer getPackageServerFromPOJO(ServerDetailsPOJO pojo) { return new PackageServer(pojo.getUrl()) .withAuthenticationMode(getModeFromPOJO(pojo)) .withServerType( - pojo.getServerType() != null && pojo.getServerType().equalsIgnoreCase("npm") ? PackageServerType.NPM : PackageServerType.FHIR + pojo.getType() != null && pojo.getType().equalsIgnoreCase("npm-package") ? PackageServerType.NPM : PackageServerType.FHIR ) .withUsername(pojo.getUsername()) .withPassword(pojo.getPassword()) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/settings/ServerDetailsPOJO.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/settings/ServerDetailsPOJO.java index e2c5784dc6..160d16c631 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/settings/ServerDetailsPOJO.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/settings/ServerDetailsPOJO.java @@ -10,17 +10,25 @@ @Jacksonized @AllArgsConstructor public class ServerDetailsPOJO { - - // what kind of HTTP server this is - a FHIR tx server, an NPM server, or a general web server - String mode; String url; // possible values: none, basic, token, apikey String authenticationType; - // npm or fhir, because the FHIR npm usage varies a little bit from general NPM usage (change over time) - String serverType; + /** + * This helps clients use appropriate API endpoints for each server type. + *

+ * It can be of the following types: + *

    + *
  • web
  • + *
  • fhir
  • + *
  • npm-package
  • + *
  • fhir-package
  • + *
+ */ + + String type; String username; diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/http/ManagedWebAccessAuthTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/http/ManagedWebAccessAuthTests.java index e57f4118a8..f57d93988f 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/http/ManagedWebAccessAuthTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/http/ManagedWebAccessAuthTests.java @@ -162,7 +162,6 @@ public void testBasicAuthFromSettings() throws IOException, InterruptedException private ServerDetailsPOJO getBasicAuthServerPojo() { return new ServerDetailsPOJO( - null, server.url("").toString(), "basic", "dummyServerType", @@ -182,7 +181,6 @@ public void testTokenAuthFromSettings() throws IOException, InterruptedException private ServerDetailsPOJO getTokenAuthServerPojo() { return new ServerDetailsPOJO( - null, server.url("").toString(), "token", "dummyServerType", @@ -202,7 +200,6 @@ public void testApiKeyAuthFromSettings() throws IOException, InterruptedExceptio private ServerDetailsPOJO getApiKeyAuthServerPojo() { return new ServerDetailsPOJO( - null, server.url("").toString(), "apikey", "dummyServerType", diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/settings/FhirSettingsTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/settings/FhirSettingsTests.java index 141ea3433d..426ec631a6 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/settings/FhirSettingsTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/settings/FhirSettingsTests.java @@ -92,7 +92,7 @@ public void testParseFhirSettings() throws IOException { assertEquals(2, packageServers.size()); assertEquals("http://dummy.org", packageServers.get(0).url); - assertEquals("npm", packageServers.get(0).serverType); + assertEquals("npm-fhir", packageServers.get(0).type); assertEquals("joe", packageServers.get(0).username); assertEquals("swordfish", packageServers.get(0).password); assertEquals("BASIC", packageServers.get(0).authenticationType); diff --git a/org.hl7.fhir.utilities/src/test/resources/settings/settings-example.json b/org.hl7.fhir.utilities/src/test/resources/settings/settings-example.json index df09269207..cbcf6807b4 100644 --- a/org.hl7.fhir.utilities/src/test/resources/settings/settings-example.json +++ b/org.hl7.fhir.utilities/src/test/resources/settings/settings-example.json @@ -14,7 +14,7 @@ "servers": [ { "url": "http://dummy.org", - "serverType": "npm", + "serverType": "npm-fhir", "authenticationType": "BASIC", "username": "joe", "password": "swordfish" diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java index c6d4ef8e63..0644bda2f6 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java @@ -430,7 +430,8 @@ private String loadPackageForVersion(InputStream stream) throws FHIRException, I private InputStream fetchFromUrlSpecific(String source, boolean optional) throws FHIRException, IOException { try { - HTTPResult res = ManagedWebAccess.get("web", source + "?nocache=" + System.currentTimeMillis()); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source + "?nocache=" + System.currentTimeMillis()); res.checkThrowException(); return new ByteArrayInputStream(res.getContent()); } catch (IOException e) { @@ -584,11 +585,13 @@ private byte[] fetchFromUrlSpecific(String source, String contentType, boolean o try { try { // try with cache-busting option and then try withhout in case the server doesn't support that - HTTPResult res = ManagedWebAccess.get("web",source + "?nocache=" + System.currentTimeMillis(), contentType); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"),source + "?nocache=" + System.currentTimeMillis(), contentType); res.checkThrowException(); return res.getContent(); } catch (Exception e) { - HTTPResult res = ManagedWebAccess.get("web", source, contentType); + //FIXME: Could this be in disagreement with the credentials selected by ManagedWebAccess? + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source, contentType); res.checkThrowException(); return res.getContent(); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java index 856f566687..a0cb339a13 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java @@ -8,13 +8,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -319,7 +313,7 @@ protected OperationOutcome exceptionToOutcome(Exception ex) throws IOException, } protected void download(String address, String filename) throws IOException { - HTTPResult res = ManagedWebAccess.get("web", address); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), address); res.checkThrowException(); TextFile.bytesToFile(res.getContent(), filename); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 46738614a9..bc642efb3a 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -19,7 +19,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.UUID; import org.fhir.ucum.UcumEssenceService; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; @@ -72,12 +71,9 @@ import org.hl7.fhir.r5.utils.validation.IResourceValidator; import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor; import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher; -import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.AdditionalBindingPurpose; -import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.CodedContentValidationAction; import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.validation.constants.BindingKind; import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption; -import org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.IdStatus; import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy; @@ -942,7 +938,7 @@ public void handleOutput(Resource r, String output, String version) throws FHIRE if (output.startsWith("http://")) { ByteArrayOutputStream bs = new ByteArrayOutputStream(); handleOutputToStream(r, output, bs, version); - HTTPResult res = ManagedWebAccess.post("web", output, bs.toByteArray(), "application/fhir+xml", "application/fhir+xml"); + HTTPResult res = ManagedWebAccess.post(Arrays.asList("web"), output, bs.toByteArray(), "application/fhir+xml", "application/fhir+xml"); res.checkThrowException(); } else { FileOutputStream s = ManagedFileAccess.outStream(output); @@ -1099,7 +1095,7 @@ public FilesystemPackageCacheManager getPcm() throws IOException { @Override public byte[] fetchRaw(IResourceValidator validator, String source) throws IOException { - HTTPResult res = ManagedWebAccess.get("web", source); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source); res.checkThrowException(); return res.getContent(); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/ProfileLoader.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/ProfileLoader.java index 2ace9d6d44..6a41e14089 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/ProfileLoader.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/ProfileLoader.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.util.Arrays; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.utilities.TextFile; @@ -25,7 +26,7 @@ public static byte[] loadProfileSource(String src) throws FHIRException, IOExcep private static byte[] loadProfileFromUrl(String src) throws FHIRException { try { - HTTPResult res = ManagedWebAccess.get("web", src + "?nocache=" + System.currentTimeMillis()); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), src + "?nocache=" + System.currentTimeMillis()); res.checkThrowException(); return res.getContent(); } catch (Exception e) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java index b0793fafa1..0cc39a5a62 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java @@ -2,6 +2,7 @@ import java.io.ByteArrayInputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -160,7 +161,7 @@ private void checkSelfLink(ValidationNode vn, Element bundle, Map= 300) { vn.getIssues().add(new ValidationMessage(Source.IPAValidator, IssueType.EXCEPTION, "http.request", "HTTP Return code is "+result.getCode()+" "+result.getMessage(), diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java index 09c87d7f09..0ef47c5372 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java @@ -8,17 +8,8 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.NotImplementedException; @@ -858,7 +849,7 @@ public static void saveWhenDone() throws IOException { @Override public byte[] fetchRaw(IResourceValidator validator, String source) throws MalformedURLException, IOException { - HTTPResult res = ManagedWebAccess.get("web", source); + HTTPResult res = ManagedWebAccess.get(Arrays.asList("web"), source); res.checkThrowException(); return res.getContent(); }