diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..bacb052d60548b6b87af4147b65cbf1eef3d623f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +**/*.md +**/*.yml +**/*.yaml +**/Dockerfile* +.* diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..6313b56c57848efce05faa7aa7e901ccfc2886ea --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/devops/gcp/deploy/templates/service-account.yaml b/devops/gcp/deploy/templates/service-account.yaml index 61f46c8a5eab3b2e30ef8799b739cd9189561ca6..3fede170cb014a4cfdf8cc99d745a32eb66aeed0 100644 --- a/devops/gcp/deploy/templates/service-account.yaml +++ b/devops/gcp/deploy/templates/service-account.yaml @@ -1,7 +1,7 @@ -{{- if .Values.conf.on_prem_enabled }} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: "{{ .Values.data.serviceAccountName }}" - namespace: "{{ .Release.Namespace }}" -{{- end }} +{{- if .Values.conf.on_prem_enabled }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "{{ .Values.data.serviceAccountName }}" + namespace: "{{ .Release.Namespace }}" +{{- end }} diff --git a/provider/notification-aws/build-aws/Dockerfile b/provider/notification-aws/build-aws/Dockerfile index 9e95e62d6b983eb876317ca354aed7a6bd39a4c3..bacdf23dcc2d3acf06a71d04dbd2ca9830c9efc3 100644 --- a/provider/notification-aws/build-aws/Dockerfile +++ b/provider/notification-aws/build-aws/Dockerfile @@ -28,4 +28,4 @@ COPY /provider/notification-aws/build-aws/ssl.sh /ssl.sh COPY /provider/notification-aws/build-aws/entrypoint.sh /entrypoint.sh EXPOSE 8080 -ENTRYPOINT ["/bin/sh", "-c", ". /entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/sh", "-c", ". /entrypoint.sh"] diff --git a/provider/notification-gcp/docker/Dockerfile b/provider/notification-gcp/docker/Dockerfile deleted file mode 100644 index 2e68183f5ef17c071cb878ad1f15d61e39aac6db..0000000000000000000000000000000000000000 --- a/provider/notification-gcp/docker/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright 2017-2020, Schlumberger -# -# 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. -# - -FROM openjdk:8-slim -RUN apt-get update && apt-get install -y curl - -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -EXPOSE 8080 - -ARG JAR_FILE -COPY ${JAR_FILE} app.jar diff --git a/provider/notification-gcp/docker/docker-compose.yml b/provider/notification-gcp/docker/docker-compose.yml deleted file mode 100644 index 8eba335a332002ad9d3bd71416ad2106fef6bcd3..0000000000000000000000000000000000000000 --- a/provider/notification-gcp/docker/docker-compose.yml +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright 2017-2020, Schlumberger -# -# 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. -# - -version: "3" -services: - os-notification-app: - build: - args: - JAR_FILE: target/notification-gcp-1.0.0-spring-boot.jar - context: .. - dockerfile: docker/Dockerfile - image: gcr.io/opendes/os-notification-app - ports: - - "8080:8080" - diff --git a/provider/notification-gcp/docs/anthos/README.md b/provider/notification-gcp/docs/anthos/README.md index 65d3dc918cc1b5302695fc141f26dc9aba792fea..4c4dd42869d7b02f8b67b450571878088c4bcf97 100644 --- a/provider/notification-gcp/docs/anthos/README.md +++ b/provider/notification-gcp/docs/anthos/README.md @@ -1,15 +1,19 @@ # Service Configuration for Anthos ## Table of Contents <a name="TOC"></a> -* [Environment variables](#Environment-variables) - * [Common properties for all environments](#Common-properties-for-all-environments) - * [For Mappers to activate drivers](#For-Mappers-to-activate-drivers) -* [Requirements for requests](#Requirements-for-requests) -* [Configuring mappers Datasources](#Configuring-mappers-Datasources) - * [For OQM RabbitMQ](#For-OQM-RabbitMQ) - * [Exchanges and queues configuration](#Exchanges-and-queues-configuration) -* [Interaction with message brokers](#Interaction-with-message-brokers) -* [Keycloak configuration](#Keycloak-configuration) + +* [Service Configuration for Anthos](#service-configuration-for-anthos) + * [Table of Contents <a name="TOC"></a>](#table-of-contents-) + * [Environment variables](#environment-variables) + * [Common properties for all environments](#common-properties-for-all-environments) + * [For Mappers to activate drivers](#for-mappers-to-activate-drivers) + * [Requirements for requests](#requirements-for-requests) + * [Configuring mappers Datasources](#configuring-mappers-datasources) + * [For OQM RabbitMQ](#for-oqm-rabbitmq) + * [Exchanges and queues configuration](#exchanges-and-queues-configuration) + * [Interaction with message brokers](#interaction-with-message-brokers) + * [Specifics of work through PULL subscription](#specifics-of-work-through-pull-subscription) + * [Keycloak configuration](#keycloak-configuration) ## Environment variables @@ -45,7 +49,7 @@ Record identifiers cannot contain a space character. At the same time, they may combined with subsequent numeric characters, may cause the application to misinterpret that combination. For example, the "%20" combination will be interpreted as a space " " character. To correctly transfer such an identifier, you should additionally perform the url-encode operation on it. This functionality can be built into the front-end application, or -you can use an online url-encoder tool ( eg.: https://www.urlencoder.org/). Thus, having ID "osdu: +you can use an online url-encoder tool ( eg.: <https://www.urlencoder.org/>). Thus, having ID "osdu: work-product-component--WellboreMarkerSet:3D%20Kirchhoff%20DepthMigration" (with %20 combination) you should url-encode it and request "osdu%3Awork-product-component--WellboreMarkerSet%3A3D%2520Kirchhoff%2520DepthMigration" instead. @@ -60,8 +64,8 @@ PartitionInfo for each Tenant. **prefix:** `oqm.rabbitmq` It can be overridden by: -- through the Spring Boot property `oqm.rabbitmq.partition-properties-prefix` -- environment variable `OQM_RABBITMQ_PARTITION_PROPERTIES_PREFIX`` +* through the Spring Boot property `oqm.rabbitmq.partition-properties-prefix` +* environment variable `OQM_RABBITMQ_PARTITION_PROPERTIES_PREFIX`` **Propertyset** (for two types of connection: messaging and admin operations): @@ -145,8 +149,8 @@ At RabbitMq should be created exchange with name: It can be overridden by: -- through the Spring Boot property `oqm-register-subscriber-control-topic-name` -- environment variable `OQM_REGISTER_SUBSCRIBER_CONTROL_TOPIC_NAME` +* through the Spring Boot property `oqm-register-subscriber-control-topic-name` +* environment variable `OQM_REGISTER_SUBSCRIBER_CONTROL_TOPIC_NAME`  @@ -175,4 +179,4 @@ Each Client has embedded Service Account (SA) option. Enable SAs for Clients, ma Add `partition-and-entitlements` scope to `Default Client Scopes` and generate Keys. -Give `client-id` and `client-secret` to services, which should be authorized within the platform. \ No newline at end of file +Give `client-id` and `client-secret` to services, which should be authorized within the platform. diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/Application.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/Application.java index 595a25c7fb367251c02bf3a0bd1dd115c180f3b2..57d8d1a57591bc7c53e33a4d8f65e4546c0c7f17 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/Application.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/Application.java @@ -1,20 +1,20 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - -package org.opengroup.osdu.notification.provider.ibm; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableAsync; - -@SpringBootApplication -@ComponentScan({"org.opengroup.osdu"}) -@EnableAsync -public class Application { - - public static void main(String[] args) { - SpringApplication.run(new Class[] { Application.class} , args); - } -} - +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + +package org.opengroup.osdu.notification.provider.ibm; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@ComponentScan({"org.opengroup.osdu"}) +@EnableAsync +public class Application { + + public static void main(String[] args) { + SpringApplication.run(new Class[] { Application.class} , args); + } +} + diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/di/ServiceAccountJwtClientFactory.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/di/ServiceAccountJwtClientFactory.java index 9acd6a3efe2e5eab5aec819e71afd0b030bebc3c..6c29c213d9ee78a5623a443a6960a8b383cff112 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/di/ServiceAccountJwtClientFactory.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/di/ServiceAccountJwtClientFactory.java @@ -1,25 +1,25 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - -package org.opengroup.osdu.notification.provider.ibm.di; -import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; -import org.opengroup.osdu.notification.provider.ibm.util.AppProperties; -import org.opengroup.osdu.notification.provider.ibm.util.ServiceAccountJwtIBMClientImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.stereotype.Component; - - -public class ServiceAccountJwtClientFactory extends AbstractFactoryBean<IServiceAccountJwtClient> { - - - @Override - public IServiceAccountJwtClient createInstance() throws Exception { - return new ServiceAccountJwtIBMClientImpl(); - } - - @Override - public Class<?> getObjectType() { - return IServiceAccountJwtClient.class; - } -} +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + +package org.opengroup.osdu.notification.provider.ibm.di; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.notification.provider.ibm.util.AppProperties; +import org.opengroup.osdu.notification.provider.ibm.util.ServiceAccountJwtIBMClientImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.springframework.stereotype.Component; + + +public class ServiceAccountJwtClientFactory extends AbstractFactoryBean<IServiceAccountJwtClient> { + + + @Override + public IServiceAccountJwtClient createInstance() throws Exception { + return new ServiceAccountJwtIBMClientImpl(); + } + + @Override + public Class<?> getObjectType() { + return IServiceAccountJwtClient.class; + } +} diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/AppProperties.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/AppProperties.java index bb9bdcc5422c06c2e300e8a59f7add13315ba509..f69c72405bc3b76828c0e78bf1fded5d57f64cca 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/AppProperties.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/AppProperties.java @@ -1,33 +1,33 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - - -package org.opengroup.osdu.notification.provider.ibm.util; - -import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class AppProperties implements IAppProperties { - - @Value("${app.entitlements}") - private String authorizeAPI; - @Value("${app.register}") - private String registerAPI; - @Value("${app.expireTime}") - private int expireTime; - @Value("${app.maxCacheSize}") - private int maxCacheSize; - - - public String getAuthorizeAPI() { - return authorizeAPI; - } - - public String getRegisterAPI() { - return registerAPI; - } - - -} +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + + +package org.opengroup.osdu.notification.provider.ibm.util; + +import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class AppProperties implements IAppProperties { + + @Value("${app.entitlements}") + private String authorizeAPI; + @Value("${app.register}") + private String registerAPI; + @Value("${app.expireTime}") + private int expireTime; + @Value("${app.maxCacheSize}") + private int maxCacheSize; + + + public String getAuthorizeAPI() { + return authorizeAPI; + } + + public String getRegisterAPI() { + return registerAPI; + } + + +} diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/GoogleServiceAccountImpl.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/GoogleServiceAccountImpl.java index f5740524f19563f0b4d2ce12e175e6795289db0c..3d3c32c0354e4504af3b53cb1ffec7b4c2db759b 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/GoogleServiceAccountImpl.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/GoogleServiceAccountImpl.java @@ -1,24 +1,24 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - - -package org.opengroup.osdu.notification.provider.ibm.util; - -import org.apache.http.impl.client.CloseableHttpClient; -//import org.opengroup.osdu.core.gcp.GoogleIdToken.IGoogleIdTokenFactory; -import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import lombok.SneakyThrows; - -@Component -public class GoogleServiceAccountImpl implements IGoogleServiceAccount { - - @SneakyThrows - @Override - public String getIdToken(String keyString, String audience) { - // TODO for GSA token validation check whether we have to impl - return "token";//this.googleIdTokenFactory.getGoogleIdToken(keyString, audience, this.closeableHttpClient); - } -} \ No newline at end of file +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + + +package org.opengroup.osdu.notification.provider.ibm.util; + +import org.apache.http.impl.client.CloseableHttpClient; +//import org.opengroup.osdu.core.gcp.GoogleIdToken.IGoogleIdTokenFactory; +import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import lombok.SneakyThrows; + +@Component +public class GoogleServiceAccountImpl implements IGoogleServiceAccount { + + @SneakyThrows + @Override + public String getIdToken(String keyString, String audience) { + // TODO for GSA token validation check whether we have to impl + return "token";//this.googleIdTokenFactory.getGoogleIdToken(keyString, audience, this.closeableHttpClient); + } +} diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java index 98ba70dd8d0098b1415ec3c175fa9e11d2cb679a..47ad624e24f03010fa1ee32fec5d4fd678d6e580 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/IBMServiceAccountValidatorImpl.java @@ -1,33 +1,33 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - - -package org.opengroup.osdu.notification.provider.ibm.util; - -import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; -import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; -import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson2.JacksonFactory; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class IBMServiceAccountValidatorImpl implements IServiceAccountValidator { - - - @Override - public boolean isValidPublisherServiceAccount(String jwt) { - //call isValidServiceAccount() - // Check whether IBM have to implement the service account verification for PubSub Role - // Marking it to return true, for the integration tests. - return false; - } - - @Override - public boolean isValidServiceAccount(String jwt, String userIdentity, String... googleAudiences) { - // Marking it to return true, for the integration tests. - return true; - } -} +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + + +package org.opengroup.osdu.notification.provider.ibm.util; + +import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; +import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.jackson2.JacksonFactory; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class IBMServiceAccountValidatorImpl implements IServiceAccountValidator { + + + @Override + public boolean isValidPublisherServiceAccount(String jwt) { + //call isValidServiceAccount() + // Check whether IBM have to implement the service account verification for PubSub Role + // Marking it to return true, for the integration tests. + return false; + } + + @Override + public boolean isValidServiceAccount(String jwt, String userIdentity, String... googleAudiences) { + // Marking it to return true, for the integration tests. + return true; + } +} diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/JwtValidity.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/JwtValidity.java index cee13c181f98c264c91f781e3f68c7cc00bab44c..38073f50afc2c47cc1b490073ab5c904168e9207 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/JwtValidity.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/JwtValidity.java @@ -1,22 +1,22 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - - - -package org.opengroup.osdu.notification.provider.ibm.util; - -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class JwtValidity { - - String token; - long expiryTime; - - JwtValidity(String jwt, long expiryTime) { - this.token = jwt; - this.expiryTime = expiryTime; - } -} +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + + + +package org.opengroup.osdu.notification.provider.ibm.util; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class JwtValidity { + + String token; + long expiryTime; + + JwtValidity(String jwt, long expiryTime) { + this.token = jwt; + this.expiryTime = expiryTime; + } +} diff --git a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/ServiceAccountJwtIBMClientImpl.java b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/ServiceAccountJwtIBMClientImpl.java index 81cfbdf7ca4af19f2aaac5b8c4c92ce1dd3e83a0..97cd0fb273b575cc354aa36c8937940700eba264 100644 --- a/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/ServiceAccountJwtIBMClientImpl.java +++ b/provider/notification-ibm/src/main/java/org/opengroup/osdu/notification/provider/ibm/util/ServiceAccountJwtIBMClientImpl.java @@ -1,140 +1,140 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - - -package org.opengroup.osdu.notification.provider.ibm.util; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; - -import javax.net.ssl.HttpsURLConnection; - -import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; -import org.opengroup.osdu.core.ibm.util.KeyCloakProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -public class ServiceAccountJwtIBMClientImpl implements IServiceAccountJwtClient { - - //private AppProperties config; - /*@Autowired - JaxRsDpsLog log;*/ - @Value("${keycloak.url}") - private String url; - @Value("${keycloak.realm}") - private String realm; - @Value("${keycloak.client_id}") - private String client_id; - @Value("${keycloak.client_secert}") - private String client_secret; - private String grant_type = "password"; - @Value("${keycloak.user}") - private String user; - @Value("${keycloak.password}") - private String pwd; - -/* public ServiceAccountJwtIBMClientImpl(AppProperties config) { - if (config == null) { - throw new IllegalArgumentException("AppProperties is null when initializing jwt client."); - } else { - this.config = config; - } - }*/ - - @Override - public String getIdToken(String tenantName) { - /* String t1=null; - try { - t1=KeyCloakProvider.getToken(user, pwd); - System.out.println("************t1 "+t1); - return "Bearer "+t1; - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - }*/ - String token_endpoint = String.format("https://%s/auth/realms/%s/protocol/openid-connect/token", url, realm); - URL url; - String token = null; - HttpsURLConnection con; - try { - url = new URL(token_endpoint); - con = (HttpsURLConnection) url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - Map<String, String> parameters = new HashMap<>(); - parameters.put("grant_type", grant_type); - parameters.put("client_id", client_id); - parameters.put("client_secret", client_secret); - parameters.put("username", user); - parameters.put("password", pwd); - - con.setDoOutput(true); - DataOutputStream out = new DataOutputStream(con.getOutputStream()); - out.writeBytes(getParamsString(parameters)); - out.flush(); - out.close(); - - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuffer content = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); - - con.disconnect(); - - Gson gson = new Gson(); - JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); - token = jobj.get("access_token").getAsString(); - token = "Bearer "+token; - } catch (MalformedURLException e) { - log.error("MalformedURLException while generating token"+e.getMessage()); - e.printStackTrace(); - } catch (IOException e) { - log.error("IOException while generating token"+e.getMessage()); - throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Provided invalid details", "Error generating token"); - } - return token; - // TODO : Implement jwtCache for storing generated token - } - - private static String getParamsString(Map<String, String> params) - throws UnsupportedEncodingException { - StringBuilder result = new StringBuilder(); - - for (Map.Entry<String, String> entry : params.entrySet()) { - result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); - result.append("="); - result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); - result.append("&"); - } - - String resultString = result.toString(); - return resultString.length() > 0 - ? resultString.substring(0, resultString.length() - 1) - : resultString; - } - -} - - +/* Licensed Materials - Property of IBM */ +/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ + + +package org.opengroup.osdu.notification.provider.ibm.util; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; + +import javax.net.ssl.HttpsURLConnection; + +import org.apache.http.HttpStatus; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.core.ibm.util.KeyCloakProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class ServiceAccountJwtIBMClientImpl implements IServiceAccountJwtClient { + + //private AppProperties config; + /*@Autowired + JaxRsDpsLog log;*/ + @Value("${keycloak.url}") + private String url; + @Value("${keycloak.realm}") + private String realm; + @Value("${keycloak.client_id}") + private String client_id; + @Value("${keycloak.client_secert}") + private String client_secret; + private String grant_type = "password"; + @Value("${keycloak.user}") + private String user; + @Value("${keycloak.password}") + private String pwd; + +/* public ServiceAccountJwtIBMClientImpl(AppProperties config) { + if (config == null) { + throw new IllegalArgumentException("AppProperties is null when initializing jwt client."); + } else { + this.config = config; + } + }*/ + + @Override + public String getIdToken(String tenantName) { + /* String t1=null; + try { + t1=KeyCloakProvider.getToken(user, pwd); + System.out.println("************t1 "+t1); + return "Bearer "+t1; + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + String token_endpoint = String.format("https://%s/auth/realms/%s/protocol/openid-connect/token", url, realm); + URL url; + String token = null; + HttpsURLConnection con; + try { + url = new URL(token_endpoint); + con = (HttpsURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + Map<String, String> parameters = new HashMap<>(); + parameters.put("grant_type", grant_type); + parameters.put("client_id", client_id); + parameters.put("client_secret", client_secret); + parameters.put("username", user); + parameters.put("password", pwd); + + con.setDoOutput(true); + DataOutputStream out = new DataOutputStream(con.getOutputStream()); + out.writeBytes(getParamsString(parameters)); + out.flush(); + out.close(); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + con.disconnect(); + + Gson gson = new Gson(); + JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); + token = jobj.get("access_token").getAsString(); + token = "Bearer "+token; + } catch (MalformedURLException e) { + log.error("MalformedURLException while generating token"+e.getMessage()); + e.printStackTrace(); + } catch (IOException e) { + log.error("IOException while generating token"+e.getMessage()); + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Provided invalid details", "Error generating token"); + } + return token; + // TODO : Implement jwtCache for storing generated token + } + + private static String getParamsString(Map<String, String> params) + throws UnsupportedEncodingException { + StringBuilder result = new StringBuilder(); + + for (Map.Entry<String, String> entry : params.entrySet()) { + result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + result.append("="); + result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); + result.append("&"); + } + + String resultString = result.toString(); + return resultString.length() > 0 + ? resultString.substring(0, resultString.length() - 1) + : resultString; + } + +} + + diff --git a/provider/notification-ibm/src/main/resources/application.properties b/provider/notification-ibm/src/main/resources/application.properties index da5dcf415d247c231f4289c80a1e9a05dea0ecf0..197165f2a68519e6b8bbb1bc8b3ad92b9a443e66 100644 --- a/provider/notification-ibm/src/main/resources/application.properties +++ b/provider/notification-ibm/src/main/resources/application.properties @@ -1,12 +1,12 @@ - - -LOG_PREFIX=notification -server.servlet.contextPath=/ -app.expireTime=300 -app.maxCacheSize=10 -server.error.whitelabel.enabled=false - -keycloak.url=TODO -keycloak.realm=TODO -keycloak.client_id=TODO -keycloak.client_secert=TODO \ No newline at end of file + + +LOG_PREFIX=notification +server.servlet.contextPath=/ +app.expireTime=300 +app.maxCacheSize=10 +server.error.whitelabel.enabled=false + +keycloak.url=TODO +keycloak.realm=TODO +keycloak.client_id=TODO +keycloak.client_secert=TODO