SLIM框架-如何使用SLIM制作访问控制列表? [英] SLIM Framework - How to make an Access Control List with SLIM?

查看:118
本文介绍了SLIM框架-如何使用SLIM制作访问控制列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问控制列表(ACL)定义一组规则,这些规则确定哪些用户组可以访问Slim应用程序中的哪些路由。

An Access Control List, or ACL, defines the set of rules that determines which group of users have access to which routes within your Slim application.

任何想法在SLIM中使用访问控制列表?

Any idea how to use Access Control List with SLIM ?

我尝试为我的REST API授权创建访问控制列表。

I try to create Access Control List for my REST API Authorization.

示例:


  • 角色成员只能从资源(/成员)访问GET,UPDATE

  • Role member only can access GET,UPDATE from resource (/member)

管理员成员只能从资源(/ admin)访问GET,UPDATE,POST,DELETE

Admin member only can access GET,UPDATE,POST,DELETE from resource (/admin)

任何想法如何用SLIM做到吗?

Any idea how to do it with SLIM ?

推荐答案

仍在学习,但是...在我的Slim路由中,您可以在控制器上调用方法。在该控制器中,为该特定方法命名权限。然后,只需使用 in_array()在用户访问数组中找到该值,即可在 $ _ SESSION 中保存该值。用户登录。

Still learning but... In my Slim routes, you can call a method on a controller. In that controller, name a permission for that specific method. Then just use in_array() to find that value in the user's access array you can save in the $_SESSION when the user logs in.

$this->get('/admin/users', 'AdminController:getUsers')->setName('admin.users');

AuthController类> getUsers方法>

AuthController class > getUsers method >

$permission = "view_users";

if(in_array($permission, $_SESSION['user']['access']) === false) {
  // show flash message, redirect- whatever
}

虽然现在大多数人都使用Zend Acl,但是我并没有走这条路去努力学习。

Most people use Zend Acl now though but I didn't go that route in an effort to learn.

这篇关于SLIM框架-如何使用SLIM制作访问控制列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆