Commit 71600b76 authored by Komal Makkar's avatar Komal Makkar
Browse files

Added logs

parent f6e691b1
......@@ -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>
......
......@@ -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);
}
......
......@@ -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");
}
......
......@@ -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));
}
......
......@@ -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));
}
......
......@@ -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
......
......@@ -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();
}
}
......@@ -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();
......
Supports Markdown
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