Skip to Main Content

New

Role-Based Row Level Security in Oracle APEX

Published on 28 Jan 2026 by CHATURVEDINIDHI26@GMAIL.COM


Enterprise applications me data security sirf login tak limited nahi hoti.
Sabse important hota hai β€œkaun sa user kaunsa data dekh sakta hai” β€” especially jab multi-tenant architecture ho.

Is article me hum dekhenge:

  • Oracle APEX me row-level access control
  • Global Admin, Tenant Admin aur Team users ke liye clear rules
  • Ek reusable PL/SQL function ke through secure implementation

🎯 Business Requirement

Application me multiple organizations (tenants) hain aur users ke roles defined hain:

πŸ‘₯ Roles & Access Rules

RoleAllowed Data
Any UserSirf apna data
Global Administrator❌ Sirf apna data, kisi aur ka nahi
Tenant Administratorβœ… Apni team + apna data (same org)
Managers / Headsβœ… Same organization ka data

πŸ‘‰ Key Rule:

Global admin hone ka matlab β€œsab kuch dekhna” nahi hota.


🧠 Design Approach

Humne access control ko UI ya page-level pe hardcode karne ke bajay,
ek centralized PL/SQL function me define kiya.

Benefits:

  • βœ… Single source of truth
  • βœ… Easy to maintain
  • βœ… Reports, IGs, REST APIs sab jagah reusable
  • βœ… Secure & scalable

🧩 Core Concept

Har data row ke saath do important columns maan ke chalte hain:

  • CREATED_BY β†’ Data ka owner
  • ORG_PROFILE_ID β†’ Kis organization ka data

Logged-in user ka context hum nikalte hain:

 

SYS_CONTEXT('APEX$SESSION','APP_USER')


πŸ§ͺ Final PL/SQL Function

 

CREATE OR REPLACE FUNCTION xxeway_can_access_user (    p_created_by   IN VARCHAR2,    p_row_org_id   IN NUMBER ) RETURN NUMBER IS    l_role_static_id  xxeway_org_users.role_static_id%TYPE;    l_org_profile_id  xxeway_org_users.org_profile_id%TYPE;    l_app_user        VARCHAR2(200); BEGIN    l_app_user := SYS_CONTEXT('APEX$SESSION','APP_USER');    /* 1️⃣ SELF DATA – ALL USERS */    IF p_created_by = l_app_user THEN        RETURN 1;    END IF;    /* Logged-in user role & org */    SELECT MAX(role_static_id),           MAX(org_profile_id)    INTO   l_role_static_id,           l_org_profile_id    FROM   xxeway_org_users    WHERE  user_name = l_app_user    AND    active_fl = 'Y';    /* 2️⃣ GLOBAL ADMIN – ONLY SELF DATA */    IF l_role_static_id = 'GLOBAL_ADMINISTRATOR' THEN        RETURN 0;    END IF;    /* 3️⃣ TENANT ADMIN – TEAM DATA (SAME ORG) */    IF l_role_static_id = 'TENANT_ADMINISTRATOR'       AND p_row_org_id = l_org_profile_id THEN        RETURN 1;    END IF;    /* 4️⃣ MANAGERS – SAME ORG */    IF l_role_static_id IN (           'DEPARTMENT_HEAD',           'PROCUREMENT_MANAGER',           'WAREHOUSE_MANAGER'       )       AND p_row_org_id = l_org_profile_id THEN        RETURN 1;    END IF;    RETURN 0; END; / 


πŸ“Š How to Use in APEX Reports / IG

 

SELECT * FROM   your_table WHERE  xxeway_can_access_user(created_by, org_profile_id) = 1;

βœ” Automatically filtered data
βœ” No extra logic in page
βœ” Security handled centrally


πŸ” Why This Pattern Is Powerful

  • πŸ”’ True row-level security
  • πŸ” Reusable across modules
  • 🧩 Easy to extend (future roles)
  • πŸš€ Production-ready architecture

πŸš€ Possible Enhancements

  • Convert this logic into Authorization Scheme
  • Implement Database VPD (DBMS_RLS)
  • Add read-only vs edit access
  • Enable audit logging

βœ… Conclusion

Is approach se:

  • Global admin overpowered nahi hota
  • Tenant apni team manage kar sakta hai
  • Har user ka data secure rehta hai

Ye real-world enterprise-grade security model hai jo Oracle APEX applications ko robust & compliant banata hai.

πŸ“ Nidhi Blog

Sharing knowledge, tutorials, and stories about Oracle APEX, development, and digital growth.

πŸ“š Quick Links
πŸ“§ Contact

Email: support@nidhispace.com

Follow us on:
linkedin | YouTube


Β© Nidhi Blog. All rights reserved.