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 38618efa2739d17c3ce1825c2b92fe797ba740e8..4ff98310b10fa909e477300cc741f20775624649 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 6eeaf1eda9f38c70ab31437d5197204345ccb9e0..3c5303d3f3e6bb100047c0df70d25730f22b3d5e 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 094c9634da55ec40d7cae91da036532d7ce5f21b..acfe9802646ceb778dffa3d678098390a612fed7 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 124af890e00463f91aeee1d04706b1c351c50bcc..ecff8661d140e74d1cc435df6cc4f6a7d51a96d4 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 3608fd1427677e37efc794c0c1e85ba193e4f918..0c5f8636d7e9c9d2d3c4fc8ea652372524361415 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);