diff --git a/provider/notification-azure/pom.xml b/provider/notification-azure/pom.xml index 6051a4d29b7fc781161dbb541d52cfd4ce88b55c..a6ec6e277f1b5c693d04a9b25150d18ec3dc6477 100644 --- a/provider/notification-azure/pom.xml +++ b/provider/notification-azure/pom.xml @@ -65,10 +65,6 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> </exclusion> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> </exclusions> </dependency> <dependency> diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridHandshakeHandler.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridHandshakeHandler.java index b3b2a861f885a62d07699f91e7e028137f85d33b..83ebf3dba8b36ca455df16f54c09da289cba6192 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridHandshakeHandler.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridHandshakeHandler.java @@ -15,6 +15,7 @@ package org.opengroup.osdu.notification.provider.azure.pubsub; import com.google.gson.JsonObject; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.notification.provider.interfaces.IPubsubHandshakeHandler; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +28,9 @@ public class EventGridHandshakeHandler implements IPubsubHandshakeHandler { @Autowired private EventGridRequestBodyExtractor eventGridRequestBodyExtractor; + @Autowired + JaxRsDpsLog logger; + /** * Extract Handshake response string form Handshake request. * TODO: Check if there is a need to verify subscription name with @@ -44,6 +48,7 @@ public class EventGridHandshakeHandler implements IPubsubHandshakeHandler { response = jsonResponse.toString(); } catch (Exception exception) { + logger.error(exception.getMessage()); throw new AppException(HttpStatus.BAD_REQUEST.value(), "Request payload parsing error", "Unable to parse request payload.", exception); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridRequestBodyExtractor.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridRequestBodyExtractor.java index 0d1a403365483e8603c43085faf2cf63318c5215..c5fcedb7f6693be986329cbfd3527cdc68a57fc2 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridRequestBodyExtractor.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridRequestBodyExtractor.java @@ -49,11 +49,11 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto private static final Gson GSON = new Gson(); private static final ObjectMapper objectMapper = new ObjectMapper(); - private JsonObject root = null; - private HttpServletRequest httpServletRequest; - private JaxRsDpsLog log; + private final JsonObject root = null; + private final HttpServletRequest httpServletRequest; + private final JaxRsDpsLog logger; - private NotificationRequest notificationRequest; + private final NotificationRequest notificationRequest; private NotificationData notificationData; private HandshakeRequestData handshakeRequestData; private boolean isHandshakeRequest; @@ -61,7 +61,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto @Autowired public EventGridRequestBodyExtractor(HttpServletRequest httpServletRequest, JaxRsDpsLog log) { this.httpServletRequest = httpServletRequest; - this.log = log; + this.logger = log; this.notificationRequest = extractNotificationRequestFromHttpRequest(); } @@ -73,6 +73,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto */ public Map<String, String> extractAttributesFromRequestBody() { if(isHandshakeRequest) { + logger.error("Invalid Event Grid Message. Is a handshake request"); return null; } return this.notificationData.getAttributes(); @@ -86,6 +87,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto */ public String extractDataFromRequestBody() { if(isHandshakeRequest) { + logger.error("Invalid Event Grid Message. Is a handshake request"); return null; } return new String(Base64.getDecoder().decode(notificationData.getData())); @@ -100,6 +102,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto public String extractNotificationIdFromRequestBody() { String subscriptionId = httpServletRequest.getHeader(SUBSCRIPTION_ID); if (Strings.isNullOrEmpty(subscriptionId)) { + logger.error("Invalid Event Grid Message. Subscription Id is null or empty"); throw new AppException(HttpStatus.BAD_REQUEST.value(), "Invalid Event Grid Message", "Subscription ID not found"); } return subscriptionId; @@ -123,6 +126,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto */ public String getValidationCodeForHandshake() { if(!isHandshakeRequest) { + logger.error("Invalid Event Grid Message. Is not a handshake request"); return null; } return this.handshakeRequestData.getValidationCode(); @@ -154,6 +158,7 @@ public class EventGridRequestBodyExtractor implements IPubsubRequestBodyExtracto extractNotificationData(notificationRequest); } } catch (Exception e) { + logger.error("Invalid Event Grid Message. %s", e.getMessage()); throw new AppException(HttpStatus.BAD_REQUEST.value(), "Request payload parsing error", "Unable to parse request payload.", "Request contents are null or empty"); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java index 59736e877ba4cb9ebf5ac417f613e930eca92a39..32f048a4696abb2945f66091a1505a5e259eda2a 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.notification.provider.azure.util; import com.azure.security.keyvault.secrets.SecretClient; import com.azure.security.keyvault.secrets.models.KeyVaultSecret; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -49,6 +50,9 @@ public class AppProperties implements IAppProperties { @Autowired private SecretClient secretClient; + @Autowired + private JaxRsDpsLog logger; + private String authURL; private String authClientID; @@ -102,11 +106,13 @@ public class AppProperties implements IAppProperties { private String getKeyVaultSecret(SecretClient kv, String secretName) { KeyVaultSecret secret = kv.getSecret(secretName); if (secret == null) { + logger.error(String.format("Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); throw new IllegalStateException(String.format("No secret found with name %s", secretName)); } String secretValue = secret.getValue(); if (secretValue == null) { + logger.error(String.format("Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); throw new IllegalStateException(String.format( "Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java index 22bb7ee411d5076e86a9ec22d1f530f37870a2ae..81bca28a60c26c81462321b06697a0602cf1cfbc 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java @@ -2,6 +2,8 @@ package org.opengroup.osdu.notification.provider.azure.util; import com.azure.security.keyvault.secrets.SecretClient; import com.azure.security.keyvault.secrets.models.KeyVaultSecret; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @@ -17,6 +19,9 @@ public class AzureCosmosProperties { @Value("${azure.cosmosdb.database}") private String cosmosDBName; + @Autowired + private JaxRsDpsLog logger; + // TODO : Move away from Named beans. @Bean @Named("COSMOS_ENDPOINT") @@ -45,11 +50,13 @@ public class AzureCosmosProperties { public String getKeyVaultSecret(SecretClient kv, String secretName) { KeyVaultSecret secret = kv.getSecret(secretName); if (secret == null) { + logger.error(String.format("No secret found with name %s", secretName)); throw new IllegalStateException(String.format("No secret found with name %s", secretName)); } String secretValue = secret.getValue(); if (secretValue == null) { + logger.error(String.format("Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); throw new IllegalStateException(String.format( "Secret unexpectedly missing from KeyVault response for secret with name %s", secretName)); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java index dc1a345185f2f6c20384644f1772ff43ef0743bd..e68b499c7ce7555043e437cf367d7238fb0dda13 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureServiceAccountValidatorImpl.java @@ -14,11 +14,8 @@ package org.opengroup.osdu.notification.provider.azure.util; -import com.auth0.jwt.JWT; -import com.auth0.jwt.interfaces.DecodedJWT; import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @Service diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java index 9b0adf6c0906062a7bacad1c5e516def27b60ea7..dc31ed83ec7072692d1c1bea4064f3dc66a86c2b 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/GoogleServiceAccountImpl.java @@ -15,7 +15,9 @@ package org.opengroup.osdu.notification.provider.azure.util; import lombok.SneakyThrows; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.notification.provider.interfaces.IGoogleServiceAccount; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.naming.AuthenticationNotSupportedException; @@ -23,10 +25,15 @@ import javax.naming.AuthenticationNotSupportedException; @Component public class GoogleServiceAccountImpl implements IGoogleServiceAccount { + @Autowired + JaxRsDpsLog logger; + @SneakyThrows @Override public String getIdToken(String keyString, String audience) { // TODO : Check if it is to be supported + logger.error("GSA tokens are not supported."); + throw new AuthenticationNotSupportedException(); } } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java index 5d6d993341d4868719e363f8895c0ef92c7714af..391637b2a2ffc484b3eec3443ba5f31ea308df63 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java @@ -19,6 +19,7 @@ import com.microsoft.aad.adal4j.AuthenticationContext; import com.microsoft.aad.adal4j.AuthenticationResult; import com.microsoft.aad.adal4j.ClientCredential; 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.model.search.IdToken; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; @@ -43,10 +44,13 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien @Autowired private IJwtCache tenantJwtCache; + @Autowired + JaxRsDpsLog logger; + public String getIdToken(String tenantName) { - // TODO : Add logs. TenantInfo tenant = tenantInfoServiceProvider.getTenantInfo(tenantName); if (tenant == null) { + logger.error(String.format("Invalid tenant name %s", tenantName)); throw new AppException(HttpStatus.SC_BAD_REQUEST, "Invalid tenant Name", "Invalid tenant Name from azure"); } @@ -67,10 +71,12 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien ACCESS_TOKEN = getAccessToken(service); IdToken idToken = IdToken.builder().tokenValue(ACCESS_TOKEN).expirationTimeMillis(JWT.decode(ACCESS_TOKEN).getExpiresAt().getTime()).build(); tenantJwtCache.put(tenant.getName(), idToken); - } catch (AppException e) { - throw e; - } catch (Exception e) { - throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Persistence error", "Error generating token", e); + } catch (AppException appException) { + logger.error(String.format("Could not get a token %s", appException.getMessage())); + throw appException; + } catch (Exception exception) { + logger.error(String.format("Could not get a token %s", exception.getMessage())); + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Persistence error", "Error generating token", exception); } finally { if(service != null) { service.shutdown();