Forum Discussion

webchris's avatar
webchris
Icon for Advocate III rankAdvocate III
2 years ago
Solved

Fabric - Row Level Security on Warehouse - Stage 2...

Good morning   I have one more question regarding the Row Level Security and how to implement it in Fabric warehouses.   In my setup, I do have one table, that shows all users and which products ...
  • webchris's avatar
    2 years ago

    Okay, I managed to find a solution...

     

    In my setup, I do have one table, that shows all users and which products each of them is allowed to see, e.g.:
    Table ProductsPerUser

    UserProduct
    [email protected]2345
    [email protected]1234
    [email protected]2345
    [email protected]5678

     

    To derive the Products the user is allowed to see, I had to extend the security function as follows:

    CREATE FUNCTION
        [SC_Security].[fn_securityProducts](@Product AS INT)
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
        SELECT 1 AS result
        FROM
            ProductsPerUser PPU
            INNER JOIN
            Products PROD
            ON PPU.Product = PROD.Product
        WHERE (PPU.User = USER_NAME() OR USER_NAME() = 'dbo')
        AND PROD.Product = @Product
    GO

    Now, I can implement the security policy on each table that has the "Product" as a field.

     

    Works like a charm...