diff --git a/provider/notification-aws/pom.xml b/provider/notification-aws/pom.xml index 119ab9cb9d568dcb657f014e07b4b65832574978..7b84df54c1df4b36ef8c992bf18dada25cb6b076 100644 --- a/provider/notification-aws/pom.xml +++ b/provider/notification-aws/pom.xml @@ -50,7 +50,7 @@ <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>os-core-lib-aws</artifactId> - <version>0.3.12</version> + <version>0.3.13-SNAPSHOT</version> </dependency> <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-secretsmanager --> diff --git a/provider/notification-aws/src/main/java/org/opengroup/osdu/notification/provider/aws/impl/ServiceAccountJwtAwsClientImpl.java b/provider/notification-aws/src/main/java/org/opengroup/osdu/notification/provider/aws/impl/ServiceAccountJwtAwsClientImpl.java index 04a2bd2dcc82b7372cd1dae27788d15e1822e5a1..02e2b91e7f64abc56a6ecafa648183337e4fe2df 100644 --- a/provider/notification-aws/src/main/java/org/opengroup/osdu/notification/provider/aws/impl/ServiceAccountJwtAwsClientImpl.java +++ b/provider/notification-aws/src/main/java/org/opengroup/osdu/notification/provider/aws/impl/ServiceAccountJwtAwsClientImpl.java @@ -13,15 +13,25 @@ package org.opengroup.osdu.notification.provider.aws.impl; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement; +import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder; +import com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest; +import com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult; +import com.amazonaws.services.simplesystemsmanagement.model.Parameter; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import org.opengroup.osdu.core.aws.entitlements.ServicePrincipal; +import org.opengroup.osdu.core.aws.iam.IAMConfig; +import org.opengroup.osdu.core.aws.secrets.SecretsManager; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; + @Component public class ServiceAccountJwtAwsClientImpl implements IServiceAccountJwtClient { @@ -46,12 +56,55 @@ public class ServiceAccountJwtAwsClientImpl implements IServiceAccountJwtClient public String environment; + @Value("${aws.tokenUrl}") + @Getter() + public String tokenUrl; + + @Value("${aws.oauth.custom.scope}") + @Getter() + private String awsOauthCustomScope; + + + + String client_credentials_secret; + String client_credentials_clientid; + ServicePrincipal sp; + + private AWSCredentialsProvider amazonAWSCredentials; + private AWSSimpleSystemsManagement ssmManager; + + @PostConstruct + public void init() { + if (ssmEnabled) { + + SecretsManager sm = new SecretsManager(); + sp = new ServicePrincipal(amazonRegion,environment,tokenUrl,awsOauthCustomScope); + + String client_credentials_client_id = "/osdu/" + environment + "/client-credentials-client-id"; + String client_secret_key = "client_credentials_client_secret"; + String client_secret_secretName = "/osdu/" + environment + "/client_credentials_secret"; + + amazonAWSCredentials = IAMConfig.amazonAWSCredentials(); + ssmManager = AWSSimpleSystemsManagementClientBuilder.standard() + .withCredentials(amazonAWSCredentials) + .withRegion(amazonRegion) + .build(); + + GetParameterRequest paramRequest = new GetParameterRequest() + .withName(client_credentials_client_id) + .withWithDecryption(true); + GetParameterResult paramResult = ssmManager.getParameter(paramRequest); + Parameter paramsResult = paramResult.getParameter(); + client_credentials_clientid = paramsResult.getValue(); + client_credentials_secret = sm.getSecret(client_secret_secretName,amazonRegion,client_secret_key); + + } + } @Override public String getIdToken(String s) { - ServicePrincipal sp = new ServicePrincipal(amazonRegion,environment); - String token= sp.getServicePrincipalAccessToken(); + String token= sp.getServicePrincipalAccessToken(client_credentials_clientid,client_credentials_secret); return token; } diff --git a/testing/notification-test-aws/pom.xml b/testing/notification-test-aws/pom.xml index 3743b6537cf655eab744d3f39423f468ae89f312..ae675c474810f1d4eb54ef7445fc6301424f2760 100644 --- a/testing/notification-test-aws/pom.xml +++ b/testing/notification-test-aws/pom.xml @@ -44,7 +44,7 @@ <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>os-core-lib-aws</artifactId> - <version>0.3.12</version> + <version>0.3.13-SNAPSHOT</version> </dependency> <dependency> <groupId>com.amazonaws</groupId>