diff --git a/NOTICE b/NOTICE index 76438017b3ddabc7a0a9c3507f0281a96f10031f..b3825be3100afeffddfcd47b206963d86ef9b71e 100644 --- a/NOTICE +++ b/NOTICE @@ -76,7 +76,7 @@ The following software have components provided under the terms of this license: - Apache Log4j JUL Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-jul) - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) -- AssertJ fluent assertions (from ${project.parent.url}#${project.artifactId}, https://repo1.maven.org/maven2/org/assertj/assertj-core) +- AssertJ Core (from ${project.organization.url}#${project.artifactId}) - Asynchronous Http Client (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client) - Asynchronous Http Client Netty Utils (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client-netty-utils) - AutoValue Annotations (from https://github.com/google/auto/tree/master/value, https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations) @@ -321,8 +321,8 @@ The following software have components provided under the terms of this license: - proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1) - proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2) - proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1) -- proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) -- proto-google-iam-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1) +- proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) +- proto-google-iam-v1 (from https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1) - resilience4j (from https://github.com/resilience4j/resilience4j, https://resilience4j.readme.io, ttps://resilience4j.readme.io) - spring-boot-starter-undertow (from https://spring.io/projects/spring-boot) - spring-security-crypto (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) @@ -353,7 +353,7 @@ BSD-2-Clause ======================================================================== The following software have components provided under the terms of this license: -- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) +- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common) - GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax) - GAX (Google Api eXtensions) for Java (HTTP JSON) (from https://repo1.maven.org/maven2/com/google/api/gax-httpjson) - GAX (Google Api eXtensions) for Java (gRPC) (from https://repo1.maven.org/maven2/com/google/api/gax-grpc) @@ -371,7 +371,7 @@ BSD-3-Clause ======================================================================== The following software have components provided under the terms of this license: -- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) +- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common) - ASM Core (from http://asm.ow2.io/, http://asm.ow2.org/) - AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/) - Expression Language 3.0 (from http://el-spec.java.net, http://uel.java.net, https://projects.eclipse.org/projects/ee4j.el) diff --git a/devops/gcp/deploy/README.md b/devops/gcp/deploy/README.md index df9605af779a713efcbb806f9e6494483f9a5195..d3cfe7b1b63812ebbaac0054d91f0b0789e512e9 100644 --- a/devops/gcp/deploy/README.md +++ b/devops/gcp/deploy/README.md @@ -36,7 +36,6 @@ First you need to set variables in **values.yaml** file using any code editor. S **entitlementsHost** | entitlements service host address | string | `http://entitlements` | yes **registerHost** | register service host address | string | `http://register` | yes **partitionHost** | partition service host address | string | `http://partition` | yes -**googleAudiences** | Client ID of Google Cloud Credentials, ex `123-abc123.apps.googleusercontent.com` | string | - | yes ### Deployment variables diff --git a/devops/gcp/deploy/templates/configmap.yaml b/devops/gcp/deploy/templates/configmap.yaml index c217ee88fdf1688dae893f76207e02203dd933bc..3099712be7d2929326734b243889efea4a1b002d 100644 --- a/devops/gcp/deploy/templates/configmap.yaml +++ b/devops/gcp/deploy/templates/configmap.yaml @@ -12,5 +12,4 @@ data: REGISTER_HOST: {{ .Values.data.registerHost | quote}} PARTITION_HOST: {{ .Values.data.partitionHost | quote}} {{- if not .Values.conf.onPremEnabled }} - GOOGLE_AUDIENCES: {{ .Values.data.googleAudiences | quote}} {{- end }} diff --git a/devops/gcp/deploy/values.yaml b/devops/gcp/deploy/values.yaml index 4d8f306b1b99758414ffcc1a1d077d92ad6a3a87..c166b37a1d7beabad7c48215c8f5dd9fcbf82971 100644 --- a/devops/gcp/deploy/values.yaml +++ b/devops/gcp/deploy/values.yaml @@ -5,7 +5,6 @@ data: entitlementsHost: "http://entitlements" registerHost: "http://register" partitionHost: "http://partition" - googleAudiences: "" #Deployments requestsCpu: "0.1" requestsMemory: "256M" diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java index 900fd07d9e0acc1afc5dae1fff496ac39181b84c..6a882c419d24ed36ca98a9726c06e9b7ed5d5630 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java @@ -14,6 +14,7 @@ package org.opengroup.osdu.notification.provider.azure.messageBus; +import com.google.api.client.util.Strings; import com.microsoft.applicationinsights.TelemetryClient; import com.microsoft.applicationinsights.telemetry.RequestTelemetry; import com.microsoft.azure.servicebus.IMessage; @@ -59,13 +60,16 @@ public class ProcessNotification { String dataPartitionId = notificationContent.getExtractAttributes().get(DpsHeaders.DATA_PARTITION_ID); String correlationId = notificationContent.getExtractAttributes().get(DpsHeaders.CORRELATION_ID); - + String collaborationId = null; + if (notificationContent.getExtractAttributes().containsKey("x-collaboration")) + collaborationId = notificationContent.getExtractAttributes().get("x-collaboration"); ConcurrentMap properties = telemetryClient.getContext().getProperties(); properties.put("correlation-id",correlationId); - properties.put("data-partition-id", dataPartitionId); - - MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId)); - dpsHeaders.setThreadContext(dataPartitionId, correlationId); + properties.put("data-partition-id", dataPartitionId); + if (!Strings.isNullOrEmpty(collaborationId)) + properties.put("x-collaboration", collaborationId); + MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId, collaborationId)); + dpsHeaders.setThreadContext(dataPartitionId, correlationId, collaborationId); LOGGER.info("Notification process started for message with id: {}", message.getMessageId()); diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java index 070029c6be6fb7e2f73c50636d0047517fdaf57d..68ec87316d7845604d69149ee630b6b210015852 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java @@ -15,12 +15,15 @@ package org.opengroup.osdu.notification.provider.azure.messageBus.extractor; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.gson.Gson; import com.microsoft.azure.servicebus.IMessage; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.notification.provider.azure.models.NotificationRecordsChangedData; import org.opengroup.osdu.notification.provider.azure.models.NotificationServiceBusRequest; import org.opengroup.osdu.notification.provider.azure.messageBus.interfaces.IPullRequestBodyExtractor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; @@ -40,7 +43,6 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor private static final Gson GSON = new Gson(); private NotificationServiceBusRequest notificationRequest; private NotificationRecordsChangedData notificationRecordsChangedData; - public void InitializeExtractor(IMessage message) { this.message = message; @@ -53,6 +55,9 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor attributes.put("correlation-id", this.notificationRecordsChangedData.getCorrelationId()); attributes.put("data-partition-id", this.notificationRecordsChangedData.getDataPartitionId()); attributes.put("account-id", this.notificationRecordsChangedData.getAccountId()); + if (!Strings.isNullOrEmpty(this.notificationRecordsChangedData.getCollaborationDirectives())) { + attributes.put("x-collaboration", this.notificationRecordsChangedData.getCollaborationDirectives()); + } return attributes; } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java index b02fe38df5244618ca5cd0f9657c571780874598..ece84e176e2f462ca1788d0caeac741812fa28f9 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java @@ -22,6 +22,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Component; +import com.google.api.client.util.Strings; import java.util.HashMap; import java.util.Map; @@ -34,12 +35,14 @@ public class ThreadDpsHeaders extends DpsHeaders { @Autowired private IServiceAccountJwtClient serviceAccountJwtClient; - public void setThreadContext(String dataPartitionId, String correlationId) { + public void setThreadContext(String dataPartitionId, String correlationId, String collaborationId) { Map<String, String> headers = new HashMap<>(); headers.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); headers.put(DpsHeaders.CORRELATION_ID, correlationId); String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId); headers.put(DpsHeaders.AUTHORIZATION, authToken); + if (!Strings.isNullOrEmpty(collaborationId)) + headers.put("x-collaboration", collaborationId); this.addFromMap(headers); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java index 4d6b9e6c92ab0d23a5a9b843837e043691c07469..0f9b964487573745316d0a068f0367079f9a4a12 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java @@ -39,4 +39,7 @@ public class NotificationRecordsChangedData { @SerializedName("data-partition-id") private String dataPartitionId; + + @SerializedName("x-collaboration") + private String collaborationDirectives; } \ No newline at end of file diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java index 57c08cb18613784974dc7260041b3a44e693d6d2..82874ec4b59d8368d2814f287da31e4fd516dafb 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java @@ -14,6 +14,7 @@ package org.opengroup.osdu.notification.provider.azure.util; +import com.google.api.client.util.Strings; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import java.util.HashMap; @@ -21,10 +22,12 @@ import java.util.Map; public class MDCContextMap { - public Map<String, String> getContextMap(String correlationId, String dataPartitionId) { + public Map<String, String> getContextMap(String correlationId, String dataPartitionId, String collaborationId) { final Map<String, String> contextMap = new HashMap<>(); contextMap.put(DpsHeaders.CORRELATION_ID, correlationId); contextMap.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); + if (!Strings.isNullOrEmpty(collaborationId)) + contextMap.put("x-collaboration", collaborationId); return contextMap; } } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java index 789d76697846e64a8bd3b334b258903cc2ed8378..95852d80abb3dbb4b7d8f6b7111b13156cac58d8 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java @@ -70,8 +70,8 @@ public class ProcessNotificationTest { public void init() { requestAttributes.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); requestAttributes.put(DpsHeaders.CORRELATION_ID, correlationId); - lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId); - lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId)).thenReturn(new HashMap<>()); + lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId, null); + lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId, null)).thenReturn(new HashMap<>()); lenient().when(dpsHeaders.getHeaders()).thenReturn(requestAttributes); when(notificationContent.getExtractAttributes()).thenReturn(requestAttributes); when(notificationContent.getNotificationId()).thenReturn(notificationId); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java index 6f9729ecd25dabd2118d8adf33643928587e1c96..13810317a2181737a4c4a97c30a6787d5f044eb5 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java @@ -38,6 +38,7 @@ public class ServiceBusRequestBodyExtractorTest { private static final String dataPartitionId = "opendes"; private static final String correlationId = "908fcf8d-30c5-4c74-a0ae-ab47b48b7a85"; private static final String accountId = "ab47b48b7a85-30c5"; + private static final String collaborationDirectives = "id=9e1c4e74-3b9b-4b17-a0d5-67766558ec65,application=Test App"; @Test public void should_throwWhenAttributesAreMissing_extractDataFromRequestBody() { @@ -65,6 +66,7 @@ public class ServiceBusRequestBodyExtractorTest { Assert.assertEquals(attributes.get("account-id"), accountId); Assert.assertEquals(attributes.get("correlation-id"), correlationId); Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId); + Assert.assertEquals(attributes.get("x-collaboration"), null); } catch (Exception exception) { fail("Should not Throw AppException"); @@ -72,6 +74,38 @@ public class ServiceBusRequestBodyExtractorTest { } + @Test + public void shouldReturnNotificationDataAndAttributesWhenValidRequestBodyWithCollaborationDirectivesProvided() { + IMessage message = getValidMessageWithCollaborationDirectives(); + try { + sut.InitializeExtractor(message); + String notificationData = sut.extractDataFromRequestBody(); + Assert.assertEquals(notificationData, validData); + Map<String, String> attributes = sut.extractAttributesFromRequestBody(); + Assert.assertEquals(attributes.get("account-id"), accountId); + Assert.assertEquals(attributes.get("correlation-id"), correlationId); + Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId); + Assert.assertEquals(attributes.get("x-collaboration"), collaborationDirectives); + } catch (Exception exception) { + fail("Should not Throw AppException"); + } + } + + private Message getValidMessageWithCollaborationDirectives() { + String body = + " {\n" + + " \"message\": {\n" + + " \"data\":" + validData + ",\n" + + " \"account-id\": \"" + accountId + "\",\n" + + " \"correlation-id\": \"" + correlationId + "\",\n" + + " \"data-partition-id\": \"" + dataPartitionId + "\",\n" + + " \"x-collaboration\": \"" + collaborationDirectives + "\"\n" + + " }\n" + + " }"; + return new Message(body); + } + + private Message getValidMessage() { String body = diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java index 019bd18063d18b46bcb594ca809ba8ee987af5f7..a066b8f5cbc6fc4175f9ea9641b92d7b74653198 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java @@ -28,7 +28,7 @@ public class ThreadDpsHeadersTest { @Test public void setThreadContextTest() { try { - threadDpsHeaders.setThreadContext("opendes", "ut"); + threadDpsHeaders.setThreadContext("opendes", "ut", null); assertEquals(threadDpsHeaders.getHeaders().get("data-partition-id"),"opendes"); assertEquals(threadDpsHeaders.getHeaders().get("correlation-id"),"ut"); } catch (Exception e) { diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java index a0449810c6d928eaf3ea0ba96df115c4ff0c6352..53f7fe8cf064de034a6b8f5855dae9df1e173d3e 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java @@ -17,7 +17,7 @@ public class MDCContextMapTest { @Test public void getContextMapTest(){ - Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes"); + Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes", null); assertNotNull(contextMap); } } diff --git a/provider/notification-gcp/docs/gcp/README.md b/provider/notification-gcp/docs/gcp/README.md index c1418d03c5faeabc520b20546823e40bb99f00d1..4410de7f11253a29a1c1fc8562585a4bc7e92625 100644 --- a/provider/notification-gcp/docs/gcp/README.md +++ b/provider/notification-gcp/docs/gcp/README.md @@ -37,7 +37,6 @@ | name | value | description | sensitive? | source | |------------------------------|---------------------------------------|--------------------------------------------------------------------|------------|---------------------------------------------------| | `APP_PROJECT` | ex `opendes` | Google Cloud Project Id | no | output of infrastructure deployment | -| `GOOGLE_AUDIENCES` | ex `*****.apps.googleusercontent.com` | Client ID for getting access to cloud resources | yes | https://console.cloud.google.com/apis/credentials | ##### service account IAM roles Also, the following IAM roles should be assigned to the service's Google service account (SA) @@ -67,7 +66,6 @@ After the service has started it should be accessible via a web browser by visit | `HMAC_SECRET` | ex`7a786376626e` | String in hex , must match pattern ^[a-zA-Z0-9]{8,30}+$ & be in register variable SUBSCRIBER_SECRET | yes | - | | `REGISTER_BASE_URL` | `http://localhost:8081/api/register/v1` | Register service url | no | - | | `NOTIFICATION_BASE_URL` | `http://localhost:8080/api/notification/v1/` | Notification service url | no | - | -| `INTEGRATION_TEST_AUDIENCE` | `********` | Client application ID | yes | https://console.cloud.google.com/apis/credentials | | `CLIENT_TENANT` | ex `opendes` | Client tenant | no | - | | `OSDU_TENANT` | ex `osdu` | osdu tenant | no | - | | `TOPIC_ID` | ex `records-changed` | PubSub topic id | no | https://console.cloud.google.com/cloudpubsub/topic | diff --git a/provider/notification-gcp/pom.xml b/provider/notification-gcp/pom.xml index 5cb26371af09d3e07dfa64630f738fe59a1756dd..2d3000afc54ac246044e2581683b85c658a412bf 100644 --- a/provider/notification-gcp/pom.xml +++ b/provider/notification-gcp/pom.xml @@ -47,7 +47,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>core-lib-gcp</artifactId> - <version>0.18.0</version> + <version>0.19.0-rc3</version> </dependency> <dependency> diff --git a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/JwtValidity.java b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/JwtValidity.java index 2685b9e71eb34877ca1897820d368c6c83ac1f12..3890e3ef735076b280c76f93547d1a920f663363 100644 --- a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/JwtValidity.java +++ b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/JwtValidity.java @@ -1,19 +1,19 @@ /* - Copyright 2020 Google LLC - Copyright 2020 EPAM Systems, Inc + Copyright 2020-2023 Google LLC + Copyright 2020-2023 EPAM Systems, Inc - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package org.opengroup.osdu.notification.provider.gcp.util; @@ -24,11 +24,11 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class JwtValidity { - String token; - long expiryTime; + String token; + long expiryTime; - JwtValidity(String jwt, long expiryTime) { - this.token = jwt; - this.expiryTime = expiryTime; - } + JwtValidity(String jwt, long expiryTime) { + this.token = jwt; + this.expiryTime = expiryTime; + } } diff --git a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/ServiceAccountJwtGcpClientImpl.java b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/ServiceAccountJwtGcpClientImpl.java index 2c5af0c721ac74d11d331e0c946c394e959e15ed..4d5261b124dc88cfa3b5d39293a992d8c7dd2008 100644 --- a/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/ServiceAccountJwtGcpClientImpl.java +++ b/provider/notification-gcp/src/main/java/org/opengroup/osdu/notification/provider/gcp/util/ServiceAccountJwtGcpClientImpl.java @@ -1,19 +1,19 @@ /* - Copyright 2020 Google LLC - Copyright 2020 EPAM Systems, Inc + Copyright 2020-2023 Google LLC + Copyright 2020-2023 EPAM Systems, Inc - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ package org.opengroup.osdu.notification.provider.gcp.util; @@ -28,12 +28,10 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient { - private final TokenProvider tokenProvider; + private final TokenProvider tokenProvider; - public String getIdToken(String tenantName) { - log.debug("Tenant name received for auth token is: {}", tenantName); - return "Bearer " + tokenProvider.getIdToken(); - } + public String getIdToken(String tenantName) { + log.debug("Tenant name received for auth token is: {}", tenantName); + return "Bearer " + tokenProvider.getIdToken(); + } } - - diff --git a/provider/notification-gcp/src/main/resources/application-local.properties b/provider/notification-gcp/src/main/resources/application-local.properties index ec8e968641b1f3292063121e19e4241b6435d729..0aba93ff487d48d0c057d464b39a3c4437accc60 100644 --- a/provider/notification-gcp/src/main/resources/application-local.properties +++ b/provider/notification-gcp/src/main/resources/application-local.properties @@ -20,7 +20,6 @@ logging.level.org.springframework.web=${LOG_LEVEL:DEBUG} app.entitlements=https://community.gcp.gnrg-osdu.projects.epam.com/entitlements/v2 app.register=https://community.gcp.gnrg-osdu.projects.epam.com/api/register/v1 app.project=nice-etching-277309 -google-audiences=689762842995-pv217jo3k8j803kk6gqf52qb5amos3a9.apps.googleusercontent.com service.token.provider=GCP partition-auth-enabled=true diff --git a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java index 8f7655b27ddf731230131e91fedad90b67809763..accd832847e95fb6c1d55a3a5807abf6467b3db7 100644 --- a/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java +++ b/testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java @@ -37,7 +37,7 @@ public class Config { public static Config Instance() { String env = getEnvironment(); config.ClientTenant = getEnvironmentVariableOrDefaultValue("CLIENT_TENANT", "nonexistenttenant"); - config.IntegrationAudience = getEnvironmentVariableOrDefaultValue("INTEGRATION_TEST_AUDIENCE", "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com"); + config.IntegrationAudience = "osdu"; config.OsduTenant = getEnvironmentVariableOrDefaultValue("OSDU_TENANT", "opendes"); config.Topic = getEnvironmentVariableOrDefaultValue("TOPIC_ID", "records-changed"); config.TimeOutSeconds = getEnvironmentVariableOrDefaultValue("TIME_OUT_SECONDS", "60"); diff --git a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java index 639eeecb1e1c3084fbcc4256fce4b0cd7acfe909..dc7766bedd9bc24e24cbb1b956bbc7ec3e8ed5f9 100644 --- a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java +++ b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GCPTestUtils.java @@ -1,3 +1,20 @@ +/* + Copyright 2020-2023 Google LLC + Copyright 2020-2023 EPAM Systems, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package org.opengroup.osdu.notification.util; import com.google.common.base.Strings; @@ -6,50 +23,43 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class GCPTestUtils extends TestUtils { - public GCPTestUtils() { + public GCPTestUtils() {} + @Override + public synchronized String getOpsToken() throws Exception { + if (Strings.isNullOrEmpty(opsToken)) { + opsToken = getToken("DE_OPS_TESTER"); } + return opsToken; + } - @Override - public synchronized String getOpsToken() throws Exception { - if(Strings.isNullOrEmpty(opsToken)) { - opsToken = getToken("DE_OPS_TESTER"); - } - return opsToken; + @Override + public synchronized String getAdminToken() throws Exception { + if (Strings.isNullOrEmpty(adminToken)) { + adminToken = getToken("DE_ADMIN_TESTER"); } + return adminToken; + } - @Override - public synchronized String getAdminToken() throws Exception { - if(Strings.isNullOrEmpty(adminToken)) { - adminToken = getToken("DE_ADMIN_TESTER"); - } - return adminToken; + @Override + public synchronized String getEditorToken() throws Exception { + if (Strings.isNullOrEmpty(editorToken)) { + editorToken = getToken("DE_EDITOR_TESTER"); } + return editorToken; + } - @Override - public synchronized String getEditorToken() throws Exception { - if(Strings.isNullOrEmpty(editorToken)) { - editorToken = getToken("DE_EDITOR_TESTER"); - } - return editorToken; + @Override + public synchronized String getNoAccessToken() throws Exception { + if (Strings.isNullOrEmpty(noAccessToken)) { + noAccessToken = getToken("DE_NO_ACCESS_TESTER"); } + return noAccessToken; + } - @Override - public synchronized String getNoAccessToken() throws Exception { - if(Strings.isNullOrEmpty(noAccessToken)) { - noAccessToken = getToken("DE_NO_ACCESS_TESTER"); - } - return noAccessToken; - } - - private String getToken(String testerEnvVar) throws Exception { - log.info("Get {} credentials", testerEnvVar); - String serviceAccountValue = System.getProperty(testerEnvVar, System.getenv(testerEnvVar)); - String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE", System.getenv("INTEGRATION_TEST_AUDIENCE")); - if (Strings.isNullOrEmpty(audience)) { - audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com"; - } - String token = new GoogleServiceAccount(serviceAccountValue).getAuthToken(audience); - return "Bearer " + token; - } + private String getToken(String testerEnvVar) throws Exception { + String serviceAccountValue = System.getProperty(testerEnvVar, System.getenv(testerEnvVar)); + String token = new GoogleServiceAccount(serviceAccountValue).getAuthToken(); + return "Bearer " + token; + } } diff --git a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java index a7540b1a7bc70caca2d12843b1322cef2f0bbb39..ecee848946ee39bc5941f51696fb9d27728b7385 100644 --- a/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java +++ b/testing/notification-test-gcp/src/test/java/org/opengroup/osdu/notification/util/GoogleServiceAccount.java @@ -1,3 +1,20 @@ +/* + Copyright 2020-2023 Google LLC + Copyright 2020-2023 EPAM Systems, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package org.opengroup.osdu.notification.util; import com.google.auth.oauth2.ServiceAccountCredentials; @@ -21,63 +38,66 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Base64; import java.util.HashMap; import java.util.Map; import static org.opengroup.osdu.config.util.DecodedContentExtractorUtil.NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER; public class GoogleServiceAccount { - public GoogleServiceAccount(String serviceAccountValue)throws IOException { - serviceAccountValue = new DecodedContentExtractor(serviceAccountValue, NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER).getContent(); + public GoogleServiceAccount(String serviceAccountValue) throws IOException { + serviceAccountValue = + new DecodedContentExtractor(serviceAccountValue, NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER) + .getContent(); - try (InputStream inputStream = new ByteArrayInputStream(serviceAccountValue.getBytes())) { - this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream); - } + try (InputStream inputStream = new ByteArrayInputStream(serviceAccountValue.getBytes())) { + this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream); } + } - final ServiceAccountCredentials serviceAccount; + final ServiceAccountCredentials serviceAccount; - public String getEmail(){ - return serviceAccount.getClientEmail(); - } - public String getAuthToken(String audience) throws IOException { - JwtBuilder jwtBuilder = Jwts.builder(); - - Map<String, Object> header = new HashMap<>(); - header.put("type", "JWT"); - header.put("alg", "RS256"); - jwtBuilder.setHeader(header); - - Map<String, Object> claims = new HashMap<>(); - claims.put("target_audience", audience); - claims.put("exp", System.currentTimeMillis() / 1000 + 3600); - claims.put("iat", System.currentTimeMillis() / 1000); - claims.put("iss", getEmail()); - claims.put("aud", "https://www.googleapis.com/oauth2/v4/token"); - jwtBuilder.addClaims(claims); - - jwtBuilder.signWith(SignatureAlgorithm.RS256, serviceAccount.getPrivateKey()); - String jwt = jwtBuilder.compact(); - - HttpPost httpPost = new HttpPost("https://www.googleapis.com/oauth2/v4/token"); - - ArrayList<NameValuePair> postParameters = new ArrayList<>(); - postParameters.add(new BasicNameValuePair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")); - postParameters.add(new BasicNameValuePair("assertion", jwt)); - - HttpClient client = new DefaultHttpClient(); - - httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8")); - httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); - HttpResponse response = client.execute(httpPost); - - String responseEntity = EntityUtils.toString(response.getEntity()); - JsonObject content = new JsonParser().parse(responseEntity).getAsJsonObject(); - JsonElement auth = content.get("id_token"); - if(auth == null){ - throw new IOException("Failed to retrieve auth token for credentials " + jwt); - } - return auth.getAsString(); + public String getEmail() { + return serviceAccount.getClientEmail(); + } + + public String getAuthToken() throws IOException { + JwtBuilder jwtBuilder = Jwts.builder(); + + Map<String, Object> header = new HashMap<>(); + header.put("type", "JWT"); + header.put("alg", "RS256"); + jwtBuilder.setHeader(header); + + Map<String, Object> claims = new HashMap<>(); + claims.put("target_audience", "osdu"); + claims.put("exp", System.currentTimeMillis() / 1000 + 3600); + claims.put("iat", System.currentTimeMillis() / 1000); + claims.put("iss", getEmail()); + claims.put("aud", "https://www.googleapis.com/oauth2/v4/token"); + jwtBuilder.addClaims(claims); + + jwtBuilder.signWith(SignatureAlgorithm.RS256, serviceAccount.getPrivateKey()); + String jwt = jwtBuilder.compact(); + + HttpPost httpPost = new HttpPost("https://www.googleapis.com/oauth2/v4/token"); + + ArrayList<NameValuePair> postParameters = new ArrayList<>(); + postParameters.add( + new BasicNameValuePair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")); + postParameters.add(new BasicNameValuePair("assertion", jwt)); + + HttpClient client = new DefaultHttpClient(); + + httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8")); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + HttpResponse response = client.execute(httpPost); + + String responseEntity = EntityUtils.toString(response.getEntity()); + JsonObject content = new JsonParser().parse(responseEntity).getAsJsonObject(); + JsonElement auth = content.get("id_token"); + if (auth == null) { + throw new IOException("Failed to retrieve auth token for credentials " + jwt); } + return auth.getAsString(); + } }