zoukankan      html  css  js  c++  java
  • api访问权限控制

    1.当用户登录时,在redis中存储对应的权限,在openresty配置要进行控制的权限,解析成一颗树

      

    2.在用户访问api时,通过用户id在openresty中提取权限,和权限树进行比较。

    local permission = MatchUrlTree(ngx.var.uri,ngx.req.get_method())
      if permission then
        local permission_json,err =redis_sess:get(permission_key)
        if permission_json == ngx.null or permission_json == "" then
          ngx.exit(ngx.HTTP_FORBIDDEN) 
        end
        local ok,permission_data = pcall(json.decode,permission_json)
        if not ok then 
          ngx.log(ngx.ERR, "json decode error")
          ngx.exit(ngx.OK)
        end
        if not permission_data[permission] then
          ngx.exit(ngx.HTTP_FORBIDDEN) 
        end
      end
    end
    作者:严彦彪 原创作品转载请注明出处
  • 相关阅读:
    其他标签
    数组和全局变量
    字符串处理
    运算符
    PHP安装配置工具
    String、StringBuffer与StringBuilder之间区别
    mybits——1
    异常
    ubuntu 系统错误:Error : BrokenCount > 0解决
    ubuntu配置VScode
  • 原文地址:https://www.cnblogs.com/yanbiao/p/9870419.html
Copyright © 2011-2022 走看看