home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / database / sybase / 754 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.8 KB

  1. Path: sparky!uunet!think.com!spool.mu.edu!sol.ctr.columbia.edu!destroyer!news.itd.umich.edu!spencer
  2. From: spencer@med.umich.edu (Spencer W. Thomas)
  3. Newsgroups: comp.databases.sybase
  4. Subject: Restricting access to rows?
  5. Date: 27 Jan 93 15:33:37
  6. Organization: University of Michigan HSITN
  7. Lines: 61
  8. Message-ID: <SPENCER.93Jan27153337@guraldi.med.umich.edu>
  9. NNTP-Posting-Host: guraldi.itn.med.umich.edu
  10.  
  11. Is there some easy way to do this?
  12.  
  13. I want to restrict access to a table according to the value of a
  14. certain field, by user, according to a second "authorization" table.
  15. I.e.,
  16.  
  17. create table base (
  18.     category    int,    /* The field to restrict access by. */
  19.     data        int
  20. )
  21.  
  22. create table auth (
  23.     uid        smallint,
  24.     category    int
  25. )
  26.  
  27. Each user who is allowed to see rows with a given value for 'category'
  28. has an entry in the 'auth' table with his/her uid and the category:
  29.  
  30. uid    category
  31. ----    --------
  32. 2    1        User 2 can see categories 1&2
  33. 2    2
  34. 3    3        User 3 can only see category 3
  35. 4    1        User 4 can see categories 1,2&3
  36. 4    2
  37. 4    3
  38.  
  39. My thought was to use a view.  Try 1:
  40.  
  41. create view stuff_1 as 
  42.     select * from base where category in 
  43.         (select category from auth where uid=user_id())
  44.  
  45. This works fine for select, but can't be updated because it has an
  46. aggregate (the 'in' in the select clause, I assume).
  47.  
  48. Try #2:
  49.  
  50. create view stuff_2 as
  51.     select base.category,data from base,auth where
  52.         base.category=auth.category and auth.uid=user_id()
  53.  
  54. This works for select, insert, and update, but not for delete.
  55.  
  56. Try #3:
  57.  
  58. As user 2:
  59.  
  60. create view stuff_3 as
  61.     select * from base where category in (1,2)
  62.  
  63. This works, but ONLY IF user 2 has permissions on the base table.
  64. Clearly, that defeats the whole purpose.
  65.  
  66. Any ideas?
  67.  
  68. --
  69. =Spencer W. Thomas         |  Info Tech and Networking, B1911 CFOB, 0704
  70.    "Genome Informatician"    |  Univ of Michigan, Ann Arbor, MI 48109
  71. Spencer.W.Thomas@med.umich.edu    |  313-747-2778, FAX 313-764-4133
  72.