From a744a00b5f9191ce9aabd923ffcc1aa3bb782690 Mon Sep 17 00:00:00 2001
From: nikhilsingh <nikhilsingh@microsoft.com>
Date: Thu, 1 Jul 2021 15:05:16 +0530
Subject: [PATCH] Commit 7 Contents: 1-Annotaion Resolution

---
 .../java/org/opengroup/osdu/notification/auth/GsaAuth.java | 2 ++
 .../org/opengroup/osdu/notification/auth/HmacAuth.java     | 2 ++
 .../osdu/notification/auth/factory/AuthFactory.java        | 4 ++--
 .../osdu/notification/service/NotificationHandler.java     | 7 ++++---
 .../notification/service/NotificationHandlerTests.java     | 6 +++---
 5 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java
index 38618efa2..4ff98310b 100644
--- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java
+++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java
@@ -24,11 +24,13 @@ import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
 import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.web.context.annotation.RequestScope;
 
 import java.util.HashMap;
 import java.util.Map;
 
 @Component
+@RequestScope
 public class GsaAuth implements SecretAuth {
     @Autowired
     private IGoogleServiceAccount gsaTokenProvider;
diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java
index 6eeaf1eda..3c5303d3f 100644
--- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java
+++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java
@@ -21,11 +21,13 @@ import org.opengroup.osdu.core.common.model.notification.Secret;
 import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.web.context.annotation.RequestScope;
 
 import java.util.HashMap;
 import java.util.Map;
 
 @Component
+@RequestScope
 public class HmacAuth implements SecretAuth {
     @Autowired
     private ISignatureService signatureService;
diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java
index 094c9634d..acfe98026 100644
--- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java
+++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java
@@ -16,12 +16,12 @@
 package org.opengroup.osdu.notification.auth.factory;
 
 import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
-import org.opengroup.osdu.core.common.model.notification.Secret;
 import org.opengroup.osdu.notification.auth.GsaAuth;
 import org.opengroup.osdu.notification.auth.HmacAuth;
 import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.web.context.annotation.RequestScope;
 
 @Component
 public class AuthFactory {
@@ -32,7 +32,7 @@ public class AuthFactory {
     @Autowired
     private JaxRsDpsLog log;
 
-    public SecretAuth getSecret(String secretType) {
+    public SecretAuth getSecretAuth(String secretType) {
         switch (secretType) {
             case "HMAC":
                 return hmacAuth;
diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java b/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java
index 124af890e..ecff8661d 100644
--- a/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java
+++ b/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java
@@ -27,6 +27,7 @@ import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import org.springframework.web.context.annotation.RequestScope;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -50,10 +51,10 @@ public class NotificationHandler {
         String endpoint = subscription.getPushEndpoint();
         String secretType = secret.getSecretType();
         String pushUrl = "";
-        Map<String, String> requestHeader = new HashMap<>();
-        // Authentication Secret
+        Map<String, String> requestHeader = new HashMap<String,String>();
 
-        SecretAuth secretAuth = authFactory.getSecret(secretType);
+        // Authentication Secret
+        SecretAuth secretAuth = authFactory.getSecretAuth(secretType);
         secretAuth.setSecret(secret);
         pushUrl = secretAuth.getPushUrl(endpoint);
         requestHeader = secretAuth.getRequestHeaders();
diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTests.java b/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTests.java
index 3608fd142..0c5f8636d 100644
--- a/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTests.java
+++ b/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTests.java
@@ -70,7 +70,7 @@ public class NotificationHandlerTests {
         response.setResponseCode(200);
         Map<String, String> headers = new HashMap<String, String>();
         when(this.subscriptionHandler.getSubscriptionFromCache(this.NOTIFICATION_ID)).thenReturn(gsa_subscription);
-        when(this.authFactory.getSecret(any())).thenReturn(secretAuth);
+        when(this.authFactory.getSecretAuth(any())).thenReturn(secretAuth);
         when(this.httpClient.send(any())).thenReturn(response);
         when(this.secretAuth.getPushUrl(gsa_subscription.getPushEndpoint())).thenReturn(gsa_subscription.getPushEndpoint());
         when(this.secretAuth.getRequestHeaders()).thenReturn(headers);
@@ -83,7 +83,7 @@ public class NotificationHandlerTests {
         response.setResponseCode(200);
         Map<String, String> headers = new HashMap<String, String>();
         when(this.subscriptionHandler.getSubscriptionFromCache(this.NOTIFICATION_ID)).thenReturn(hmac_subscription);
-        when(this.authFactory.getSecret(any())).thenReturn(secretAuth);
+        when(this.authFactory.getSecretAuth(any())).thenReturn(secretAuth);
         when(this.httpClient.send(any())).thenReturn(response);
         when(this.secretAuth.getPushUrl(hmac_subscription.getPushEndpoint())).thenReturn(hmac_subscription.getPushEndpoint());
         when(this.secretAuth.getRequestHeaders()).thenReturn(headers);
@@ -94,7 +94,7 @@ public class NotificationHandlerTests {
     @Test(expected = SubscriptionException.class)
     public void should_throwException_whenSubscriptionHandlerThrowsException() throws Exception {
         Map<String, String> headers = new HashMap<String, String>();
-        when(this.authFactory.getSecret(any())).thenReturn(secretAuth);
+        when(this.authFactory.getSecretAuth(any())).thenReturn(secretAuth);
         when(this.httpClient.send(any())).thenReturn(response);
         when(this.secretAuth.getPushUrl(gsa_subscription.getPushEndpoint())).thenReturn(gsa_subscription.getPushEndpoint());
         when(this.secretAuth.getRequestHeaders()).thenReturn(headers);
-- 
GitLab