diff --git a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/WhoamiController.java b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/WhoamiController.java
index 5a538259e9942e1d74577b4023a7a637c3fb812c..e04342872d10fb7839684f9ce376e91441ae08f0 100644
--- a/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/WhoamiController.java
+++ b/provider/legal-azure/src/main/java/org/opengroup/osdu/legal/azure/security/WhoamiController.java
@@ -15,6 +15,7 @@
 package org.opengroup.osdu.legal.azure.security;
 
 import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -22,10 +23,24 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 @Controller
 public class WhoamiController {
+
+    private SecurityContext securityContext;
+
+    // Constructor made for unit testing
+    public WhoamiController(SecurityContext securityContext) {
+        this.securityContext = securityContext;
+    }
+
+    public WhoamiController() {
+    }
+
     @RequestMapping(value = "/whoami")
     @ResponseBody
     public String whoami() {
-        final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+        // Added for unit testing
+        if (securityContext == null)
+            securityContext = SecurityContextHolder.getContext();
+        final Authentication auth = securityContext.getAuthentication();
 
         String userName = auth.getName();
         String roles = String.valueOf(auth.getAuthorities());
diff --git a/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/security/WhoamiControllerTest.java b/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/security/WhoamiControllerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..6a8df1c3f087d8ff7c0a19187e5fc6330fd1d904
--- /dev/null
+++ b/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/security/WhoamiControllerTest.java
@@ -0,0 +1,2 @@
+package org.opengroup.osdu.legal.azure.security;public class WhoamiControllerTest {
+}