Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6346755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:04:45+00:00 2026-05-24T21:04:45+00:00

I have a need to bring some role based content (several pieces resulting into

  • 0

I have a need to bring some role based content (several pieces resulting into one object) from the database to a service layer. Access to each content piece will depend on the role that the user has. If the user role has no access to a piece, that one will be empty. This is not a huge application, just a web service method exposing some content based on roles.

I could do this in three ways.

1) Based on the user role, make database calls for each piece of content.

Pros – The roles are managed in the code thus helping business logic (?) stay in the code. Only brings back data that is needed.

Cons – Multiple db calls. Code needs to be modified when a new role is added. (unless some really complicated business logic is used.)

2) Make a single db call and bring back all the content pieces as separate results sets. Loop through the sets and obtain pieces based on the user role.

Pros – Single db call. Roles are managed within the code.

Cons – Code needs to be modified for new roles. Extra data is brought back though it may not be needed. Those unneeded queries can add a couple of seconds.

3) Send the roles to the db and get each piece based on the role access.

Pros – single db call. Only brings back what is needed. No need to change code for new roles as only stored procedure needs to change.

Cons – Business logic in the database?


It looks to me that #3 > #2 > #1. (overriden > to mean better than)

Does anyone have any insights into which approach may be better?

Update -based on some comments, some more details are below.

User role is obtained from another system. #3 would ideally pass it to the db, and in crude terms for the db, return data as- if user_role =”admin”, get all pieces, for “editor” get content pieces 1,3 and 55. Again, this is not a big application where the role management is done in the db. Its a web service method to expose some data for several companies.

We obviously cannot use this model for managing the roles across an application. But for a method level access control as in this scenario, I believe #3 is the best way. Since the roles come from another system than where the content resides, the logic to control access to different content pieces has to reside somewhere. The database looks like the right place to have a maintainable,scalable, less hassle solution in this particular scenario. Perhaps, even create a look up table in the content db to hold roles and content piece access to give a sense of “data” and “logic” separation, rather than having a udf to perform the logic.

If no one can think of a valid case against #3, I think I’ll go ahead with it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:04:46+00:00Added an answer on May 24, 2026 at 9:04 pm

    I would always pick option 3 and enforce it in the database itself.

    Security is best handled at the closest point to the actual data itself for a lot of reasons. Look at it this way: It is more common for an additional application to be added in a different language than it is to toss a database model. When this happens all of your role handling code would have to be duplicated.

    Or let’s say the application is completely bypassed during a hack. The database should still enforce it’s security.

    Finally, although people like separating “business logic” from their data, the reality is that most data has no meaning without said logic. Further “security logic” isn’t the same thing as regular “business logic” anyway. It is there to protect you and your clients. But that’s my $0.02.


    Looking at your other options:

    2) You are sending too much data back to the client. This is both a security and performance no no. What if your app isn’t the one making the data request? What if you have a slight bug in your app that shows too much to the user?

    1 and 2) Both require redeploy for even slight logic changes (such as fixing the mythical bug above). This might not be desired. Personally, I prefer making minor adjustments to stored procedures over redeploying code. On a sizeable enough project it might be difficult to know exactly what all is being deployed and just generally has a higher potential of problems.

    UPDATE

    Based on your additional info, I still suggest sticking with #3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql server database that I want to bring into a datagrid.
I need to bring some data into an IObservable stream. I want to use
I'm doing some policy-based designs here and I have the need to typedef lots
I have need to select a number of 'master' rows from a table, also
I have need to return multiple results from a subquery and have been unable
I have need to pack four signed bytes into 32-bit integral type. this is
I have files stored in one container within a blob storage account. I need
I have a method that is called on an object to perform some business
I have several log files of events (one event per line). The logs can
I have a requirement where I have to pass some values into the next

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.