Commit e718ddf7 authored by Rucha Deshpande's avatar Rucha Deshpande
Browse files

Add Register Integration tests

commit 7277a94e 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 10:20:05 GMT-0500 (Central Daylight Time) 

    Addng ENVIRONMENT variable


commit 7e854a11 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 09:57:38 GMT-0500 (Central Daylight Time) 

    used logger


commit 5dea70b1 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 09:31:27 GMT-0500 (Central Daylight Time) 

    Bug Fix: flushing httpReponse buffer


commit ccb26905 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 08:06:39 GMT-0500 (Central Daylight Time) 

    Removing commented code


commit 97b7e028 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 07:55:55 GMT-0500 (Central Daylight Time) 

    Removed commented code


commit 9f8a300b 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 12 2020 07:44:46 GMT-0500 (Central Daylight Time) 

    Remove debug prints


commit 8e02aa46 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Sun Oct 11 2020 09:21:00 GMT-0500 (Central Daylight Time) 

    add prefix to debug stmt


commit 264298d2 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Sun Oct 11 2020 09:18:06 GMT-0500 (Central Daylight Time) 

    Adding debug prints


commit 0415c8ec 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Sat Oct 10 2020 15:35:15 GMT-0500 (Central Daylight Time) 

    Adding some prints


commit d855fa6a 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Fri Oct 09 2020 12:09:11 GMT-0500 (Central Daylight Time) 

    enable int tests in pipeline


commit a029c439 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Fri Oct 09 2020 11:14:23 GMT-0500 (Central Daylight Time) 

    Update env var name and remove print statements


commit fc72f144 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Fri Oct 09 2020 09:32:08 GMT-0500 (Central Daylight Time) 

    Bug Fix: int tests


commit 02f774a1 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 08 2020 13:40:52 GMT-0500 (Central Daylight Time) 

    Fix for int tests


commit 242e6a80 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 08 2020 10:48:35 GMT-0500 (Central Daylight Time) 

    Bug fix


commit 436ffaee 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 08 2020 09:53:43 GMT-0500 (Central Daylight Time) 

    using coore-lib 0.3.10


commit 63dcc6f8 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 08 2020 09:36:07 GMT-0500 (Central Daylight Time) 

    skipping Mongo health check


commit 28d3b094 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 16:51:53 GMT-0500 (Central Daylight Time) 

    Using latest os-core-lib-aws artifact


commit b942ad1a 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 15:52:42 GMT-0500 (Central Daylight Time) 

    Bug fixes for int tests


commit c9be3d47 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 13:13:09 GMT-0500 (Central Daylight Time) 

    Bug fix


commit 4b04690a 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 11:01:52 GMT-0500 (Central Daylight Time) 

    Bug fix


commit 2d9a2197 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 10:59:07 GMT-0500 (Central Daylight Time) 

    Add AWS test listener and add env vars for push path


commit eb5b75f0 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 09:54:27 GMT-0500 (Central Daylight Time) 

    Bug fix


commit 7d9920e1 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 09:44:58 GMT-0500 (Central Daylight Time) 

    Bug fix


commit ba4dff33 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Wed Oct 07 2020 07:05:19 GMT-0500 (Central Daylight Time) 

    Save encrypted secret as ByteBuffer instead of String


commit 73a0557f 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Tue Oct 06 2020 14:40:50 GMT-0500 (Central Daylight Time) 

    BugFux: test-core - Create subscription id dynamically for int test


commit a244b3fb 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Tue Oct 06 2020 11:34:47 GMT-0500 (Central Daylight Time) 

    int tests bug fixes


commit 3bd87fcf 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Mon Oct 05 2020 17:02:28 GMT-0500 (Central Daylight Time) 

    Int tests update


commit d6ca3715 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 01 2020 12:36:28 GMT-0500 (Central Daylight Time) 

    Add int tests1


commit 01a32c8b 
Author: Rucha Deshpande <deshruch@amazon.com> 
Date: Thu Oct 01 2020 10:39:54 GMT-0500 (Central Daylight Time) 

    save epoch as string in DynamoDB
parent 252849b1
......@@ -16,6 +16,8 @@
FROM amazoncorretto:8
ARG JAR_FILE=provider/register-aws/target/*spring-boot.jar
# Harcoding this value since Register-core requires this variable. AWS does not use it. Might change in future
ENV ENVIRONMENT=DEV
WORKDIR /
COPY ${JAR_FILE} app.jar
EXPOSE 8080
......
......@@ -53,8 +53,8 @@ phases:
- echo "Building primary service assemblies..."
- mvn -B test install -pl register-core,provider/register-aws -Ddeployment.environment=prod
#- echo "Building integration testing assemblies and gathering artifacts..."
#- ./testing/storage-test-aws/build-aws/prepare-dist.sh
- echo "Building integration testing assemblies and gathering artifacts..."
- ./testing/register-test-aws/build-aws/prepare-dist.sh
- echo "Building docker image..."
- docker build -f provider/register-aws/build-aws/Dockerfile -t ${ECR_IMAGE} .
......
......@@ -66,7 +66,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.3.7</version>
<version>0.3.11-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -50,7 +50,7 @@ public class ActionDoc {
private String contactEmail;
@DynamoDBAttribute(attributeName = "createdOnEpoch")
private Timestamp createdOnEpoch;
private String createdOnEpoch;
@DynamoDBAttribute(attributeName = "dataPartitionId")
private String dataPartitionId;
......@@ -92,7 +92,7 @@ public class ActionDoc {
.url(action.getUrl())
.contactEmail(action.getContactEmail())
.filter(action.getFilter())
.createdOnEpoch(new Timestamp(System.currentTimeMillis()))
.createdOnEpoch((new Timestamp(System.currentTimeMillis())).toString())
.dataPartitionId(dataPartitionId);
return actionDocBuilder.build();
......@@ -107,10 +107,17 @@ public class ActionDoc {
action.setImg(actionDoc.getImg());
action.setUrl(actionDoc.getUrl());
action.setContactEmail(actionDoc.getContactEmail());
action.setCreatedOnEpoch(com.google.cloud.Timestamp.of(actionDoc.getCreatedOnEpoch()));
Timestamp sqlTimestamp = Timestamp.valueOf(actionDoc.getCreatedOnEpoch());
com.google.cloud.Timestamp t = com.google.cloud.Timestamp.of(sqlTimestamp);
action.setCreatedOnEpoch(t);
action.setFilter(actionDoc.getFilter());
return action;
}
}
......@@ -14,13 +14,16 @@
package org.opengroup.osdu.register.provider.aws.action;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.opengroup.osdu.register.provider.aws.util.DocUtil;
import org.opengroup.osdu.register.provider.interfaces.action.IActionRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
......@@ -48,6 +51,10 @@ public class AwsActionRepo implements IActionRepo {
private DynamoDBQueryHelper queryHelper;
@Autowired
DocUtil docUtil;
@PostConstruct
public void init() {
queryHelper = new DynamoDBQueryHelper(serviceConfig.getDynamoDbEndpoint(),
......@@ -91,39 +98,42 @@ public class AwsActionRepo implements IActionRepo {
ActionDoc doc = ActionDoc.mapFrom(action, dpsHeaders.getPartitionId());
try {
queryHelper.save(doc);
queryHelper.saveWithHashCondition(doc,docUtil.getHashKey());
}
catch (AppException e) {
if(e.getError().getCode() == 409) {
logger.error(String.format("An action already exists with the id: %s", action.getId()));
throw new AppException(409, "Conflict", String.format("An action already exists with the id: %s", action.getId()));
}
else {
logger.error(e.getMessage());
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("An action already exists with the id: %s", action.getId()));
throw new AppException(409, "Conflict", String.format("An action already exists with the id: %s", action.getId()));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return action;
}
@Override
public boolean delete(String id) {
try {
queryHelper.deleteByPrimaryKey(ActionDoc.class, id);
}catch (AppException e) {
if(e.getError().getCode() == 404) {
logger.error(String.format("Action with id %s does not exist.", id));
}
else {
logger.error(e.getMessage());
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return false;
}
return true;
try{
ActionDoc objectTodelete = new ActionDoc();
objectTodelete.setId(id);
DynamoDBDeleteExpression deleteExpression = new DynamoDBDeleteExpression()
.withConditionExpression("attribute_exists(id)");
queryHelper.deleteByObjectWithCondition(objectTodelete,deleteExpression);
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("Failed to delete: %s Object does not exist",id));
throw new AppException(404, "ObjectNotFound", String.format("The Action you are trying to delete: %s does not exist", id));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return true;
}
@Override
public Action get(String id){
ActionDoc doc = queryHelper.loadByPrimaryKey(ActionDoc.class, id);
......@@ -136,4 +146,5 @@ public class AwsActionRepo implements IActionRepo {
}
}
......@@ -14,11 +14,15 @@
package org.opengroup.osdu.register.provider.aws.config;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.sns.AmazonSNS;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.core.aws.ssm.ParameterStorePropertySource;
import org.opengroup.osdu.core.aws.ssm.SSMConfig;
import org.opengroup.osdu.register.provider.aws.subscriber.KmsConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -49,22 +53,6 @@ public class AwsServiceConfig {
@Setter(AccessLevel.PROTECTED)
public Boolean ssmEnabled;
@Value("${aws.register.sns.topic.arn}")
@Getter()
private String snsTopicArn;
/*@Value("${aws.register.kms.key.arn}")
@Getter()
private String kmsKeyArn;*/
@Value("${aws.register.kms.key.id}")
@Getter()
@Setter(AccessLevel.PROTECTED)
private String kmsKeyId;
@Value("${aws.kms.endpoint}")
@Getter()
@Setter(AccessLevel.PROTECTED)
......@@ -76,25 +64,37 @@ public class AwsServiceConfig {
@Setter(AccessLevel.PROTECTED)
public String environment;
@Getter()
public String kmsKeyId;
/*@Inject
protected JaxRsDpsLog logger;*/
@Getter()
public String snsTopicArn;
@Getter()
public AWSKMS kmsClient;
@Getter()
public AmazonSNS snsClient;
@PostConstruct
public void init() {
if (ssmEnabled) {
//Can be used to retrieve ssm parameters
SSMConfig ssmConfig = new SSMConfig();
ParameterStorePropertySource ssm = ssmConfig.amazonSSM();
String keyssmparameter = "/osdu/" + environment + "/register/register-kms-key-id";
try {
//Can be used to retrieve ssm parameters
SSMConfig ssmConfig = new SSMConfig();
ParameterStorePropertySource ssm = ssmConfig.amazonSSM();
String keyssmparameter = "/osdu/" + environment + "/register/register-kms-key-id";
String snstopicArnParameter = "/osdu/" + environment + "/register/register-sns-topic-arn";
kmsKeyId = ssm.getProperty(keyssmparameter).toString();
snsTopicArn=ssm.getProperty(snstopicArnParameter).toString();
AmazonSNSConfig snsConfig = new AmazonSNSConfig(amazonRegion);
snsClient = snsConfig.AmazonSNS();
KmsConfig kmsConfig = new KmsConfig(kmsEndpoint, amazonRegion);
kmsClient = kmsConfig.awsKMS();
} catch (Exception e) {
System.out.println(String.format("SSM property %s not found", keyssmparameter));
}
System.out.println("SSM property not found");
System.out.println("Error while initializing AwsServiceConfig"+e.getMessage());
}
}
}
......
......@@ -14,7 +14,9 @@
package org.opengroup.osdu.register.provider.aws.ddms;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -47,7 +49,10 @@ public class AwsDdmsRepo implements IDdmsRepository {
private DynamoDBQueryHelper queryHelper;
DocUtil docUtil = new DocUtil();
@Autowired
DocUtil docUtil;
@PostConstruct
public void init() {
......@@ -61,17 +66,16 @@ public class AwsDdmsRepo implements IDdmsRepository {
public Ddms create(Ddms ddms) {
DdmsDoc doc = DdmsDoc.mapFrom(ddms, dpsHeaders.getPartitionId());
try {
queryHelper.save(doc);
queryHelper.saveWithHashCondition(doc,docUtil.getHashKey());
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("An DDMS already exists with the id: %s", ddms.getId()));
throw new AppException(409, "Conflict", String.format("An DDMS already exists with the id: %s", ddms.getId()));
}
catch (AppException e) {
if(e.getError().getCode() == 409) {
logger.error(String.format("A DDMS already exists with the same id: %s", ddms.getId()));
throw new AppException(409, "Conflict", String.format("A DDMS already exists with the same id: %s", ddms.getId()));
}
else {
logger.error(e.getMessage());
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return ddms;
......@@ -105,20 +109,26 @@ public class AwsDdmsRepo implements IDdmsRepository {
}
@Override
public boolean delete(String id){
try {
queryHelper.deleteByPrimaryKey(DdmsDoc.class, id);
}catch (AppException e) {
if(e.getError().getCode() == 404) {
logger.error(String.format("Ddms with id %s does not exist.", id));
}
else {
logger.error(e.getMessage());
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return false;
public boolean delete(String id) {
try{
DdmsDoc objectTodelete = new DdmsDoc();
objectTodelete.setId(id);
DynamoDBDeleteExpression deleteExpression = new DynamoDBDeleteExpression()
.withConditionExpression("attribute_exists(id)");
queryHelper.deleteByObjectWithCondition(objectTodelete,deleteExpression);
}
catch(ConditionalCheckFailedException e){
logger.error(String.format("Failed to delete: %s Object does not exist",id));
throw new AppException(404, "ObjectNotFound", String.format("The Ddms you are trying to delete: %s does not exist", id));
}
catch(AppException e)
{
throw new AppException(e.getError().getCode(), e.getError().getReason(), e.getMessage());
}
return true;
}
}
......@@ -45,7 +45,7 @@ public class DdmsDoc {
private String contactEmail;
@DynamoDBAttribute(attributeName = "createdDateTimeEpoch")
private Timestamp createdDateTimeEpoch;
private String createdDateTimeEpoch;
@DynamoDBAttribute(attributeName = "dataPartitionId")
private String dataPartitionId;
......@@ -89,7 +89,7 @@ public class DdmsDoc {
.name(ddms.getName())
.description(ddms.getDescription())
.contactEmail(ddms.getContactEmail())
.createdDateTimeEpoch(new Timestamp(System.currentTimeMillis()))
.createdDateTimeEpoch((new Timestamp(System.currentTimeMillis())).toString())
.interfaces(ddms.getInterfaces())
.dataPartitionId(dataPartitionId)
.partitionIdEntityType(String.format("%s:%s",dataPartitionId,getEntityType(ddms)));
......@@ -104,8 +104,9 @@ public class DdmsDoc {
ddms.setName(ddmsDoc.getName());
ddms.setDescription(ddmsDoc.getDescription());
ddms.setContactEmail(ddmsDoc.getContactEmail());
ddms.setCreatedDateTimeEpoch(com.google.cloud.Timestamp.of(ddmsDoc.getCreatedDateTimeEpoch()));
// ddms.setInterfaces(ddmsDoc.getInterfaces().stream().map(DdmsDoc::getRegisteredInterface).collect(Collectors.toSet()));
Timestamp sqlTimestamp = Timestamp.valueOf(ddmsDoc.getCreatedDateTimeEpoch());
com.google.cloud.Timestamp t = com.google.cloud.Timestamp.of(sqlTimestamp);
ddms.setCreatedDateTimeEpoch(t);
ddms.setInterfaces(ddmsDoc.getInterfaces());
return ddms;
}
......@@ -129,7 +130,6 @@ public class DdmsDoc {
private static String getEntityType(Ddms ddms){
String entityType="";
//get the first element from the set
RegisteredInterface ri = ddms.getInterfaces().iterator().next();
if(ri!=null) {
......
// Copyright © 2020 Amazon Web Services
//
// 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.register.provider.aws.pushApi;
import com.amazonaws.services.sns.message.*;
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 com.google.common.base.Strings;
import com.google.common.hash.Hashing;
import org.opengroup.osdu.core.common.cryptographic.ISignatureService;
import org.opengroup.osdu.core.common.cryptographic.SignatureServiceException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.utils.AppServiceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
//used by integration test to validate challenge response logic and confirm subscription
@RestController
@RequestMapping("/awstest")
@RequestScope
@Validated
public class AwsSubscriberTestListenerApi {
@Autowired
private AppServiceConfig serviceConfig;
@Autowired
private ISignatureService signatureService;
@Autowired
private JaxRsDpsLog logger;
@Inject
private javax.inject.Provider<DpsHeaders> headersProvider;
private final SnsMessageManager messageParser = new SnsMessageManager();
@GetMapping("/aws/challenge/{count}")
public ResponseEntity<?> testCrc(@RequestParam("crc") @NotBlank String crc, @RequestParam("hmac") @NotBlank String hmac) {
try {
signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret());
} catch (SignatureServiceException e) {
return new ResponseEntity<>("Authorization signature validation Failed", HttpStatus.BAD_REQUEST);
}
logger.info("Signature verified and sending response");
// Use the secret you send to the subscriber registration create request
return getResponse(crc, this.serviceConfig.getSubscriberSecret());
}
@PostMapping("/aws/challenge/{count}")
public void process(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {
messageParser.handleMessage(httpRequest.getInputStream(), new DefaultSnsMessageHandler() {
@Override
public void handle(SnsNotification snsNotification) {
// If the subject is "unsubscribe" then unsubscribe from this topic
if (snsNotification.getSubject().equalsIgnoreCase("unsubscribe")) {
snsNotification.unsubscribeFromTopic();
} else {
// Otherwise process the message
System.out.printf("Received message %n"
+ "Subject=%s %n"
+ "Message = %s %n",
snsNotification.getSubject(), snsNotification.getMessage());
}
}
@Override
public void handle(SnsUnsubscribeConfirmation message) {
logger.info("Received unsubscribe confirmation.");
}
@Override
public void handle(SnsSubscriptionConfirmation message) {
super.handle(message);
logger.info("Received subscription confirmation.");
}
});
}
@PostMapping("challenge/{count}")
public ResponseEntity testPushHmac(@RequestBody Object o, @RequestParam("hmac") String hmac) {
try {
signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret());
} catch (SignatureServiceException e) {
return new ResponseEntity<>("Authorization signature validation Failed", HttpStatus.BAD_REQUEST);
}
logger.info("Sending acknowledgement from hmac endpoint");
return new ResponseEntity<>(HttpStatus.OK);
}
class ChallengeResponse {
public String responseHash = "";
}
private boolean verifyToken() {
DpsHeaders headers = headersProvider.get();
if (Strings.isNullOrEmpty(headers.getAuthorization()))
return true;
try {
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance())
.setAudience(Collections.singletonList(this.serviceConfig.getIntegrationTestJwtAudiences()))
.build();
GoogleIdToken idToken = verifier.verify(headers.getAuthorization());
return idToken != null;
} catch (Exception ex) {
return false;
}
}
private ResponseEntity<ChallengeResponse> getResponse(String crc, String secretString) {
String response = secretString + crc;
response = Hashing.sha256()
.hashString(response, StandardCharsets.UTF_8)
.toString();
response = Base64.getEncoder().encodeToString(response.getBytes());
ChallengeResponse cr = new ChallengeResponse();
cr.responseHash = response;
return new ResponseEntity<>(cr, HttpStatus.OK);
}
}
......@@ -13,15 +13,20 @@
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.subscriber;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDeleteExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import com.amazonaws.services.sns.AmazonSNS;
import com.google.cloud.Timestamp;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.core.aws.ssm.ParameterStorePropertySource;
import org.opengroup.osdu.core.aws.ssm.SSMConfig;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.aws.action.ActionDoc;
import org.opengroup.osdu.register.provider.aws.config.AwsServiceConfig;
import org.opengroup.osdu.register.provider.aws.util.DocUtil;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
......@@ -32,6 +37,7 @@ import org.springframework.stereotype.Repository;