Skip to content

Commit

Permalink
RANGER-3611: fix NullPtrException in download API
Browse files Browse the repository at this point in the history
Signed-off-by: pradeep <pradeep@apache.org>
  • Loading branch information
ZhouTianling authored and pradeepagrawal8184 committed Apr 7, 2022
1 parent 7fc670b commit 88a375f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 29 deletions.
Expand Up @@ -674,7 +674,7 @@ public void run() {
return ret;
}

public void createPluginInfo(String serviceName, String pluginId, HttpServletRequest request, int entityType, Long downloadedVersion, long lastKnownVersion, long lastActivationTime, int httpCode, String clusterName, String pluginCapabilities) {
public void createPluginInfo(String serviceName, String pluginId, HttpServletRequest request, int entityType, Long downloadedVersion, Long lastKnownVersion, long lastActivationTime, int httpCode, String clusterName, String pluginCapabilities) {
RangerRESTUtils restUtils = new RangerRESTUtils();

final String ipAddress = getRemoteAddress(request);
Expand Down
Expand Up @@ -723,7 +723,7 @@ public List<String> getUserRoles(@PathParam("user") String userName, @Context Ht
@Produces({ "application/json", "application/xml" })
public RangerRoles getRangerRolesIfUpdated(
@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownRoleVersion") Long lastKnownRoleVersion,
@DefaultValue("-1") @QueryParam("lastKnownRoleVersion") Long lastKnownRoleVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand Down Expand Up @@ -751,9 +751,6 @@ public RangerRoles getRangerRolesIfUpdated(
logMsg = e.getMessage();
}
if (isValid) {
if (lastKnownRoleVersion == null) {
lastKnownRoleVersion = Long.valueOf(-1);
}
try {
RangerRoles roles = roleStore.getRoles(serviceName, lastKnownRoleVersion);
if (roles == null) {
Expand Down Expand Up @@ -793,7 +790,7 @@ public RangerRoles getRangerRolesIfUpdated(
@Produces({ "application/json", "application/xml" })
public RangerRoles getSecureRangerRolesIfUpdated(
@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownRoleVersion") Long lastKnownRoleVersion,
@DefaultValue("-1") @QueryParam("lastKnownRoleVersion") Long lastKnownRoleVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand Down Expand Up @@ -824,9 +821,6 @@ public RangerRoles getSecureRangerRolesIfUpdated(
logMsg = e.getMessage();
}
if (isValid) {
if (lastKnownRoleVersion == null) {
lastKnownRoleVersion = Long.valueOf(-1);
}
try {
XXService xService = daoManager.getXXService().findByName(serviceName);
if (xService == null) {
Expand Down
Expand Up @@ -2989,7 +2989,7 @@ private RangerPolicyList getServicePolicies(String serviceName, SearchFilter fil
@Produces({ "application/json", "application/xml" })
public ServicePolicies getServicePoliciesIfUpdated(
@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownVersion") Long lastKnownVersion,
@DefaultValue("-1") @QueryParam("lastKnownVersion") Long lastKnownVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand Down Expand Up @@ -3022,11 +3022,8 @@ public ServicePolicies getServicePoliciesIfUpdated(
httpCode = HttpServletResponse.SC_BAD_REQUEST;
logMsg = e.getMessage();
}
if (isValid) {
if (lastKnownVersion == null) {
lastKnownVersion = Long.valueOf(-1);
}

if (isValid) {
try {
if(RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServicePoliciesIfUpdated(serviceName=" + serviceName + ",lastKnownVersion=" + lastKnownVersion + ",lastActivationTime=" + lastActivationTime + ")");
Expand Down Expand Up @@ -3071,7 +3068,7 @@ public ServicePolicies getServicePoliciesIfUpdated(
@Produces({ "application/json", "application/xml" })
public ServicePolicies getSecureServicePoliciesIfUpdated(
@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownVersion") Long lastKnownVersion,
@DefaultValue("-1") @QueryParam("lastKnownVersion") Long lastKnownVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand Down Expand Up @@ -3104,10 +3101,8 @@ public ServicePolicies getSecureServicePoliciesIfUpdated(
httpCode = HttpServletResponse.SC_BAD_REQUEST;
logMsg = e.getMessage();
}

if (isValid) {
if (lastKnownVersion == null) {
lastKnownVersion = Long.valueOf(-1);
}
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getSecureServicePoliciesIfUpdated(serviceName=" + serviceName + ",lastKnownVersion=" + lastKnownVersion + ",lastActivationTime=" + lastActivationTime + ")");
Expand Down
15 changes: 4 additions & 11 deletions security-admin/src/main/java/org/apache/ranger/rest/XUserREST.java
Expand Up @@ -1299,7 +1299,7 @@ public void deleteSingleGroupByGroupId(@Context HttpServletRequest request, @Pat
@Path("/download/{serviceName}")
@Produces({ "application/xml", "application/json" })
public RangerUserStore getRangerUserStoreIfUpdated(@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownUserStoreVersion") Long lastKnownUserStoreVersion,
@DefaultValue("-1") @QueryParam("lastKnownUserStoreVersion") Long lastKnownUserStoreVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand All @@ -1313,8 +1313,9 @@ public RangerUserStore getRangerUserStoreIfUpdated(@PathParam("serviceName") Str
boolean isValid = false;
int httpCode = HttpServletResponse.SC_OK;
String logMsg = null;
Long downloadedVersion = null;

try {
try {
bizUtil.failUnauthenticatedIfNotAllowed();

isValid = serviceUtil.isValidService(serviceName, request);
Expand All @@ -1326,16 +1327,11 @@ public RangerUserStore getRangerUserStoreIfUpdated(@PathParam("serviceName") Str
logMsg = e.getMessage();
}

Long downloadedVersion = null;

if (isValid) {
try {
XXService xService = rangerDaoManager.getXXService().findByName(serviceName);

if (xService != null) {
if (lastKnownUserStoreVersion == null) {
lastKnownUserStoreVersion = Long.valueOf(-1);
}

RangerUserStore rangerUserStore = xUserMgr.getRangerUserStore(lastKnownUserStoreVersion);

Expand Down Expand Up @@ -1377,7 +1373,7 @@ public RangerUserStore getRangerUserStoreIfUpdated(@PathParam("serviceName") Str
@Path("/secure/download/{serviceName}")
@Produces({ "application/xml", "application/json" })
public RangerUserStore getSecureRangerUserStoreIfUpdated(@PathParam("serviceName") String serviceName,
@QueryParam("lastKnownUserStoreVersion") Long lastKnownUserStoreVersion,
@DefaultValue("-1") @QueryParam("lastKnownUserStoreVersion") Long lastKnownUserStoreVersion,
@DefaultValue("0") @QueryParam("lastActivationTime") Long lastActivationTime,
@QueryParam("pluginId") String pluginId,
@DefaultValue("") @QueryParam("clusterName") String clusterName,
Expand All @@ -1402,9 +1398,6 @@ public RangerUserStore getSecureRangerUserStoreIfUpdated(@PathParam("serviceName
isValid = true;
}
if (isValid) {
if (lastKnownUserStoreVersion == null) {
lastKnownUserStoreVersion = Long.valueOf(-1);
}
XXServiceDef xServiceDef = rangerDaoManager.getXXServiceDef().getById(xService.getType());
RangerService rangerService = svcStore.getServiceByName(serviceName);

Expand Down

0 comments on commit 88a375f

Please sign in to comment.