472,960 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Implementing row-level security (SQL/AD)

Br
I'm going to go into a fair bit of detail as I'm hoping my methods may
be of assistance to anyone else wanting to implement something similar
(or totally confusing:)

One of systems I've developed has three levels of security.

Admins - can see all records
Manager - can only see records based on an organisation structure held
in a table (simple tree structure)
Employee - can only see own records

The system uses a table which contains 'login', 'employeeid' (level is
determined from security group/role)

User account creation is controlled by a form which forces the account
to be associated with an employeeid (if manager/employee level). This is
the critical step.

I then use queries (row-level security) to return only the employee
records that person can view based on the user role and the employeeid.
(This has been implemented in both Access and for SQL backends).

Still with me? :)

In our Access version that is all fine and works well. In SQL however it
means that all security still has to be administered through the client
software to link employee's to a login.

User account details are entered into a form and then I use a stored
procedure that creates an SQL account, give permissions to the database,
assign the user to a database role and then create an entry in my users
table linking them to an employee record. I then put a user-defined
function as the criteria in my views so they return only the appropriate
employee records. The function checks the current database role and gets
the current user's employeeid from the user table and then returns a
true/false if that employeeid is valid for the person to see.

Admin level - allow all records

Manager level - This one is a little trickier since it's not just
returning all the employee's that belong to the organisation unit that
the person manages but also all the people of the sub-units as well (it
needs to cascade all the way down the tree levels). This is done by
creating a special field in the organisation table which contains a
string of all the parent ID's in the structure for each unit (eg. unit
12's string might be ';1;5;12;'). This allows a simple query to be used
(eg. a criteria of LIKE *;5;* returns all the organisation units who are
children, grand-children, etc of unit 5).

Employee level - return only records for current user's employeeid

The link between the login and an employee record is the hurdle I can't
seem to get past. I can't see any other way to implement this type of
security.

The reason we want to remove administration from the client is so the
administration can be done solely on the server or even better using
Active Directory.

This is probably "pie in the sky" stuff but it would be nice to be able
to determine this link automatically or use some other method.

ie. if domain\group is given manager level access to the database (ie.
made a member of my manager database role in SQL) then a member of this
windows group then has access to the database but somehow can only see
the records of the people they manage???

I might have to create a mixed environment where manager/employee level
is for user accounts (requiring a link to be made to an employee record
manually via the client), whereas admin level can be for either user
accounts or groups.....
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #1
3 3247
Br@dley wrote:
I'm going to go into a fair bit of detail as I'm hoping my methods may
be of assistance to anyone else wanting to implement something similar
(or totally confusing:)

One of systems I've developed has three levels of security.

Admins - can see all records
Manager - can only see records based on an organisation structure held
in a table (simple tree structure)
Employee - can only see own records

The system uses a table which contains 'login', 'employeeid' (level is
determined from security group/role)

User account creation is controlled by a form which forces the account
to be associated with an employeeid (if manager/employee level). This is
the critical step.

I then use queries (row-level security) to return only the employee
records that person can view based on the user role and the employeeid.
(This has been implemented in both Access and for SQL backends).

Still with me? :)

In our Access version that is all fine and works well. In SQL however it
means that all security still has to be administered through the client
software to link employee's to a login.

User account details are entered into a form and then I use a stored
procedure that creates an SQL account, give permissions to the database,
assign the user to a database role and then create an entry in my users
table linking them to an employee record. I then put a user-defined
function as the criteria in my views so they return only the appropriate
employee records. The function checks the current database role and gets
the current user's employeeid from the user table and then returns a
true/false if that employeeid is valid for the person to see.

Admin level - allow all records

Manager level - This one is a little trickier since it's not just
returning all the employee's that belong to the organisation unit that
the person manages but also all the people of the sub-units as well (it
needs to cascade all the way down the tree levels). This is done by
creating a special field in the organisation table which contains a
string of all the parent ID's in the structure for each unit (eg. unit
12's string might be ';1;5;12;'). This allows a simple query to be used
(eg. a criteria of LIKE *;5;* returns all the organisation units who are
children, grand-children, etc of unit 5).

Employee level - return only records for current user's employeeid

The link between the login and an employee record is the hurdle I can't
seem to get past. I can't see any other way to implement this type of
security.

The reason we want to remove administration from the client is so the
administration can be done solely on the server or even better using
Active Directory.

This is probably "pie in the sky" stuff but it would be nice to be able
to determine this link automatically or use some other method.

ie. if domain\group is given manager level access to the database (ie.
made a member of my manager database role in SQL) then a member of this
windows group then has access to the database but somehow can only see
the records of the people they manage???

I might have to create a mixed environment where manager/employee level
is for user accounts (requiring a link to be made to an employee record
manually via the client), whereas admin level can be for either user
accounts or groups.....


First a carp, then a suggestion.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carp: Having more than one value in a column violates 1NF, i.e., each
cell must be atomic (only one piece of data in a cell [aka Field]). You
can solve your hierarchical problem by using nested sets. See this site
for an MS SQL version of a nested set solution:

http://toponewithties.blogspot.com/

Joe Celko has 2 books that discuss hierarchical tables. One is _Joe
Celko's SQL For Smarties: Advanced SQL Programming_. The other is
something like _Hierarchical SQL Tables_, not sure. There are also WEB
sites that talk about nested sets and other hierarchial solutions.

Suggestion: You can use a combination of Views & Stored Procedures to
limit users access to data. Once you set up a hierarchical employees
table you can use a View to retrieve only the rows/columns that user is
entitled to see. You can also use a stored procedure to determine which
View a user can use.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQuVBnYechKqOuFEgEQL6jACeNPWzjuTZqQC7OinsPhbti3 +LdwkAn04f
PVB2oJqII42qgBlJPYDgCbs7
=EajH
-----END PGP SIGNATURE-----
Nov 13 '05 #2
Br
MGFoster <me@privacy.com> wrote:
Br@dley wrote:
I'm going to go into a fair bit of detail as I'm hoping my methods
may be of assistance to anyone else wanting to implement something
similar (or totally confusing:)

One of systems I've developed has three levels of security.

Admins - can see all records
Manager - can only see records based on an organisation structure
held in a table (simple tree structure)
Employee - can only see own records

The system uses a table which contains 'login', 'employeeid' (level
is determined from security group/role)

User account creation is controlled by a form which forces the
account to be associated with an employeeid (if manager/employee
level). This is the critical step.

I then use queries (row-level security) to return only the employee
records that person can view based on the user role and the
employeeid. (This has been implemented in both Access and for SQL
backends). Still with me? :)

In our Access version that is all fine and works well. In SQL
however it means that all security still has to be administered
through the client software to link employee's to a login.

User account details are entered into a form and then I use a stored
procedure that creates an SQL account, give permissions to the
database, assign the user to a database role and then create an
entry in my users table linking them to an employee record. I then
put a user-defined function as the criteria in my views so they
return only the appropriate employee records. The function checks
the current database role and gets the current user's employeeid
from the user table and then returns a true/false if that employeeid
is valid for the person to see. Admin level - allow all records

Manager level - This one is a little trickier since it's not just
returning all the employee's that belong to the organisation unit
that the person manages but also all the people of the sub-units as
well (it needs to cascade all the way down the tree levels). This is
done by creating a special field in the organisation table which
contains a string of all the parent ID's in the structure for each
unit (eg. unit 12's string might be ';1;5;12;'). This allows a
simple query to be used (eg. a criteria of LIKE *;5;* returns all
the organisation units who are children, grand-children, etc of unit
5). Employee level - return only records for current user's
employeeid

The link between the login and an employee record is the hurdle I
can't seem to get past. I can't see any other way to implement this
type of security.

The reason we want to remove administration from the client is so the
administration can be done solely on the server or even better using
Active Directory.

This is probably "pie in the sky" stuff but it would be nice to be
able to determine this link automatically or use some other method.

ie. if domain\group is given manager level access to the database
(ie. made a member of my manager database role in SQL) then a member
of this windows group then has access to the database but somehow
can only see the records of the people they manage???

I might have to create a mixed environment where manager/employee
level is for user accounts (requiring a link to be made to an
employee record manually via the client), whereas admin level can be
for either user accounts or groups.....
First a carp, then a suggestion.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carp: Having more than one value in a column violates 1NF
Yes I know that. I've been developing for 10 years. The tables are
designed properly but I've included this concatenated field as it is the
only fast, easy way I could devise to filter out the records that I
want. I'm more than happy to live with it if it works and it is simple.
Other more elegant solution are very complex from what I've read so far
and in the real world justifying development time on something that
already works well is not always easy:)
, i.e., each
cell must be atomic (only one piece of data in a cell [aka Field]).
You can solve your hierarchical problem by using nested sets. See
this site for an MS SQL version of a nested set solution:

http://toponewithties.blogspot.com/
Funnily enough I've done a very similar thing to what this site is doing
except they are using prime numbers wheras I am just using a string of
ID's. My design works fine and is far less complicated for returning all
the branches below a unit. I'll read into it though as it's some good
theory.. but at this stage it's the least of my worries as the current
design works really well.

My biggest problem is having to rely on a table stored link between the
user and the employee in order to implement this type of security which
means security admin has to be done throught the client.
Joe Celko has 2 books that discuss hierarchical tables. One is _Joe
Celko's SQL For Smarties: Advanced SQL Programming_. The other is
something like _Hierarchical SQL Tables_, not sure. There are also
WEB sites that talk about nested sets and other hierarchial solutions.

Suggestion: You can use a combination of Views & Stored Procedures to
limit users access to data. Once you set up a hierarchical employees
table you can use a View to retrieve only the rows/columns that user
is entitled to see. You can also use a stored procedure to determine
which View a user can use.


This is pretty much what I am doing.....

- Organisation structure table (unitid, parentid, managerid, unitname,
parentstring)
- The only way I've found to cascade down every branch of the tree
structure is to build a string on each field that contains the path from
that node back to the top parent and then search for the parent's id in
each record as the criteria. It's not ideal but it is very simple and
works really well.
- I use a user-defined function as part of the criteria in a view to
work out if a record is viewable for the current user. I had to do it
this way as store procedures are not updateable nor are views with more
than one table in them (user's don't have access to underlying tables
obviously and I'm using an Access2000 ADP).
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #3
Br
Br@dley <n0****@4u.com> wrote:
MGFoster <me@privacy.com> wrote:
Br@dley wrote:
I'm going to go into a fair bit of detail as I'm hoping my methods
may be of assistance to anyone else wanting to implement something
similar (or totally confusing:)

One of systems I've developed has three levels of security.

Admins - can see all records
Manager - can only see records based on an organisation structure
held in a table (simple tree structure)
Employee - can only see own records

The system uses a table which contains 'login', 'employeeid' (level
is determined from security group/role)

User account creation is controlled by a form which forces the
account to be associated with an employeeid (if manager/employee
level). This is the critical step.

I then use queries (row-level security) to return only the employee
records that person can view based on the user role and the
employeeid. (This has been implemented in both Access and for SQL
backends). Still with me? :)

In our Access version that is all fine and works well. In SQL
however it means that all security still has to be administered
through the client software to link employee's to a login.

User account details are entered into a form and then I use a stored
procedure that creates an SQL account, give permissions to the
database, assign the user to a database role and then create an
entry in my users table linking them to an employee record. I then
put a user-defined function as the criteria in my views so they
return only the appropriate employee records. The function checks
the current database role and gets the current user's employeeid
from the user table and then returns a true/false if that employeeid
is valid for the person to see. Admin level - allow all records

Manager level - This one is a little trickier since it's not just
returning all the employee's that belong to the organisation unit
that the person manages but also all the people of the sub-units as
well (it needs to cascade all the way down the tree levels). This is
done by creating a special field in the organisation table which
contains a string of all the parent ID's in the structure for each
unit (eg. unit 12's string might be ';1;5;12;'). This allows a
simple query to be used (eg. a criteria of LIKE *;5;* returns all
the organisation units who are children, grand-children, etc of unit
5). Employee level - return only records for current user's
employeeid

The link between the login and an employee record is the hurdle I
can't seem to get past. I can't see any other way to implement this
type of security.

The reason we want to remove administration from the client is so
the administration can be done solely on the server or even better
using Active Directory.

This is probably "pie in the sky" stuff but it would be nice to be
able to determine this link automatically or use some other method.

ie. if domain\group is given manager level access to the database
(ie. made a member of my manager database role in SQL) then a member
of this windows group then has access to the database but somehow
can only see the records of the people they manage???

I might have to create a mixed environment where manager/employee
level is for user accounts (requiring a link to be made to an
employee record manually via the client), whereas admin level can be
for either user accounts or groups.....
First a carp, then a suggestion.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carp: Having more than one value in a column violates 1NF

<>
, i.e., each
cell must be atomic (only one piece of data in a cell [aka Field]).
You can solve your hierarchical problem by using nested sets. See
this site for an MS SQL version of a nested set solution:

http://toponewithties.blogspot.com/

Funnily enough I've done a very similar thing....


Actually I've implemented the Materialised Path method without knowing
it:)

"[using a] node's primary keys within the path string"
http://www.dbazine.com/oracle/or-articles/tropashko4

Obviously the limitation of this method is that the path strings needs
to be updated if records are changed. I simply rebuild all the strings
every time the user leaves the organisation screen as it is a very fast
operation to perform.

<>
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Allan Hart | last post by:
Hi.. I'd very much appreciate it if someone would tell me how to translate a statement level trigger written in Oracle to its equivalent (if there is one) in MS SQL Server. Ditto for a row...
1
by: Arska | last post by:
Hi Is it possible to force row level locking in one or more tables in some database. We have some problems when SQL Server decides to choose page- or table-level locking. We are using SQL...
12
by: Puvendran | last post by:
Hi, We have encountered deadlock on a table which is used to generate sequential numbers for different categories eg typical entries Category Value TRADE_NO ...
1
by: Elham.Ghoddousi | last post by:
How can I implement "Row Level Security" in SQL Server 2000? Thanks alot.
16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
5
by: Bomza | last post by:
Hi, I'm writing an application that involves data that has a set of users that are allowed to perform certain operations on it. i.e. Only the row owner can modify a row, but there is a set of...
3
by: gregory.sharrow | last post by:
I need to secure a datawarehouse table at the row level based on 1 to many keys on that table. A user should only see the rows they have access to. I need to be able to figure out which rows they...
2
by: robert | last post by:
well, talk about timely. i'm tasked to implement a security feature, and would rather do so in the database than the application code. the application is generally Oracle, but sometimes DB2. ...
1
by: Friends | last post by:
Hi I need to set security for row level but not based on Database user's login. It should be based on the user table login. For the particular user I need to allow only the particular records to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.