Using Oracle VPD, after adding a policy and creating a function, I was able to hide a column from unauthorized users.
But instead of (null) how can i show something like ‘xxxxxx’
Also in the function I am validation for the user login, like
if sys_context( 'userenv', 'session_user' ) = 'USER1'
what is the best approach to remove this hard coding in the function?
Thanks in advance.
in order to return text in the place of not null, you’d have to create a view over top of the table to change null into the static literal you wanted, as the only option in VPD would be to hide the rows or set the secret columns to NULL.
for your second part of your question, if you are using that check to determine who has access to the sensitive columns, you can use a role instead and have the VPD function check this like:
i.e. whomever has the role
XXXXXX(just create an appropriate role and grant it to your privileged users) set in their session can see the data. That way you don’t need to hard code a bunch of user ids.e.g:
if we create a role and grant it to a test user:
for my set up ive created a simple test table + a policy that stops people reading the
your_sec_colcolumn.now if we select from that table and we don’t have the
ACCESS_TABLEA_SEC_COLrole, we’d get:but you want a string like
xxxxx. VPD itself cannot do this, but a view could decodeNULLto that string.now selecting from the view will , depending on whether the role is set:
so VPD still protects your table against anyone selecting from it, but you’d have clients select from the view to get the literal string instead. If your protected strings can contain NULL, and you want to differentiate those from no access, you can put the role check in the view instead.