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

fimugdha 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 4e6335e78 RANGER-5859 : Ranger Admin UI: Invalid or unsupported 
policyType in the URL is not redirected to the Page Not Found page (#1335)
4e6335e78 is described below

commit 4e6335e78081a7f8a93f430a0b348ee4c7c42afa
Author: Mugdha Varadkar <[email protected]>
AuthorDate: Tue Oct 27 13:57:50 2026 +0530

    RANGER-5859 : Ranger Admin UI: Invalid or unsupported policyType in the URL 
is not redirected to the Page Not Found page (#1335)
---
 .../main/webapp/react-webapp/src/utils/XAUtils.js  | 17 ++++++++++++
 .../src/views/PolicyListing/PolicyFormContext.jsx  | 26 ++++++++----------
 .../views/PolicyListing/PolicyListingTabView.jsx   | 32 +++++++++++++++-------
 3 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/security-admin/src/main/webapp/react-webapp/src/utils/XAUtils.js 
b/security-admin/src/main/webapp/react-webapp/src/utils/XAUtils.js
index 438caaf52..c33cb351f 100644
--- a/security-admin/src/main/webapp/react-webapp/src/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/react-webapp/src/utils/XAUtils.js
@@ -106,6 +106,23 @@ export const isRenderRowFilter = (rowFilterDef) => {
     : false;
 };
 
+// Returns the policy types (Access / Masking / Row Filter) supported by a 
service def.
+// Access is always supported; Masking and Row Filter depend on the service 
def.
+export const getSupportedPolicyTypes = (serviceDef) => {
+  const supportedPolicyTypes = [
+    RangerPolicyType.RANGER_ACCESS_POLICY_TYPE.value
+  ];
+  if (isRenderMasking(serviceDef?.dataMaskDef)) {
+    
supportedPolicyTypes.push(RangerPolicyType.RANGER_MASKING_POLICY_TYPE.value);
+  }
+  if (isRenderRowFilter(serviceDef?.rowFilterDef)) {
+    supportedPolicyTypes.push(
+      RangerPolicyType.RANGER_ROW_FILTER_POLICY_TYPE.value
+    );
+  }
+  return supportedPolicyTypes;
+};
+
 export const getUserAccessRoleList = () => {
   var userRoleList = [];
   filter(UserRoles, function (val, key) {
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyFormContext.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyFormContext.jsx
index c983682cf..48a60ebd5 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyFormContext.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyFormContext.jsx
@@ -19,11 +19,11 @@
 
 import React, { useEffect, useState } from "react";
 import { Outlet, useParams, useNavigate, useLocation } from "react-router-dom";
-import { cloneDeep, pick } from "lodash";
+import { cloneDeep, isUndefined, pick } from "lodash";
 import { Loader } from "Components/CommonComponents";
 import { fetchApi } from "Utils/fetchAPI";
 import { getServiceDef } from "Utils/appState";
-import { commonBreadcrumb } from "Utils/XAUtils";
+import { commonBreadcrumb, getSupportedPolicyTypes } from "Utils/XAUtils";
 
 const PolicyFormContext = () => {
   const { serviceId, policyType, policyId } = useParams();
@@ -74,19 +74,17 @@ const PolicyFormContext = () => {
     let serviceCompData = serviceDefs?.allServiceDefs?.find((serviceDef) => {
       return serviceDef.name == serviceData.type;
     });
-    if (serviceCompData) {
-      let serviceDefPolicyType = 0;
-      if (
-        serviceCompData?.dataMaskDef &&
-        Object.keys(serviceCompData.dataMaskDef).length != 0
-      )
-        serviceDefPolicyType++;
+
+    // `policyType` is only present in the URL on the create route
+    // (/service/:serviceId/policies/create/:policyType). The edit route
+    // (/service/:serviceId/policies/:policyId/edit) has no such param, so
+    // there is nothing to validate there.
+    if (serviceCompData && !isUndefined(policyType)) {
       if (
-        serviceCompData?.rowFilterDef &&
-        Object.keys(serviceCompData.rowFilterDef).length != 0
-      )
-        serviceDefPolicyType++;
-      if (+policyType > serviceDefPolicyType) navigate("/pageNotFound");
+        !getSupportedPolicyTypes(serviceCompData).includes(Number(policyType))
+      ) {
+        navigate("/pageNotFound");
+      }
     }
     let fetchedPolicyData = null;
     if (policyId) {
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyListingTabView.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyListingTabView.jsx
index 38468a39e..964c51355 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyListingTabView.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/PolicyListing/PolicyListingTabView.jsx
@@ -27,7 +27,8 @@ import {
   isRenderRowFilter,
   isKeyAdmin,
   isKMSAuditor,
-  updateTagActive
+  updateTagActive,
+  getSupportedPolicyTypes
 } from "Utils/XAUtils";
 import { Loader } from "Components/CommonComponents";
 import TopNavBar from "../SideBar/TopNavBar";
@@ -128,17 +129,28 @@ export const PolicyListingTabView = () => {
 
     setZones(getZones?.data || []);
 
-    dispatch({
-      type: "SERVICES_DATA",
-      allServicesData: getAllServicesData?.data || [],
-      serviceData: getServiceData?.data,
-      serviceDefData: getServiceDefData
-    });
-    if (!isEmpty(getServiceData) && !isEmpty(getServiceDefData)) {
+    let isInvalidPolicyType = false;
+    if (!isEmpty(getServiceDefData)) {
+      isInvalidPolicyType = !getSupportedPolicyTypes(
+        getServiceDefData
+      ).includes(Number(params.policyType));
+    }
+
+    if (isInvalidPolicyType) {
+      navigate("/pageNotFound");
+    } else {
       dispatch({
-        type: "SET_LOADER",
-        loader: false
+        type: "SERVICES_DATA",
+        allServicesData: getAllServicesData?.data || [],
+        serviceData: getServiceData?.data,
+        serviceDefData: getServiceDefData
       });
+      if (!isEmpty(getServiceData) && !isEmpty(getServiceDefData)) {
+        dispatch({
+          type: "SET_LOADER",
+          loader: false
+        });
+      }
     }
     document
       .getElementById("resourceSelectedZone")

Reply via email to