From 7ef8640ef757ff7e2b06466a0a6b8d80919a87a8 Mon Sep 17 00:00:00 2001 From: lmds Date: Tue, 10 Jun 2014 15:34:50 -0400 Subject: [PATCH] update restful server to prompt user for credentials on authorization exception if request came from a browser --- .../src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 48e7908de68..49d6d7919a6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -625,6 +625,11 @@ public class RestfulServer extends HttpServlet { resourceMethod.invokeServer(this, r, theResponse); } catch (AuthenticationException e) { + String userAgent = theRequest.getHeader("User-Agent"); + if (userAgent != null && userAgent.contains("Mozilla")) { + //if request is coming from a browser, prompt the user to enter login credentials + theResponse.setHeader("WWW-Authenticate", "BASIC realm=\"FHIR\""); + } theResponse.setStatus(e.getStatusCode()); addHeadersToResponse(theResponse); theResponse.setContentType("text/plain");