api访问权限控制

2021-07-04 04:28

阅读:349

标签:ref   hub   get   erlang   lan   openresty   nbsp   rmi   perm   

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

  

api访问权限控制

标签:ref   hub   get   erlang   lan   openresty   nbsp   rmi   perm   

原文地址:https://www.cnblogs.com/yanbiao/p/9870419.html


评论


亲,登录后才可以留言!