Skip to content

Commit

Permalink
RANGER-5124 : The policy and tag active time are not in sync with the…
Browse files Browse the repository at this point in the history
… last update and policy download
  • Loading branch information
dineshkumar-yadav committed Feb 4, 2025
1 parent a90a77e commit 852d894
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions security-admin/src/main/java/org/apache/ranger/biz/AssetMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,28 +1051,64 @@ private void createOrUpdatePluginInfo(final RangerPluginInfo pluginInfo, int ent
final Runnable commitWork;

if (httpCode == HttpServletResponse.SC_NOT_MODIFIED) {
if (!pluginActivityAuditLogNotModified) {
RangerPluginInfo dbObj = null;
Long pluginActivationTime = null;
Long dbLastActivationTime = null;

if (StringUtils.isNotBlank(pluginInfo.getServiceName())) {
XXPluginInfo xObj = rangerDaoManager.getXXPluginInfo().find(pluginInfo.getServiceName(), pluginInfo.getHostName(), pluginInfo.getAppType());
if (xObj != null) {
dbObj = pluginInfoService.populateViewObject(xObj);
}
}

// Create or update PluginInfo record after transaction is completed. If it is created in-line here
// then the TransactionManager will roll-back the changes because the HTTP return code is
// HttpServletResponse.SC_NOT_MODIFIED

switch (entityType) {
case RangerPluginInfo.ENTITY_TYPE_POLICIES:
isTagVersionResetNeeded = rangerDaoManager.getXXService().findAssociatedTagService(pluginInfo.getServiceName()) == null;

pluginActivationTime = pluginInfo.getPolicyActivationTime();
dbLastActivationTime = dbObj != null ? dbObj.getPolicyActivationTime() : null;
break;
case RangerPluginInfo.ENTITY_TYPE_TAGS:
isTagVersionResetNeeded = false;

pluginActivationTime = pluginInfo.getTagActivationTime();
dbLastActivationTime = dbObj != null ? dbObj.getTagActivationTime() : null;
break;
case RangerPluginInfo.ENTITY_TYPE_ROLES:
isTagVersionResetNeeded = false;

pluginActivationTime = pluginInfo.getRoleActivationTime();
dbLastActivationTime = dbObj != null ? dbObj.getRoleActivationTime() : null;
break;
case RangerPluginInfo.ENTITY_TYPE_USERSTORE:
isTagVersionResetNeeded = false;

pluginActivationTime = pluginInfo.getUserStoreActivationTime();
dbLastActivationTime = dbObj != null ? dbObj.getUserStoreActivationTime() : null;
break;
case RangerPluginInfo.ENTITY_TYPE_GDS:
isTagVersionResetNeeded = false;

pluginActivationTime = pluginInfo.getGdsActivationTime();
dbLastActivationTime = dbObj != null ? dbObj.getGdsActivationTime() : null;
break;
default:
isTagVersionResetNeeded = false;
break;
}

boolean isLastActivationTimeUpdateNeeded = pluginActivationTime != null && pluginActivationTime > 0 && (dbLastActivationTime == null || !dbLastActivationTime.equals(pluginActivationTime));

if (!pluginActivityAuditLogNotModified && !isLastActivationTimeUpdateNeeded) {
logger.debug("Not logging HttpServletResponse. SC_NOT_MODIFIED. To enable, set configuration: {}=true", PROP_PLUGIN_ACTIVITY_AUDIT_NOT_MODIFIED);

commitWork = null;
} else {
// Create or update PluginInfo record after transaction is completed. If it is created in-line here
// then the TransactionManager will roll-back the changes because the HTTP return code is
// HttpServletResponse.SC_NOT_MODIFIED

switch (entityType) {
case RangerPluginInfo.ENTITY_TYPE_POLICIES:
isTagVersionResetNeeded = rangerDaoManager.getXXService().findAssociatedTagService(pluginInfo.getServiceName()) == null;
break;
case RangerPluginInfo.ENTITY_TYPE_TAGS:
case RangerPluginInfo.ENTITY_TYPE_ROLES:
case RangerPluginInfo.ENTITY_TYPE_USERSTORE:
case RangerPluginInfo.ENTITY_TYPE_GDS:
default:
isTagVersionResetNeeded = false;
break;
}

commitWork = () -> doCreateOrUpdateXXPluginInfo(pluginInfo, entityType, isTagVersionResetNeeded, clusterName);
}
} else if (httpCode == HttpServletResponse.SC_NOT_FOUND) {
Expand Down

0 comments on commit 852d894

Please sign in to comment.