Remove conflicting authorization header setting methods
This commit is contained in:
parent
a93ab69231
commit
2c57f5954e
|
@ -54,8 +54,7 @@ public class VSACImporter extends OIDBasedValueSetImporter {
|
|||
Map<String, String> errs = new HashMap<>();
|
||||
|
||||
FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac");
|
||||
fhirToolingClient.setUsername("apikey");
|
||||
fhirToolingClient.setPassword(apiKey);
|
||||
|
||||
fhirToolingClient.setTimeoutNormal(30000);
|
||||
fhirToolingClient.setTimeoutExpand(30000);
|
||||
|
||||
|
|
|
@ -33,12 +33,10 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
@ -47,7 +45,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -93,13 +90,7 @@ public class ClientUtils {
|
|||
@Setter
|
||||
private int timeout = 5000;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String username;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String password;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
|
@ -213,18 +204,6 @@ public class ClientUtils {
|
|||
return unmarshalReference(response, resourceFormat);
|
||||
}
|
||||
|
||||
private Iterable<HTTPHeader> getAuthHeaders() {
|
||||
if (password != null) {
|
||||
try {
|
||||
byte[] b = Base64.encodeBase64((username + ":" + password).getBytes("ASCII"));
|
||||
String b64 = new String(b, StandardCharsets.US_ASCII);
|
||||
return Arrays.asList(new HTTPHeader[]{new HTTPHeader("Authorization", "Basic " + b64)});
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) {
|
||||
if (FhirSettings.isProhibitNetworkAccess()) {
|
||||
throw new FHIRException("Network Access is prohibited in this context");
|
||||
|
@ -318,9 +297,6 @@ public class ClientUtils {
|
|||
Iterable<HTTPHeader> resourceFormatHeaders = getResourceFormatHeaders(httpRequest, format);
|
||||
resourceFormatHeaders.forEach(configuredHeaders::add);
|
||||
|
||||
Iterable<HTTPHeader> authHeaders = getAuthHeaders();
|
||||
authHeaders.forEach(configuredHeaders::add);
|
||||
|
||||
if (headers != null) {
|
||||
headers.forEach(configuredHeaders::add);
|
||||
}
|
||||
|
|
|
@ -110,20 +110,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
initialize(baseServiceUrl);
|
||||
}
|
||||
|
||||
public FHIRToolingClient(String baseServiceUrl, String userAgent, String username, String password)
|
||||
throws URISyntaxException {
|
||||
preferredResourceFormat = ResourceFormat.RESOURCE_XML;
|
||||
utils = getClientUtils();
|
||||
utils.setUserAgent(userAgent);
|
||||
utils.setUsername(username);
|
||||
utils.setPassword(password);
|
||||
initialize(baseServiceUrl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void initialize(String baseServiceUrl) throws URISyntaxException {
|
||||
base = baseServiceUrl;
|
||||
resourceAddress = new ResourceAddress(baseServiceUrl);
|
||||
|
@ -592,22 +578,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
utils.setTimeout(timeout);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return utils.getUsername();
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
utils.setUsername(username);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return utils.getPassword();
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
utils.setPassword(password);
|
||||
}
|
||||
|
||||
public Parameters getTerminologyCapabilities() {
|
||||
return (Parameters) utils
|
||||
.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), withVer(getPreferredResourceFormat(), "1.0"), timeoutNormal)
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.net.URISyntaxException;
|
|||
import java.util.*;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hl7.fhir.dstu3.model.Bundle;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement;
|
||||
import org.hl7.fhir.dstu3.model.CodeSystem;
|
||||
|
@ -68,13 +69,16 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
private CapabilityStatement capabilities;
|
||||
private Client client = new Client();
|
||||
private List<HTTPHeader> headers = new ArrayList<>();
|
||||
private String username;
|
||||
private String password;
|
||||
@Setter
|
||||
@Getter
|
||||
private String userAgent;
|
||||
private EnumSet<FhirPublication> allowedVersions;
|
||||
@Setter
|
||||
@Getter
|
||||
private String acceptLanguage;
|
||||
@Setter
|
||||
private String contentLanguage;
|
||||
@Getter
|
||||
private int useCount;
|
||||
|
||||
//Pass endpoint for client - URI
|
||||
|
@ -534,21 +538,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
return result == null ? null : (ConceptMap) result.getPayload();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return client.getTimeout();
|
||||
|
@ -579,15 +568,9 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
headers.forEach(this.headers::add);
|
||||
}
|
||||
|
||||
//FIXME should be in ManagedWebAccess?
|
||||
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
|
||||
List<HTTPHeader> headers = new ArrayList<>();
|
||||
// Add basic auth header if it exists
|
||||
if (basicAuthHeaderExists()) {
|
||||
headers.add(getAuthorizationHeader());
|
||||
}
|
||||
// Add any other headers
|
||||
headers.addAll(this.headers);
|
||||
List<HTTPHeader> headers = new ArrayList<>(this.headers);
|
||||
if (!Utilities.noString(userAgent)) {
|
||||
headers.add(new HTTPHeader("User-Agent",userAgent));
|
||||
}
|
||||
|
@ -603,40 +586,11 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
return headers;
|
||||
}
|
||||
|
||||
public boolean basicAuthHeaderExists() {
|
||||
return (username != null) && (password != null);
|
||||
}
|
||||
|
||||
public HTTPHeader getAuthorizationHeader() {
|
||||
String usernamePassword = username + ":" + password;
|
||||
String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes());
|
||||
return new HTTPHeader("Authorization", "Basic " + base64usernamePassword);
|
||||
}
|
||||
|
||||
public String getUserAgent() {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
public void setUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
public String getServerVersion() {
|
||||
checkCapabilities();
|
||||
return capabilities == null ? null : capabilities.getSoftware().getVersion();
|
||||
}
|
||||
|
||||
public void setAcceptLanguage(String lang) {
|
||||
this.acceptLanguage = lang;
|
||||
}
|
||||
public void setContentLanguage(String lang) {
|
||||
this.contentLanguage = lang;
|
||||
}
|
||||
|
||||
public int getUseCount() {
|
||||
return useCount;
|
||||
}
|
||||
|
||||
private void recordUse() {
|
||||
useCount++;
|
||||
}
|
||||
|
|
|
@ -76,10 +76,7 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
@Setter
|
||||
private Client client = new Client();
|
||||
private List<HTTPHeader> headers = new ArrayList<>();
|
||||
@Getter @Setter
|
||||
private String username;
|
||||
@Getter @Setter
|
||||
private String password;
|
||||
|
||||
@Getter @Setter
|
||||
private String userAgent;
|
||||
@Setter
|
||||
|
@ -544,13 +541,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
|
||||
//FIXME should be in ManagedWebAccess?
|
||||
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
|
||||
List<HTTPHeader> headers = new ArrayList<>();
|
||||
// Add basic auth header if it exists
|
||||
if (basicAuthHeaderExists()) {
|
||||
headers.add(getAuthorizationHeader());
|
||||
}
|
||||
// Add any other headers
|
||||
headers.addAll(this.headers);
|
||||
List<HTTPHeader> headers = new ArrayList<>(this.headers);
|
||||
if (!Utilities.noString(userAgent)) {
|
||||
headers.add(new HTTPHeader("User-Agent",userAgent));
|
||||
}
|
||||
|
@ -563,21 +555,9 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
headers.add(new HTTPHeader("Content-Language",contentLanguage));
|
||||
}
|
||||
|
||||
headers.add(new HTTPHeader("Host", "cts.nlm.nih.gov"));
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
public boolean basicAuthHeaderExists() {
|
||||
return (username != null) && (password != null);
|
||||
}
|
||||
|
||||
public HTTPHeader getAuthorizationHeader() {
|
||||
String usernamePassword = username + ":" + password;
|
||||
String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes());
|
||||
return new HTTPHeader("Authorization", "Basic " + base64usernamePassword);
|
||||
}
|
||||
|
||||
public String getServerVersion() {
|
||||
checkCapabilities();
|
||||
return capabilities == null ? null : capabilities.getSoftware().getVersion();
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.hl7.fhir.r4b.model.*;
|
|||
import org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent;
|
||||
import org.hl7.fhir.r4b.utils.client.network.ByteUtils;
|
||||
import org.hl7.fhir.r4b.utils.client.network.Client;
|
||||
import org.hl7.fhir.r4b.utils.client.network.ClientHeaders;
|
||||
import org.hl7.fhir.r4b.utils.client.network.ResourceRequest;
|
||||
import org.hl7.fhir.utilities.FHIRBaseToolingClient;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
|
@ -46,7 +45,6 @@ import org.hl7.fhir.utilities.Utilities;
|
|||
import org.hl7.fhir.utilities.http.HTTPHeader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
|
@ -96,13 +94,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{
|
|||
@Setter
|
||||
private Client client = new Client();
|
||||
private List<HTTPHeader> headers = new ArrayList<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private String username;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String password;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
|
@ -537,13 +528,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{
|
|||
}
|
||||
|
||||
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
|
||||
List<HTTPHeader> headers = new ArrayList<>();
|
||||
// Add basic auth header if it exists
|
||||
if (basicAuthHeaderExists()) {
|
||||
headers.add(getAuthorizationHeader());
|
||||
}
|
||||
// Add any other headers
|
||||
headers.addAll(this.headers);
|
||||
List<HTTPHeader> headers = new ArrayList<>(this.headers);
|
||||
if (!Utilities.noString(userAgent)) {
|
||||
headers.add(new HTTPHeader("User-Agent",userAgent));
|
||||
}
|
||||
|
@ -559,16 +545,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{
|
|||
return headers;
|
||||
}
|
||||
|
||||
public boolean basicAuthHeaderExists() {
|
||||
return (username != null) && (password != null);
|
||||
}
|
||||
|
||||
public HTTPHeader getAuthorizationHeader() {
|
||||
String usernamePassword = username + ":" + password;
|
||||
String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes());
|
||||
return new HTTPHeader("Authorization", "Basic " + base64usernamePassword);
|
||||
}
|
||||
|
||||
public String getServerVersion() {
|
||||
return capabilities == null ? null : capabilities.getSoftware().getVersion();
|
||||
}
|
||||
|
|
|
@ -100,12 +100,7 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
@Setter
|
||||
private Client client = new Client();
|
||||
private List<HTTPHeader> headers = new ArrayList<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private String username;
|
||||
@Getter
|
||||
@Setter
|
||||
private String password;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private String userAgent;
|
||||
|
@ -602,13 +597,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
|
||||
//FIXME should be in ManagedWebAccess?
|
||||
private Iterable<HTTPHeader> generateHeaders(boolean hasBody) {
|
||||
List<HTTPHeader> headers = new ArrayList<>();
|
||||
// Add basic auth header if it exists
|
||||
if (basicAuthHeaderExists()) {
|
||||
headers.add(getAuthorizationHeader());
|
||||
}
|
||||
// Add any other headers
|
||||
headers.addAll(this.headers);
|
||||
List<HTTPHeader> headers = new ArrayList<>(this.headers);
|
||||
if (!Utilities.noString(userAgent)) {
|
||||
headers.add(new HTTPHeader("User-Agent",userAgent));
|
||||
}
|
||||
|
@ -624,16 +614,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient {
|
|||
return headers;
|
||||
}
|
||||
|
||||
public boolean basicAuthHeaderExists() {
|
||||
return (username != null) && (password != null);
|
||||
}
|
||||
|
||||
public HTTPHeader getAuthorizationHeader() {
|
||||
String usernamePassword = username + ":" + password;
|
||||
String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes());
|
||||
return new HTTPHeader("Authorization", "Basic " + base64usernamePassword);
|
||||
}
|
||||
|
||||
public String getServerVersion() {
|
||||
if (capabilities == null) {
|
||||
try {
|
||||
|
|
|
@ -76,8 +76,6 @@ public class ManagedWebAccess {
|
|||
@Getter
|
||||
private static IFhirWebAccessor fhirWebAccessor;
|
||||
|
||||
|
||||
|
||||
@Getter
|
||||
private static String userAgent;
|
||||
private static List<ServerDetailsPOJO> serverAuthDetails;
|
||||
|
|
|
@ -51,4 +51,22 @@ public abstract class ManagedWebAccessBuilderBase<B extends ManagedWebAccessBuil
|
|||
this.token = token;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B withNoneAuth() {
|
||||
this.authenticationMode = HTTPAuthenticationMode.NONE;
|
||||
setAllAuthHeadersToNull();
|
||||
return self();
|
||||
}
|
||||
|
||||
public B withServerSpecificAuth() {
|
||||
this.authenticationMode = null;
|
||||
setAllAuthHeadersToNull();
|
||||
return self();
|
||||
}
|
||||
|
||||
private void setAllAuthHeadersToNull() {
|
||||
this.token = null;
|
||||
this.username = null;
|
||||
this.password = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue