diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/HttpBasicAuthInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/HttpBasicAuthInterceptor.java new file mode 100644 index 00000000000..eb2e393ecb5 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/HttpBasicAuthInterceptor.java @@ -0,0 +1,44 @@ +package ca.uhn.fhir.rest.client; + +import java.io.IOException; + +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.auth.AuthState; +import org.apache.http.auth.Credentials; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.protocol.HttpContext; + +/** + * HTTP interceptor to be used for adding HTTP basic auth username/password tokens + * to requests + *
+ * See the + *
+ */ +public class HttpBasicAuthInterceptor implements HttpRequestInterceptor { + + private String myUsername; + private String myPassword; + + public HttpBasicAuthInterceptor(String theUsername, String thePassword) { + super(); + myUsername = theUsername; + myPassword = thePassword; + } + + @Override + public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { + AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); + + if (authState.getAuthScheme() == null) { + Credentials creds = new UsernamePasswordCredentials(myUsername, myPassword); + authState.update(new BasicScheme(), creds); + } + + } + +} \ No newline at end of file diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java index 7f2b12ecf48..d75c475fcad 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java @@ -69,7 +69,7 @@ public abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends if (param == null) { continue; } - params[i] = param.translateQueryParametersIntoServerArgument(theRequest.getParameters(), resource); + params[i] = param.translateQueryParametersIntoServerArgument(theRequest, resource); } addParametersForServerRequest(theRequest, params); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java index 3238780a6b6..2089bed62c2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.method; -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.IOException; import java.io.PrintWriter; @@ -130,7 +130,7 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi throw new IllegalStateException("Should not get here!"); } - public abstract List