Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-06-29 : 04:21:37
|
The table creation script..if exists (select * from dbo.sysobjects where id = object_id(N'[guest].[Address_Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [guest].[Address_Test]GOif exists (select * from dbo.sysobjects where id = object_id(N'[guest].[User_Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [guest].[User_Test]GOif exists (select * from dbo.sysobjects where id = object_id(N'[guest].[Details_Test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [guest].[Details_Test]GOCREATE TABLE [guest].[Address_Test] ( [ID] [int] NOT NULL , [Address1] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Address2] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Address3] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]GOCREATE TABLE [guest].[User_Test] ( [UserRole] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [AllowedFields] [nvarchar] (300) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ) ON [PRIMARY]GOCREATE TABLE [guest].[Details_Test] ( [ID] [int] NULL , [FirstName] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [LastName] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [EmailId] [nvarchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ) ON [PRIMARY]GO Table values ....Table User_TestUserRole AllowedFieldsAdmin allDEO ID,FirstName,Address1Supervisor ID,FirstName,LastName,Address1,Address2Table Details_TestID FirstName LastName EmailId1 ABC XYZ abc@xyz.com 2 AAA BBB aaa@bbb.com3 XYZ ABC xyz@abc.comTable Address_TestID Address1 Address2 Address31 123 4562 456 456 7893 525 525 676 If we look at the User_Test table for every user there is a set of allowed fields. These fields can be different tables. What I'm try to figure out is based on this list of allowed fields is it possible to restrict the query the user executes.For example:A user with DEO role cannot execute a query with columns other than ID,FirstName,Address1 or he can can view or update only the columns of ID,FirstName,Address1.If the query is like "Select FirstName,LastName,EmailId,Address1,Address2,Address3 From Detail_Test,Address_Test Where Detail_Test.ID = Address_Test.ID"While a user with admin role can see all the values of this result, the user with DEO role should be able to see values for the columns specified in AllowedFields in the User_Test table...Any ideas pointers???Karunakaran___________It's better to be loved and lost, than ever to be loved... |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-06-29 : 04:31:13
|
| check column level permission--------------------keeping it simple... |
 |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-06-29 : 05:26:41
|
Jen,I suppose, the column level permission can be granted only for users created in sql server itself. If you look at the code I have userrole is in a separate table these userroles might not be in the database.Kind of custom ones...The other problem I noticed is when a specific userrole executes a query with columns where the userrole dont have a permission then I will get an error.But what I need is the query to just return a result with the columns where that userrole has permissions.Say DEO executes the following query Select FirstName,LastName,EmailId,Address1,Address2,Address3 From Detail_Test,Address_Test Where Detail_Test.ID = Address_Test.ID I will get an error stating that Select permission denied. Instead what I want the query to return is the values of ID,FirstName,Address1 columns, other columns can be null not in the resultset at all...something like this....Result 1:ID FirstName Address11 ABC 1232 AAA 4563 XYZ 525ORResult 2:ID FirstName Address1 Othercolumns...1 ABC 123 Null 2 AAA 456 Null 3 XYZ 525 NullThe basic idea is whether I can manage custom userlevel access to data from front end or not...Kind of security excerise...May be asking for too much....? Karunakaran___________It's better to be loved and lost, than ever to be loved... |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-06-29 : 15:52:42
|
>>May be asking for too much....?column/row level security as well as application object security is not asking too much. However, covering a general "how to" in a forum thread may be. :)Homegrown security schemes can be quite varied. You obviously need to take your application architecture into account when designing the security. Often a hiearchal approach is used that starts with application modules and works through application controls and finally down to specific data columns and rows. The result is achieved with a coordinated effort between the application tiers and the database. How that division of labor is decided upon depends on the approach and the expertise of the resources.Having said all that, here is one (off the top of my head) way to accomplish what you actually asked for:set nocount oncreate table TGuser (userid int identity(1,1), username varchar(30))create table TGRole (roleid int identity(1,1), rolename varchar(30))gocreate table TGUserRole (userid int, roleid int)gocreate table TGDataSecurity (roleid int, tablename varchar(30), columnname varchar(30), accesslevel char(1))create table TGDataTable (companyid int, companyname varchar(30), acctBal money, foundedDate datetime)goinsert TGuser (username) select 'tg' union select 'Karuna'insert TGrole (rolename) select 'Admin' union select 'user'insert TGuserrole (userid, roleid) select 1,1 union select 2,2goinsert TGDataTable select 1,'tg''s company', 20, getdate()goinsert TGdatasecurity (roleid, tablename, columnname, accesslevel)select 2, 'TGDataTable', 'acctBal', 'H' --(hidden, readonly, etc...)union select 2, 'TGDataTable', 'foundedDate', 'R'go-------------------------------------------------------------Stored Procedure input parameterscreate proc TGTestColumnSecurity @userid intasdeclare @hideAcctBal bit ,@hideFoundedDate bitselect @HideAcctBal = convert(bit,sum(acctBal)) ,@HideFoundedDate = convert(bit,sum(foundedDate))from ( select userid ,tablename ,columnname ,acctBal = case when columnname = 'acctBal' then 1 else 0 end ,foundedDate = case when columnname = 'dateFounded' then 1 else 0 end from TGDataSecurity a join TGuserRole b on a.roleid = b.roleid where b.userid = @userid and tablename = 'TGDataTable' and columnname in ('acctBal', 'foundedDate') and accessLevel = 'H' ) aselect CalledByUser = @Userid ,companyid ,companyname ,acctBal = case when @HideAcctBal = 1 then null else acctBal end ,foundedDate = case when @HidefoundedDate = 1 then null else foundedDate endfrom TGDataTablegoexec TGTestColumnSecurity 1exec TGTestColumnSecurity 2drop proc TGTestColumnSecuritydrop table TGdatatabledrop table TGDataSecuritydrop table TGUserRoledrop table TGroledrop table TGUserBe One with the OptimizerTG |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-06-29 : 22:46:46
|
| will it work for you if you can control the users using views or selective sproc for specific columns?otherwise, you're talking dsql to build the query as implied by TG--------------------keeping it simple... |
 |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-06-30 : 00:03:14
|
quote: Originally posted by TG >>May be asking for too much....?column/row level security as well as application object security is not asking too much. However, covering a general "how to" in a forum thread may be. :)Be One with the OptimizerTG
TG, We have a seperate security module in the application where we are planning to handle this issue. My idea is to see if I can filter it in db query level itself so that can avoid much hassles at front end level coding. Since its very early for us to decide upon anything just exploring the possiblities...BTW, Thanks for all your help with my previous posts, which helped me a lot in completing the application. quote: >>will it work for you if you can control the users using views or selective sproc for specific columns?>>otherwise, you're talking dsql to build the query as implied by TG
Jen,I'll check the options.Jen,The total users will be some where around 100+ or so..., the records might be around 300,000+, So dsql might not affect much I suppose...Let me check the options and post it here....Karunakaran___________It's better to be loved and lost, than ever to be loved... |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-06-30 : 09:02:20
|
>>otherwise, you're talking dsql to build the query as implied by TGDid I imply that? I didn't mean to . When you say dsql does that mean dynamic sql? or dumb sql? I guess if it's the latter, I'm guilty.Be One with the OptimizerTG |
 |
|
|
|
|
|
|
|