summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend')
-rw-r--r--openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java69
-rw-r--r--openecomp-be/backend/openecomp-sdc-security-util/pom.xml6
-rw-r--r--openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/filters/SessionValidationFilter.java88
3 files changed, 110 insertions, 53 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java b/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java
index a317d41a50..bc7a6f4f64 100644
--- a/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java
@@ -88,13 +88,7 @@ import org.openecomp.sdc.action.dao.types.ActionArtifactEntity;
import org.openecomp.sdc.action.dao.types.ActionEntity;
import org.openecomp.sdc.action.errors.ActionErrorConstants;
import org.openecomp.sdc.action.errors.ActionException;
-import org.openecomp.sdc.action.logging.StatusCode;
-import org.openecomp.sdc.action.types.Action;
-import org.openecomp.sdc.action.types.ActionArtifact;
-import org.openecomp.sdc.action.types.ActionArtifactProtection;
-import org.openecomp.sdc.action.types.ActionStatus;
-import org.openecomp.sdc.action.types.ActionSubOperation;
-import org.openecomp.sdc.action.types.OpenEcompComponent;
+import org.openecomp.sdc.action.types.*;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -111,6 +105,15 @@ import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.slf4j.MDC;
+import java.util.*;
+
+import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.COMPLETE;
+import static org.onap.logging.ref.slf4j.ONAPLogConstants.ResponseStatus.ERROR;
+import static org.openecomp.sdc.action.ActionConstants.*;
+import static org.openecomp.sdc.action.errors.ActionErrorConstants.*;
+import static org.openecomp.sdc.action.util.ActionUtil.*;
+import static org.openecomp.sdc.versioning.dao.types.Version.VERSION_STRING_VIOLATION_MSG;
+
/**
* Manager Implementation for {@link ActionManager Action Library Operations}
* <br>
@@ -272,7 +275,7 @@ public class ActionManagerImpl implements ActionManager {
"entering deleteAction with actionInvariantUuId = " + actionInvariantUuId + " and user = " + user);
actionLogPreProcessor(ActionSubOperation.DELETE_ACTION, TARGET_ENTITY_API);
versioningManager.delete(ACTION_VERSIONABLE_TYPE, actionInvariantUuId, user);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
actionDao.deleteAction(actionInvariantUuId);
} catch (CoreException ce) {
@@ -295,12 +298,12 @@ public class ActionManagerImpl implements ActionManager {
try {
actionLogPreProcessor(ActionSubOperation.VALIDATE_ACTION_UNIQUE_NAME, TARGET_ENTITY_API);
uniqueValueUtil.validateUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName());
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
} catch (CoreException exception) {
String errorDesc = String.format(ACTION_ENTITY_UNIQUE_VALUE_MSG, ActionConstants.UniqueValues.ACTION_NAME,
action.getName());
log.error(errorDesc, exception);
- actionLogPostProcessor(StatusCode.ERROR, ACTION_ENTITY_UNIQUE_VALUE_ERROR, errorDesc, false);
+ actionLogPostProcessor(ERROR, ACTION_ENTITY_UNIQUE_VALUE_ERROR, errorDesc, false);
throw new ActionException(ACTION_ENTITY_UNIQUE_VALUE_ERROR, errorDesc);
} finally {
log.metrics("");
@@ -312,7 +315,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_VERSION, TARGET_ENTITY_API);
Version version = versioningManager.create(ACTION_VERSIONABLE_TYPE, action.getActionInvariantUuId(), user);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
action.setVersion(version.toString());
@@ -322,7 +325,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_UNIQUE_VALUE, TARGET_ENTITY_API);
uniqueValueUtil.createUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName());
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
return action;
@@ -346,7 +349,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_API);
VersionInfo versionInfo = versioningManager.getEntityVersionInfo(ACTION_VERSIONABLE_TYPE, invariantUuId,
user, VersionableEntityAction.Write);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
Version activeVersion = versionInfo.getActiveVersion();
@@ -382,7 +385,7 @@ public class ActionManagerImpl implements ActionManager {
log.debug("entering checkout for Action with invariantUUID= " + invariantUuId + BY_USER + user);
actionLogPreProcessor(ActionSubOperation.CHECKOUT_ACTION, TARGET_ENTITY_API);
version = versioningManager.checkout(ACTION_VERSIONABLE_TYPE, invariantUuId, user);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
actionEntity = updateUniqueIdForVersion(invariantUuId, version, ActionStatus.Locked.name(), user);
@@ -393,7 +396,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
VersionInfoEntity versionInfoEntity = versionInfoDao
.get(new VersionInfoEntity(ACTION_VERSIONABLE_TYPE, invariantUuId));
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
String checkoutUser = versionInfoEntity.getCandidate()
.getUser();
@@ -427,7 +430,7 @@ public class ActionManagerImpl implements ActionManager {
// Get list of uploaded artifacts in this checked out version
VersionInfoEntity versionInfoEntity = versionInfoDao
.get(new VersionInfoEntity(ACTION_VERSIONABLE_TYPE, invariantUuId));
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
if (versionInfoEntity == null) {
throw new CoreException(new EntityNotExistErrorBuilder(ACTION_VERSIONABLE_TYPE, invariantUuId).build());
@@ -443,27 +446,27 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_VERSION, TARGET_ENTITY_DB);
Action action = actionDao.get(new ActionEntity(invariantUuId, activeVersion))
.toDto();
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
// Perform undo checkout on the action
actionLogPreProcessor(ActionSubOperation.UNDO_CHECKOUT_ACTION, TARGET_ENTITY_API);
version = versioningManager.undoCheckout(ACTION_VERSIONABLE_TYPE, invariantUuId, user);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
if (version.equals(new Version(0, 0))) {
actionLogPreProcessor(ActionSubOperation.DELETE_UNIQUEVALUE, TARGET_ENTITY_API);
UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
uniqueValueUtil.deleteUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName());
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
actionLogPreProcessor(ActionSubOperation.DELETE_ACTIONVERSION, TARGET_ENTITY_DB);
// Added for the case where Create->Undo_Checkout->Checkout
// should not get the action
versionInfoDao.delete(new VersionInfoEntity(ACTION_VERSIONABLE_TYPE, invariantUuId));
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
}
@@ -476,7 +479,7 @@ public class ActionManagerImpl implements ActionManager {
getEffectiveVersion(activeVersion.toString()));
actionLogPreProcessor(ActionSubOperation.DELETE_ARTIFACT, TARGET_ENTITY_DB);
actionArtifactDao.delete(artifactDeleteEntity);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
}
}
@@ -503,7 +506,7 @@ public class ActionManagerImpl implements ActionManager {
log.debug("entering checkin for Action with invariantUUID= " + invariantUuId + BY_USER + user);
actionLogPreProcessor(ActionSubOperation.CHECKIN_ACTION, TARGET_ENTITY_API);
version = versioningManager.checkin(ACTION_VERSIONABLE_TYPE, invariantUuId, user, null);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
actionEntity = updateStatusForVersion(invariantUuId, version, ActionStatus.Available.name(), user);
} catch (CoreException exception) {
@@ -530,7 +533,7 @@ public class ActionManagerImpl implements ActionManager {
log.debug("entering submit for Action with invariantUUID= " + invariantUuId + BY_USER + user);
actionLogPreProcessor(ActionSubOperation.SUBMIT_ACTION, TARGET_ENTITY_API);
version = versioningManager.submit(ACTION_VERSIONABLE_TYPE, invariantUuId, user, null);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
actionEntity = updateUniqueIdForVersion(invariantUuId, version, ActionStatus.Final.name(), user);
} catch (CoreException exception) {
@@ -601,13 +604,13 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB);
VersionInfo versionInfo = versioningManager.getEntityVersionInfo(ACTION_VERSIONABLE_TYPE,
actionInvariantUuId, user, VersionableEntityAction.Write);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
Version activeVersion = versionInfo.getActiveVersion();
actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, TARGET_ENTITY_DB);
Action action = actionDao.get(new ActionEntity(actionInvariantUuId, activeVersion))
.toDto();
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
String artifactUuId = generateActionArtifactUuId(action, artifact.getArtifactName());
// Check for Unique document name
@@ -675,7 +678,7 @@ public class ActionManagerImpl implements ActionManager {
actionEntity.setData(data);
actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, TARGET_ENTITY_DB);
actionDao.update(actionEntity);
- actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
+ actionLogPostProcessor(COMPLETE, null, "", false);
log.metrics("");
// delete Artifact if it's upload and delete action on same checkout
// version
@@ -688,7 +691,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.DELETE_ACTION_ARTIFACT, TARGET_ENTITY_DB);
actionArtifactDao.delete(artifactDeleteEntity);
}
- actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
+ actionLogPostProcessor(COMPLETE, null, "", false);
log.metrics("");
}
@@ -716,13 +719,13 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_API);
VersionInfo versionInfo = versioningManager.getEntityVersionInfo(ACTION_VERSIONABLE_TYPE,
actionInvariantUuId, user, VersionableEntityAction.Write);
- actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
+ actionLogPostProcessor(COMPLETE, null, "", false);
log.metrics("");
Version activeVersion = versionInfo.getActiveVersion();
actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, TARGET_ENTITY_DB);
Action action = actionDao.get(new ActionEntity(actionInvariantUuId, activeVersion))
.toDto();
- actionLogPostProcessor(StatusCode.COMPLETE, null, "", false);
+ actionLogPostProcessor(COMPLETE, null, "", false);
log.metrics("");
List<ActionArtifact> actionArtifacts = action.getArtifacts();
ActionArtifact artifactMetadataByUuId = getArtifactMetadataFromAction(actionArtifacts,
@@ -903,7 +906,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_VERSIONINFO_FOR_ALL_ACTIONS, TARGET_ENTITY_API);
Map<String, VersionInfo> actionVersionMap = versioningManager.listEntitiesVersionInfo(ACTION_VERSIONABLE_TYPE,
"", VersionableEntityAction.Read);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
for (Action action : actions) {
if (action.getStatus() == ActionStatus.Deleted) {
@@ -1071,7 +1074,7 @@ public class ActionManagerImpl implements ActionManager {
actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_VERSION, TARGET_ENTITY_DB);
entity = actionDao
.get(new ActionEntity(invariantUuId != null ? invariantUuId.toUpperCase() : null, version));
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
}
log.debug("exit getActionsEntityByVersion with invariantUuId= " + invariantUuId + AND_VERSION + version);
@@ -1128,7 +1131,7 @@ public class ActionManagerImpl implements ActionManager {
actionEntity.setTimestamp(getCurrentTimeStampUtc());
actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, TARGET_ENTITY_DB);
actionDao.update(actionEntity);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
}
@@ -1164,7 +1167,7 @@ public class ActionManagerImpl implements ActionManager {
actionEntity.setTimestamp(getCurrentTimeStampUtc());
actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, TARGET_ENTITY_DB);
actionDao.update(actionEntity);
- actionLogPostProcessor(StatusCode.COMPLETE);
+ actionLogPostProcessor(COMPLETE);
log.metrics("");
}
log.debug("exit updateStatusForVersion with invariantUuId= " + invariantUuId + AND_VERSION + version
diff --git a/openecomp-be/backend/openecomp-sdc-security-util/pom.xml b/openecomp-be/backend/openecomp-sdc-security-util/pom.xml
index 3b2fd1da53..78fa00a17b 100644
--- a/openecomp-be/backend/openecomp-sdc-security-util/pom.xml
+++ b/openecomp-be/backend/openecomp-sdc-security-util/pom.xml
@@ -88,6 +88,12 @@
<version>1.7.4</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>1.4.0</version>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/filters/SessionValidationFilter.java b/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/filters/SessionValidationFilter.java
index 1684df4017..de235bff89 100644
--- a/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/filters/SessionValidationFilter.java
+++ b/openecomp-be/backend/openecomp-sdc-security-util/src/main/java/org/openecomp/sdc/securityutil/filters/SessionValidationFilter.java
@@ -20,11 +20,14 @@
package org.openecomp.sdc.securityutil.filters;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.securityutil.AuthenticationCookieUtils;
import org.openecomp.sdc.securityutil.CipherUtilException;
import org.openecomp.sdc.securityutil.ISessionValidationFilterConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.apache.commons.lang.StringUtils;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -38,6 +41,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -46,6 +50,19 @@ public abstract class SessionValidationFilter implements Filter {
private ISessionValidationFilterConfiguration filterConfiguration;
private List<String> excludedUrls;
+ private static final String REQUEST_ID = ONAPLogConstants.MDCs.REQUEST_ID;
+ private static final String ONAP_REQUEST_ID_HEADER = ONAPLogConstants.Headers.REQUEST_ID;
+ private static final String REQUEST_ID_HEADER = "X-RequestID";
+ private static final String TRANSACTION_ID_HEADER = "X-TransactionId";
+ private static final String ECOMP_REQUEST_ID_HEADER = "X-ECOMP-RequestID";
+
+ private static final String PARTNER_NAME = ONAPLogConstants.MDCs.PARTNER_NAME;
+ private static final String USER_ID_HEADER = "USER_ID";
+ private static final String ONAP_PARTNER_NAME_HEADER = ONAPLogConstants.Headers.PARTNER_NAME;
+ private static final String USER_AGENT_HEADER = "User-Agent";
+ private static final String UNKNOWN = "UNKNOWN";
+
+
public abstract ISessionValidationFilterConfiguration getFilterConfiguration();
protected abstract Cookie addRoleToCookie(Cookie updatedCookie);
protected abstract boolean isRoleValid(Cookie cookie);
@@ -61,51 +78,45 @@ public abstract class SessionValidationFilter implements Filter {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
- long starTime = System.nanoTime();
+ long startTime = System.nanoTime();
+ fillMDCFromHeaders(httpRequest);
log.debug("SessionValidationFilter: Validation started, received request with URL {}", httpRequest.getRequestURL());
// request preprocessing
- boolean isContinueProcessing = preProcessingRequest(servletRequest, servletResponse, filterChain, httpRequest, httpResponse);
+ boolean isContinueProcessing = preProcessingRequest(servletRequest, servletResponse, filterChain, httpRequest, httpResponse, startTime);
List<Cookie> cookies = null;
+ Cookie extractedCookie = null;
// request processing
if (isContinueProcessing) {
cookies = extractAuthenticationCookies(httpRequest.getCookies());
- isContinueProcessing = processRequest(httpRequest, httpResponse, cookies.get(0));
+ extractedCookie = cookies.get(0);
+ isContinueProcessing = processRequest(httpRequest, httpResponse, extractedCookie);
}
// response processing
if(isContinueProcessing){
log.debug("SessionValidationFilter: Cookie from request {} is valid, passing request to session extension ...", httpRequest.getRequestURL());
- Cookie updatedCookie = processResponse(cookies.get(cookies.size()-1));
-
+ Cookie updatedCookie = processResponse(extractedCookie);
cleanResponceFromLeftoverCookies(httpResponse, cookies);
-
- // Use responce wrapper if servlet remove Cookie header from responce
-// OutputStream out = httpResponse.getOutputStream();
-// ResponceWrapper responceWrapper = new ResponceWrapper(httpResponse);
-
log.debug("SessionValidationFilter: request {} passed all validations, passing request to endpoint ...", httpRequest.getRequestURL());
httpResponse.addCookie(updatedCookie);
+ long durationSec = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
+ long durationMil = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
+ log.debug("SessionValidationFilter: Validation ended, running time for URL {} is: {} seconds {} miliseconds", httpRequest.getPathInfo(), durationSec, durationMil);
filterChain.doFilter(servletRequest, httpResponse);
-
- // Use responce wrapper if servlet remove Cookie header from responce
-// responceWrapper.addCookie(updatedCookie);
-// httpResponse.setContentLength(responceWrapper.getData().length);
-// out.write(responceWrapper.getData());
-// out.close();
}
- long durationSec = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - starTime);
- long durationMil = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - starTime);
- log.debug("SessionValidationFilter: Validation ended, running time for URL {} is: {} seconds {} miliseconds", httpRequest.getPathInfo(), durationSec, durationMil);
}
- private boolean preProcessingRequest(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
+ private boolean preProcessingRequest(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain, HttpServletRequest httpRequest, HttpServletResponse httpResponse, long startTime) throws IOException, ServletException {
boolean isPreProcessingSucceeded = true;
if (isUrlFromWhiteList(httpRequest)) {
log.debug("SessionValidationFilter: URL {} excluded from access validation , passing request to endpoint ... ", httpRequest.getRequestURL());
+ long durationSec = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
+ long durationMil = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
+ log.debug("SessionValidationFilter: Validation ended, running time for URL {} is: {} seconds {} miliseconds", httpRequest.getPathInfo(), durationSec, durationMil);
filterChain.doFilter(servletRequest, servletResponse);
isPreProcessingSucceeded = false;
@@ -207,6 +218,43 @@ public abstract class SessionValidationFilter implements Filter {
}
}
+ public static void fillMDCFromHeaders(HttpServletRequest httpServletRequest) {
+ fillRequestIdFromHeader(httpServletRequest);
+ fillPartnerNameFromHeader(httpServletRequest);
+
+ }
+
+ private static void fillRequestIdFromHeader(HttpServletRequest httpServletRequest){
+ if (MDC.get(REQUEST_ID) == null) {
+ if (StringUtils.isNotEmpty(httpServletRequest.getHeader(ONAP_REQUEST_ID_HEADER))) {
+ MDC.put(REQUEST_ID, httpServletRequest.getHeader(ONAP_REQUEST_ID_HEADER));
+ } else if (StringUtils.isNotEmpty(httpServletRequest.getHeader(REQUEST_ID_HEADER))) {
+ MDC.put(REQUEST_ID, httpServletRequest.getHeader(REQUEST_ID_HEADER));
+ } else if (StringUtils.isNotEmpty(httpServletRequest.getHeader(TRANSACTION_ID_HEADER))) {
+ MDC.put(REQUEST_ID, httpServletRequest.getHeader(TRANSACTION_ID_HEADER));
+ } else if (StringUtils.isNotEmpty(httpServletRequest.getHeader(ECOMP_REQUEST_ID_HEADER))) {
+ MDC.put(REQUEST_ID, httpServletRequest.getHeader(ECOMP_REQUEST_ID_HEADER));
+ } else {
+ MDC.put(REQUEST_ID, UUID.randomUUID().toString());
+ }
+ }
+ }
+
+ private static void fillPartnerNameFromHeader(HttpServletRequest httpServletRequest){
+ if (MDC.get(PARTNER_NAME) == null) {
+ if (StringUtils.isNotEmpty(httpServletRequest.getHeader(USER_ID_HEADER))) {
+ MDC.put(PARTNER_NAME, httpServletRequest.getHeader(USER_ID_HEADER));
+ } else if (StringUtils.isNotEmpty(httpServletRequest.getHeader(ONAP_PARTNER_NAME_HEADER))) {
+ MDC.put(PARTNER_NAME, httpServletRequest.getHeader(ONAP_PARTNER_NAME_HEADER));
+ } else if (StringUtils.isNotEmpty(httpServletRequest.getHeader(USER_AGENT_HEADER))) {
+ MDC.put(PARTNER_NAME, httpServletRequest.getHeader(USER_AGENT_HEADER));
+ } else {
+ MDC.put(PARTNER_NAME, UNKNOWN);
+ }
+ }
+ }
+
+
@Override
public void destroy() {