There is a security vulnerability in SSH key-generation using GitKraken < v8.0.1. If you used this tool to create SSH keys, please update GitKraken and regenerate. If you need help with this, contact forum-support@opengroup.org

Commit 64c3542b authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 12 Contents:

1- Exception Handling
2- Short Topic name usage
parent f7809a71
Pipeline #54592 failed with stages
in 1 minute and 12 seconds
...@@ -24,7 +24,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; ...@@ -24,7 +24,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig; import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig; import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.register.provider.azure.util.CryptographyUtil; import org.opengroup.osdu.register.provider.azure.util.CryptographyUtil;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper; import org.opengroup.osdu.register.provider.azure.util.PartitionHelperServiceBus;
import org.opengroup.osdu.register.subscriber.model.*; import org.opengroup.osdu.register.subscriber.model.*;
import org.opengroup.osdu.register.utils.Constants; import org.opengroup.osdu.register.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -54,14 +54,14 @@ public class CosmosSubscription { ...@@ -54,14 +54,14 @@ public class CosmosSubscription {
private CryptographyUtil cryptographyUtil; private CryptographyUtil cryptographyUtil;
@Autowired @Autowired
private PartitionHelper partitionHelper; private PartitionHelperServiceBus partitionHelper;
@Autowired @Autowired
private TopicsRepositoryImpl topicsRepository; private TopicsRepositoryImpl topicsRepository;
public Subscription createSubscription(Subscription input) throws AppException { public Subscription createSubscription(Subscription input) throws AppException {
SubscriptionDoc doc = new SubscriptionDoc(input, dpsHeaders.getPartitionId()); SubscriptionDoc doc = new SubscriptionDoc(input, dpsHeaders.getPartitionId());
doc.setTopic(partitionHelper.getFullyQualifiedTopicName(input.getTopic())); doc.setTopic(input.getTopic());
doc.setSecretValue(cryptographyUtil.encryptData(input.getSecret().toString())); doc.setSecretValue(cryptographyUtil.encryptData(input.getSecret().toString()));
doc.setKeyName(cryptographyUtil.getKeyName()); doc.setKeyName(cryptographyUtil.getKeyName());
doc.setKeyVersion(cryptographyUtil.getKeyVersion()); doc.setKeyVersion(cryptographyUtil.getKeyVersion());
...@@ -73,7 +73,7 @@ public class CosmosSubscription { ...@@ -73,7 +73,7 @@ public class CosmosSubscription {
public void deleteSubscription(String subscriptionId) { public void deleteSubscription(String subscriptionId) {
cosmosStore.deleteItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosStore.deleteItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(),
cosmosContainerConfig.getSubscriptionContainerName(), subscriptionId, dpsHeaders.getPartitionId()); cosmosContainerConfig.getSubscriptionContainerName(), subscriptionId, dpsHeaders.getPartitionId());
logger.info("Record deleted for subscription with ID: " + subscriptionId); logger.debug("Record deleted for subscription with ID: " + subscriptionId);
} }
public Subscription getSubscription(String id) { public Subscription getSubscription(String id) {
...@@ -82,6 +82,7 @@ public class CosmosSubscription { ...@@ -82,6 +82,7 @@ public class CosmosSubscription {
logger.error(String.format("Subscriber with id %s does not exist.", id)); logger.error(String.format("Subscriber with id %s does not exist.", id));
return new AppException(404, "Not found", String.format("Subscriber with id %s does not exist.", id)); return new AppException(404, "Not found", String.format("Subscriber with id %s does not exist.", id));
}); });
logger.debug("Record fetched successfully for subscription with ID: " + id);
return convertToSubscriptionClass(doc); return convertToSubscriptionClass(doc);
} }
...@@ -115,12 +116,12 @@ public class CosmosSubscription { ...@@ -115,12 +116,12 @@ public class CosmosSubscription {
public void updateSubscription(Subscription input) { public void updateSubscription(Subscription input) {
SubscriptionDoc doc = new SubscriptionDoc(input, dpsHeaders.getPartitionId()); SubscriptionDoc doc = new SubscriptionDoc(input, dpsHeaders.getPartitionId());
doc.setTopic(partitionHelper.getFullyQualifiedTopicName(input.getTopic())); doc.setTopic(input.getTopic());
doc.setSecretValue(cryptographyUtil.encryptData(input.getSecret().toString())); doc.setSecretValue(cryptographyUtil.encryptData(input.getSecret().toString()));
doc.setKeyName(cryptographyUtil.getKeyName()); doc.setKeyName(cryptographyUtil.getKeyName());
doc.setKeyVersion(cryptographyUtil.getKeyVersion()); doc.setKeyVersion(cryptographyUtil.getKeyVersion());
cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), dpsHeaders.getPartitionId(), doc); cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), dpsHeaders.getPartitionId(), doc);
logger.info("Updating Record for subscription with ID: ", input.getId()); logger.debug("Updating Record for subscription with ID: ", input.getId());
} }
private Subscription convertToSubscriptionClass(SubscriptionDoc doc) { private Subscription convertToSubscriptionClass(SubscriptionDoc doc) {
...@@ -137,7 +138,7 @@ public class CosmosSubscription { ...@@ -137,7 +138,7 @@ public class CosmosSubscription {
hmacSecret.setValue(secretValue); hmacSecret.setValue(secretValue);
secret = hmacSecret; secret = hmacSecret;
} }
return new Subscription(doc.getId(), doc.getName(), doc.getDescription(), topicsRepository.getTopicAliasFromFullyQualifiedTopicName(doc.getTopic()), doc.getPushEndpoint(), return new Subscription(doc.getId(), doc.getName(), doc.getDescription(), doc.getTopic(), doc.getPushEndpoint(),
doc.getCreatedBy(), doc.getCreatedOnEpoch(), doc.getNotificationId(), secret); doc.getCreatedBy(), doc.getCreatedOnEpoch(), doc.getNotificationId(), secret);
} }
......
...@@ -75,7 +75,7 @@ public class SubscriptionRepository implements ISubscriptionRepository { ...@@ -75,7 +75,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
// This will result in an 500 Exception so the user should be able to create the subscription with // This will result in an 500 Exception so the user should be able to create the subscription with
// the same topic and PubSub Endpoint combination again // the same topic and PubSub Endpoint combination again
logger.info(String.format("Record already exists for Subscription with id %s", input.getId())); logger.info(String.format("Record already exists for Subscription with id %s", input.getId()));
Subscription outputSubscription = createPubSubSubscriptionIfDoesNotExist(subscription); Subscription outputSubscription = createPubSubSubscriptionIfDoesNotExist(input);
input.setNotificationId(outputSubscription.getNotificationId()); input.setNotificationId(outputSubscription.getNotificationId());
return input; return input;
} else { } else {
...@@ -89,7 +89,7 @@ public class SubscriptionRepository implements ISubscriptionRepository { ...@@ -89,7 +89,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
return input; return input;
} catch (AppException e) { } catch (AppException e) {
if (e.getError().getCode() == 409) { if (e.getError().getCode() == 409) {
throw new AppException(409, "Conflict", "Another request is trying to create the same subscription"); throw new AppException(409, "Conflict", e.getMessage());
} }
logger.error("PubSub Subscription creation failed.Rollback Cosmos Subscription Creation"); logger.error("PubSub Subscription creation failed.Rollback Cosmos Subscription Creation");
try { try {
...@@ -119,13 +119,10 @@ public class SubscriptionRepository implements ISubscriptionRepository { ...@@ -119,13 +119,10 @@ public class SubscriptionRepository implements ISubscriptionRepository {
*/ */
@Override @Override
public boolean delete(String id) { public boolean delete(String id) {
Subscription subscription = cosmosSubscription.getSubscription(id);
if (subscription == null) {
logger.info("Record not found for subscription with ID: " + id);
return false;
}
logger.debug("Record found for subscription with ID: " + id);
try { try {
Subscription subscription = cosmosSubscription.getSubscription(id);
logger.debug("Record found for subscription with ID: " + id);
pubSubSubscription.deleteSubscription(subscription.getNotificationId(), subscription.getTopic()); pubSubSubscription.deleteSubscription(subscription.getNotificationId(), subscription.getTopic());
logger.debug("PubSub Subscription deleted with ID:" + subscription.getNotificationId()); logger.debug("PubSub Subscription deleted with ID:" + subscription.getNotificationId());
try { try {
...@@ -140,9 +137,13 @@ public class SubscriptionRepository implements ISubscriptionRepository { ...@@ -140,9 +137,13 @@ public class SubscriptionRepository implements ISubscriptionRepository {
} }
} }
} catch (AppException e) { } catch (AppException e) {
// TODO:This exception is not created in flow of delete
if (e.getError().getCode() == 409) { if (e.getError().getCode() == 409) {
logger.error("Another request is trying to delete the same subscription"); logger.error("Another request is trying to delete the same subscription");
throw new AppException(409, "Conflict", "Another request is trying to delete the same subscription"); throw new AppException(409, "Conflict", "Another request is trying to delete the same subscription");
} else if (e.getMessage().equals(String.format("Subscriber with id %s does not exist.", id))) {
logger.info("Record not found for subscription with ID: " + id);
return false;
} else { } else {
logger.error("Unexpected error deleting subscription"); logger.error("Unexpected error deleting subscription");
throw new AppException(500, "Server Error", "Unexpected error deleting subscription"); throw new AppException(500, "Server Error", "Unexpected error deleting subscription");
......
...@@ -57,12 +57,19 @@ public class ManagementClientFactoryImpl implements IManagementClientFactory { ...@@ -57,12 +57,19 @@ public class ManagementClientFactoryImpl implements IManagementClientFactory {
String serviceBusConnectionString = pi.getSbConnection(); String serviceBusConnectionString = pi.getSbConnection();
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(serviceBusConnectionString); ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(serviceBusConnectionString);
ManagementClient managementClient = new ManagementClient(connectionStringBuilder); ManagementClient managementClient = new ManagementClient(connectionStringBuilder);
if (managementClient == null)
throw new Exception("Null Pointer Exception");
logger.debug("Management client creation successful for partition Id : " + dpsHeaders.getPartitionId()); logger.debug("Management client creation successful for partition Id : " + dpsHeaders.getPartitionId());
this.clientCache.put(cacheKey, managementClient); this.clientCache.put(cacheKey, managementClient);
return managementClient; return managementClient;
} catch (Exception e) { } catch (Exception e) {
logger.error("Management client creation failed for partition Id : " + dpsHeaders.getPartitionId()); if (e.getMessage().equals("Null Pointer Exception")) {
throw new AppException(500, "Null Pointer Exception", MANAGEMENT_CLIENT_ERROR_MESSAGE); logger.error("Management client can not be Null for partition Id : " + dpsHeaders.getPartitionId());
throw new AppException(500, "Null Pointer Exception", MANAGEMENT_CLIENT_ERROR_MESSAGE);
} else {
logger.error("Management client creation failed for partition Id : " + dpsHeaders.getPartitionId());
throw new AppException(500, "Server Error", MANAGEMENT_CLIENT_ERROR_MESSAGE + " : " + e.getMessage().toString());
}
} }
} }
......
...@@ -14,24 +14,23 @@ ...@@ -14,24 +14,23 @@
package org.opengroup.osdu.register.provider.azure.subscriber.pubsub; package org.opengroup.osdu.register.provider.azure.subscriber.pubsub;
import com.microsoft.azure.CloudException;
import com.microsoft.azure.servicebus.management.ManagementClient; import com.microsoft.azure.servicebus.management.ManagementClient;
import com.microsoft.azure.servicebus.primitives.MessagingEntityAlreadyExistsException;
import com.microsoft.azure.servicebus.primitives.MessagingEntityNotFoundException;
import org.opengroup.osdu.azure.partition.PartitionServiceClient; import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; 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.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.provider.azure.subscriber.messageBus.IManagementClientFactory; import org.opengroup.osdu.register.provider.azure.subscriber.messageBus.IManagementClientFactory;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@ConditionalOnProperty(value = "azure.servicebus.enabled", havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(value = "azure.serviceBus.enabled", havingValue = "true", matchIfMissing = true)
public class PullSubscription implements IPubsubSubscription { public class PullSubscription implements IPubsubSubscription {
// TODO: UPDATE ERROR_MESSAGE FOR SERVICE BUS // TODO: UPDATE ERROR_MESSAGE FOR SERVICE BUS
private static final String RESOURCE_PROVISIONING_ERROR_MESSAGE = "Resource cannot be updated during provisioning"; private static final String RESOURCE_PROVISIONING_ERROR_MESSAGE = "Resource cannot be updated during provisioning";
private static final String MANAGEMENT_CLIENT_ERROR_MESSAGE = "Unable to create management client";
@Autowired @Autowired
private IManagementClientFactory factory; private IManagementClientFactory factory;
@Autowired @Autowired
...@@ -40,8 +39,6 @@ public class PullSubscription implements IPubsubSubscription { ...@@ -40,8 +39,6 @@ public class PullSubscription implements IPubsubSubscription {
private JaxRsDpsLog logger; private JaxRsDpsLog logger;
@Autowired @Autowired
private PartitionServiceClient partitionService; private PartitionServiceClient partitionService;
@Autowired
private PartitionHelper partitionHelper;
public void createSubscription(String subscriptionId, String topicAliasName) { public void createSubscription(String subscriptionId, String topicAliasName) {
ManagementClient managementClient = factory.getManager(); ManagementClient managementClient = factory.getManager();
...@@ -52,7 +49,11 @@ public class PullSubscription implements IPubsubSubscription { ...@@ -52,7 +49,11 @@ public class PullSubscription implements IPubsubSubscription {
if (e.getMessage().equals(RESOURCE_PROVISIONING_ERROR_MESSAGE)) { if (e.getMessage().equals(RESOURCE_PROVISIONING_ERROR_MESSAGE)) {
logger.error("Another request is trying to create the same Pull subscription"); logger.error("Another request is trying to create the same Pull subscription");
throw new AppException(409, "Conflict", "Another request is trying to create the same Pull subscription"); throw new AppException(409, "Conflict", "Another request is trying to create the same Pull subscription");
} else { } else if (e instanceof MessagingEntityAlreadyExistsException) {
logger.error(String.format("Pull Subscription with id %s already exist.", subscriptionId));
throw new AppException(409, "Conflict", "Pull Subscription already exists");
}
else {
logger.error("Creating Pull Subscription failed with error: " + e.toString()); logger.error("Creating Pull Subscription failed with error: " + e.toString());
throw new AppException(500, "Server Error", "Unexpected error creating Pull subscription"); throw new AppException(500, "Server Error", "Unexpected error creating Pull subscription");
} }
...@@ -65,10 +66,9 @@ public class PullSubscription implements IPubsubSubscription { ...@@ -65,10 +66,9 @@ public class PullSubscription implements IPubsubSubscription {
managementClient.deleteSubscription(topicAliasName, subscriptionId); managementClient.deleteSubscription(topicAliasName, subscriptionId);
logger.debug(String.format("Pull Subscription with id %s deleted successfully", subscriptionId)); logger.debug(String.format("Pull Subscription with id %s deleted successfully", subscriptionId));
} catch (Exception e) { } catch (Exception e) {
if (e instanceof CloudException) { if (e instanceof MessagingEntityNotFoundException) {
CloudException cloudException = (CloudException) e; logger.error(String.format("Pull Subscription with id %s does not exist.", subscriptionId));
logger.error(cloudException.toString()); throw new AppException(404, "Not found", String.format("Pull Subscription with id %s does not exist.", subscriptionId));
throw new AppException(cloudException.response().code(), cloudException.body().code(), cloudException.body().message());
} else { } else {
logger.error("Deleting Pull Subscription failed with error: " + e.toString()); logger.error("Deleting Pull Subscription failed with error: " + e.toString());
throw new AppException(500, "Server Error", "Unexpected error deleting Pull subscription"); throw new AppException(500, "Server Error", "Unexpected error deleting Pull subscription");
...@@ -82,7 +82,7 @@ public class PullSubscription implements IPubsubSubscription { ...@@ -82,7 +82,7 @@ public class PullSubscription implements IPubsubSubscription {
managementClient.getSubscription(topicAliasName, subscriptionId); managementClient.getSubscription(topicAliasName, subscriptionId);
logger.debug(String.format("Pull Subscription with id %s fetched successfully", subscriptionId)); logger.debug(String.format("Pull Subscription with id %s fetched successfully", subscriptionId));
} catch (Exception e) { } catch (Exception e) {
if (e instanceof NullPointerException) { if (e instanceof MessagingEntityNotFoundException) {
logger.error(String.format("Pull Subscription with id %s does not exist.", subscriptionId)); logger.error(String.format("Pull Subscription with id %s does not exist.", subscriptionId));
throw new AppException(404, "Not found", String.format("Pull Subscription with id %s does not exist.", subscriptionId)); throw new AppException(404, "Not found", String.format("Pull Subscription with id %s does not exist.", subscriptionId));
} else { } else {
......
...@@ -97,8 +97,6 @@ public class ManagementClientFactoryTest { ...@@ -97,8 +97,6 @@ public class ManagementClientFactoryTest {
}); });
assertNotNull(exception); assertNotNull(exception);
assertEquals(500, exception.getError().getCode()); assertEquals(500, exception.getError().getCode());
assertEquals(MANAGEMENT_CLIENT_ERROR_MESSAGE, exception.getMessage());
assertEquals("Null Pointer Exception", exception.getError().getReason());
verify(partitionService, times(1)).getPartition(dataPartitionId); verify(partitionService, times(1)).getPartition(dataPartitionId);
verify(partitionInfoAzure, times(1)).getSbConnection(); verify(partitionInfoAzure, times(1)).getSbConnection();
verify(clientCache, times(0)).put(dpsHeaders.getPartitionId() + "-managementClient", managementClient); verify(clientCache, times(0)).put(dpsHeaders.getPartitionId() + "-managementClient", managementClient);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment