This is an automated email from the ASF dual-hosted git repository.

dineshkumar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a132c5d0 RANGER-4132: If view policy button is clicked for a policy 
which is deleted, then the page gets stuck in loading state
9a132c5d0 is described below

commit 9a132c5d017c4f0a08837180625786a54539b758
Author: Brijesh Bhalala <brijeshbhalala2...@gmail.com>
AuthorDate: Wed Jul 12 14:57:44 2023 +0530

    RANGER-4132: If view policy button is clicked for a policy which is 
deleted, then the page gets stuck in loading state
    
    Signed-off-by: Dineshkumar Yadav <dineshkumar.ya...@outlook.com>
---
 .../main/java/org/apache/ranger/biz/XUserMgr.java  |  8 ++++++
 .../org/apache/ranger/common/RESTErrorUtil.java    | 31 ++++++++++++++++++++++
 .../main/java/org/apache/ranger/rest/RoleREST.java |  6 ++++-
 .../org/apache/ranger/rest/SecurityZoneREST.java   |  5 +++-
 .../java/org/apache/ranger/rest/ServiceREST.java   |  5 +++-
 .../main/webapp/react-webapp/src/utils/fetchAPI.js |  2 --
 .../src/views/AuditEvent/AdminLogs/PolicyLogs.jsx  |  4 ++-
 .../AuditEvent/AdminLogs/PolicyViewDetails.jsx     | 10 +++----
 .../views/PolicyListing/AddUpdatePolicyForm.jsx    |  2 +-
 .../users_details/EditUserView.jsx                 |  2 +-
 10 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java 
b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
index f653dbc8a..09154491d 100755
--- a/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
@@ -2031,6 +2031,10 @@ public class XUserMgr extends XUserMgrBase {
                xaBizUtil.blockAuditorRoleUser();
                XXGroupDao xXGroupDao = daoManager.getXXGroup();
                XXGroup xXGroup = xXGroupDao.getById(id);
+               if (xXGroup == null) {
+                       throw restErrorUtil.create404RESTException("Data Not 
Found for given Id", MessageEnums.DATA_NOT_FOUND, id,
+                                       null, "readResource : No Object found 
with given id.");
+               }
                VXGroup vXGroup = xGroupService.populateViewBean(xXGroup);
                if (vXGroup == null || StringUtils.isEmpty(vXGroup.getName())) {
                        throw restErrorUtil.createRESTException("Group ID 
doesn't exist.", MessageEnums.INVALID_INPUT_DATA);
@@ -2249,6 +2253,10 @@ public class XUserMgr extends XUserMgrBase {
                xaBizUtil.blockAuditorRoleUser();
                XXUserDao xXUserDao = daoManager.getXXUser();
                XXUser xXUser = xXUserDao.getById(id);
+               if (xXUser == null) {
+                       throw restErrorUtil.create404RESTException("Data Not 
Found for given Id", MessageEnums.DATA_NOT_FOUND, id,
+                                       null, "readResource : No Object found 
with given id.");
+               }
                VXUser vXUser = xUserService.populateViewBean(xXUser);
                if(vXUser==null || StringUtils.isEmpty(vXUser.getName())){
                        throw restErrorUtil.createRESTException("No user found 
with id=" + id);
diff --git 
a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java 
b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
index e0ff95814..4aaf36442 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
@@ -413,4 +413,35 @@ public class RESTErrorUtil {
                                restException);
                return restException;
        }
+
+       public WebApplicationException create404RESTException(String 
errorMessage,
+                       MessageEnums messageEnum, Long objectId, String 
fieldName,
+                       String logMessage) {
+               List<VXMessage> messageList = new ArrayList<VXMessage>();
+               messageList.add(messageEnum.getMessage(objectId, fieldName));
+
+               VXResponse gjResponse = new VXResponse();
+               gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
+               gjResponse.setMsgDesc(errorMessage);
+               gjResponse.setMessageList(messageList);
+
+               Response errorResponse = Response
+                               
.status(javax.servlet.http.HttpServletResponse.SC_NOT_FOUND)
+                               .entity(gjResponse).build();
+
+               WebApplicationException restException = new 
WebApplicationException(
+                               errorResponse);
+               restException.fillInStackTrace();
+               UserSessionBase userSession = 
ContextUtil.getCurrentUserSession();
+               String loginId = null;
+               if (userSession != null) {
+                       loginId = userSession.getLoginId();
+               }
+
+               logger.info("Request failed. loginId="
+                               + loginId + ", logMessage=" + 
gjResponse.getMsgDesc(),
+                               restException);
+
+               return restException;
+       }
 }
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java 
b/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
index a4dd6ef89..ca9f286b3 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java
@@ -53,6 +53,7 @@ import org.apache.ranger.common.UserSessionBase;
 import org.apache.ranger.common.PropertiesUtil;
 import org.apache.ranger.common.AppConstants;
 import org.apache.ranger.common.ContextUtil;
+import org.apache.ranger.common.MessageEnums;
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.entity.XXService;
 import org.apache.ranger.entity.XXServiceDef;
@@ -287,7 +288,10 @@ public class RoleREST {
         } catch(Throwable excp) {
             LOG.error("deleteRole(" + roleId + ") failed", excp);
 
-            throw restErrorUtil.createRESTException(excp.getMessage());
+            throw restErrorUtil.createRESTException(
+                                       "Data Not Found for given Id",
+                                       MessageEnums.DATA_NOT_FOUND, roleId, 
null,
+                                       "readResource : No Object found with 
given id.");
         }
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== deleteRole(id=" + roleId + ")");
diff --git 
a/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java 
b/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
index 66fa22163..55d6aaac5 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
@@ -241,7 +241,10 @@ public class SecurityZoneREST {
         } catch(Throwable excp) {
             LOG.error("deleteSecurityZone(" + zoneId + ") failed", excp);
 
-            throw restErrorUtil.createRESTException(excp.getMessage());
+            throw restErrorUtil.createRESTException(
+                                       "Data Not Found for given Id",
+                                       MessageEnums.DATA_NOT_FOUND, zoneId, 
null,
+                                       "readResource : No Object found with 
given id.");
         }
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== deleteSecurityZone(id=" + zoneId + ")");
diff --git 
a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java 
b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index ce26b1d66..a307293eb 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -4569,7 +4569,10 @@ public class ServiceREST {
                                        svcStore.deleteService(id);
                                } else {
                                        LOG.error("Cannot retrieve service:[" + 
id + "] for deletion");
-                                       throw new Exception("deleteService(" + 
id + ") failed");
+                                       throw restErrorUtil.createRESTException(
+                                                       "Data Not Found for 
given Id",
+                                                       
MessageEnums.DATA_NOT_FOUND, id, null,
+                                                       "readResource : No 
Object found with given id.");
                                }
                        } else {
                                LOG.error("Cannot retrieve user session.");
diff --git a/security-admin/src/main/webapp/react-webapp/src/utils/fetchAPI.js 
b/security-admin/src/main/webapp/react-webapp/src/utils/fetchAPI.js
index 5d9a7d5c4..ef32634bb 100644
--- a/security-admin/src/main/webapp/react-webapp/src/utils/fetchAPI.js
+++ b/security-admin/src/main/webapp/react-webapp/src/utils/fetchAPI.js
@@ -97,11 +97,9 @@ async function fetchApi(axiosConfig = {}, otherConf = {}) {
     }
     if (error?.response?.status === 404) {
       navigateTo.navigate("/pageNotFound", { replace: true });
-      return;
     }
     if (error?.response?.status === 403) {
       navigateTo.navigate("/forbidden", { replace: true });
-      return;
     }
     throw error;
   }
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyLogs.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyLogs.jsx
index abb58c94d..9c81e307d 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyLogs.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyLogs.jsx
@@ -1867,7 +1867,9 @@ export const PolicyLogs = ({ data, reportdata }) => {
               </Badge>
             </div>
             <div className="font-weight-bolder">Policy Name: {objectName}</div>
-            <div className="font-weight-bolder">Service Name: {owner}</div>
+            <div className="font-weight-bolder">
+              Service Name: {parentObjectName}
+            </div>
             <div className="font-weight-bolder">
               Created Date: {dateFormat(createDate, "mm/dd/yyyy hh:MM:ss TT ")}
               India Standard Time
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyViewDetails.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyViewDetails.jsx
index d74f9a83e..1f89900eb 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyViewDetails.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/PolicyViewDetails.jsx
@@ -76,10 +76,10 @@ export function PolicyViewDetails(props) {
     } catch (error) {
       console.error(`eventTime can not be undefined ${error}`);
     }
-    accessLogsServiceDef = allServiceDefs.find((servicedef) => {
-      return servicedef.name == accesslogs.data.serviceType;
+    accessLogsServiceDef = allServiceDefs?.find((servicedef) => {
+      return servicedef.name == accesslogs?.data?.serviceType;
     });
-    setAccess(accesslogs.data);
+    setAccess(accesslogs?.data);
     setServiceDef(accessLogsServiceDef);
     SetLoader(false);
   };
@@ -95,7 +95,7 @@ export function PolicyViewDetails(props) {
     } catch (error) {
       console.error(`versionNo can not be undefined ${error}`);
     }
-    setAccess(accesslogs.data);
+    setAccess(accesslogs?.data);
   };
 
   const fetchPolicyVersions = async () => {
@@ -115,7 +115,7 @@ export function PolicyViewDetails(props) {
       );
       serverError(error);
     }
-    setAccess(accesslogs && accesslogs.data);
+    setAccess(accesslogs?.data);
   };
 
   const {
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/AddUpdatePolicyForm.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/AddUpdatePolicyForm.jsx
index cc34488ea..13a8eaf4f 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/AddUpdatePolicyForm.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/AddUpdatePolicyForm.jsx
@@ -256,7 +256,7 @@ export default function AddUpdatePolicyForm(props) {
       });
       data = resp.data || null;
     } catch (error) {
-      console.error(`Error occurred while fetching service details ! 
${error}`);
+      console.error(`Error occurred while fetching policy details ! ${error}`);
     }
     return data;
   };
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/UserGroupRoleListing/users_details/EditUserView.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/UserGroupRoleListing/users_details/EditUserView.jsx
index e47fccc6f..73585458a 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/UserGroupRoleListing/users_details/EditUserView.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/UserGroupRoleListing/users_details/EditUserView.jsx
@@ -79,7 +79,7 @@ function AddUserView(props) {
       });
     } catch (error) {
       console.error(
-        `Error occurred while fetching Zones or CSRF headers! ${error}`
+        `Error occurred while fetching Users or CSRF headers! ${error}`
       );
     }
     dispatch({

Reply via email to