douyao2529 2013-08-23 07:33
浏览 20

基于操作的用户访问级别

I'm developing a small site. It has a Product page on where users can perform CRUD functionality with some exporting, uploading etc. actions. I'm configuring the page level actions in a table. Actions are like ProductView, ProductDetailsView, ProductInsert, ProductUpdate, ProductDelete, ProductExport, ProductUploadViaFile etc.

I'm developing role based on action level on pages. Like Role1 has permission to menu Product.php and it has action permission of ProductView and ProductInsert on that page. Suppose user1 has role Role1.

When user1 is going to the page Product.php and then I'm checking its action permission. If he has ProductView I'm showing the product table to the user1. I'm finding that the code is pretty much hard coded in the javascript/php level. like

foreach($useractions in $useraction){
   if($useraction == 'ProductView'){
      //show the product page....
   }
   if($useraction == 'ProductInsert')
   {
     //show create button
   }
}

Looks like I have to create a lot more code when there is action level permissions. Again in case of another action insert I have to change the UI level coding again. I hope there is a better way to do this. Any suggestions will help a lot.

  • 写回答

1条回答 默认 最新

  • douping5226 2013-09-19 19:05
    关注

    You want to externalize the authorization logic from your application so that:

    1. you do not have to rewrite authorization code all over all the time
    2. you can maintain authorization independently

    The main standard in that space is XACML, the eXtensible Access Control Markup Language. Have a look at the OASIS XACML webpage and Wikipedia for more information.

    XACML gives you the notion of an enforcement point (PEP) or interceptor. That PEP reaches out to the authorization engine or policy decision point (PDP). The PDP considers its policies and eventually reaches a decision (either permit or deny).

    For instance:

    1. The PEP asks: can user Alice view the products page?
    2. the PDP looks at its policies and sees that managers can view products pages. It retrieves Alice's role and sees that Alice is a manager.
    3. the PDP concludes yes permit and returns that to the PEP.

    I hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算