From 79670cf172ad25db9e49c9f5f48d05b128dcae92 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Fri, 7 Mar 2014 17:18:40 -0500 Subject: [PATCH] added the ISecurityManager interface --- .../java/ca/uhn/fhir/rest/server/ISecurityManager.java | 10 ++++++++++ .../java/ca/uhn/fhir/rest/server/RestfulServer.java | 9 +++++++++ .../ca/uhn/fhir/rest/server/DummyRestfulServer.java | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/ISecurityManager.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/ISecurityManager.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/ISecurityManager.java new file mode 100644 index 00000000000..f407182dfde --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/ISecurityManager.java @@ -0,0 +1,10 @@ +package ca.uhn.fhir.rest.server; + +import javax.servlet.http.HttpServletRequest; + +/** + * Created by dsotnikov on 3/7/2014. + */ +public interface ISecurityManager { + public boolean authenticate(HttpServletRequest request); +} 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 df849858046..65933bf9d7e 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 @@ -37,6 +37,8 @@ public abstract class RestfulServer extends HttpServlet { private static final long serialVersionUID = 1L; + private ISecurityManager securityManager; + private FhirContext myFhirContext; private Map, IResourceProvider> myTypeToProvider = new HashMap, IResourceProvider>(); @@ -101,6 +103,8 @@ public abstract class RestfulServer extends HttpServlet { public abstract Collection getResourceProviders(); + public abstract ISecurityManager getSecurityManager(); + protected void handleRequest(SearchMethodBinding.RequestType requestType, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String resourceName = null; @@ -201,6 +205,11 @@ public abstract class RestfulServer extends HttpServlet { try { ourLog.info("Initializing HAPI FHIR restful server"); + securityManager = getSecurityManager(); + if (null == securityManager) { + ourLog.warn("No security manager has been provided, requests will not be authenticated!"); + } + Collection resourceProvider = getResourceProviders(); for (IResourceProvider nextProvider : resourceProvider) { if (myTypeToProvider.containsKey(nextProvider.getResourceType())) { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/DummyRestfulServer.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/DummyRestfulServer.java index b6612fe8531..1364e6152e2 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/DummyRestfulServer.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/DummyRestfulServer.java @@ -21,4 +21,9 @@ public class DummyRestfulServer extends RestfulServer { return myResourceProviders; } + @Override + public ISecurityManager getSecurityManager() { + return null; + } + }