• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    Go
  • License
    Other
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

权限管理服务平台, 利用shiro权限管理设计思想, 支持单用户多角色,比RBAC的资源管理更细粒度化

权限管理服务平台

该服务采用比较流行的微服务思想, 利用shiro<域,动作,实体>思想,实现权限管理平台服务, 它支持单用户多角色 , 比RBAC的资源管理更细粒度化

权限管理服务平台的实现,主要由三个步骤构成:

  • 第一步:判断URL是否在白名单中,如果是,直接返回状态码:200
  • 第二步:解析URL,获取功能ID和实体ID,服务初始化阶段,会构建多叉树
  • 第三步:获取<域,动作,实体>, 并在redis中采用SET集合存储<UserId-FuncId, SET集合={实体1, 实体2, ... , 实体N}>

权限管理库表设计

权限管理库表

环境依赖

OpenResty配置

权限管理安插在Nginx Access访问阶段,对http请求的合法性进行校验

access_by_lua_file "/data/openresty/lua_files/test_ycfm_lua_files/access_by_grbac.lua"

-- GRBAC权限管理模块
ngx.req.read_body()
local bodyData = ngx.req.get_body_data()
ngx.log(ngx.ERR, "body data:", bodyData)
local cjson = require "cjson"
local info={
        ["body"] =  bodyData,
        ["method"] = ngx.req.get_method(),
        ["uri"] = ngx.var.uri,
}
local encode = cjson.encode(info)
local res = ngx.location.capture('/v1/grbac/functions/tree_parsing', {method=ngx.HTTP_POST, body=encode})
if res.status == 403 then
        ngx.exit(ngx.HTTP_FORBIDDEN)
end
--- 这里需要注意的地方:
--- 当http请求头Content-type: multipart/form-data时,由于子请求继承父请求的信息,导致body无法改变
--- 需要在nginx中location ~ /v1/grbac体中增加下面一句:
——- `proxy_set_header   Content-Type   "application/x-www-form-urlencoded"`;
--- 这样做body=encode才能生效

DEMO

demo

解析树性能测试结果

测试数据:

functions表: 共259条
role_function_relationships表:1036条
roles表: 7条
user_roles表: 31条
white_list表: 85条

可以看到一个请求耗时平均: 0.108ms

ab结果中指标说明,可参考ab test

ab -c 8000 -n 800000 -p post.txt -H "Accept: application/json"  -H "XXXX-XXXX-XXX-Id: 12" -H "XXXX-XXXX-XXXX-Id: 3"  http://120.**.**.193:30100/v1/grbacs/functions/tree_parsing
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 120.**.**.193 (be patient)
Completed 80000 requests
Completed 160000 requests
Completed 240000 requests
Completed 320000 requests
Completed 400000 requests
Completed 480000 requests
Completed 560000 requests
Completed 640000 requests
Completed 720000 requests
Completed 800000 requests
Finished 800000 requests


Server Software:
Server Hostname:        120.**.**.193
Server Port:            30040

Document Path:          /v1/grbacs/functions/tree_parsing
Document Length:        0 bytes

Concurrency Level:      8000
Time taken for tests:   86.028 seconds
Complete requests:      800000
Failed requests:        0
Total transferred:      92800000 bytes
Total body sent:        265600000
HTML transferred:       0 bytes
Requests per second:    9299.33 [#/sec] (mean)
Time per request:       860.277 [ms] (mean)
Time per request:       0.108 [ms] (mean, across all concurrent requests)
Transfer rate:          1053.44 [Kbytes/sec] received
                        3015.02 kb/s sent
                        4068.46 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   47 219.0      3    7025
Processing:    22  810  96.5    798    2066
Waiting:       19  806  96.6    794    2050
Total:         24  857 242.3    807    7837

说明

  • 希望与大家一起成长,有任何该服务运行或者代码问题,可以及时找我沟通,喜欢开源,热爱开源, 欢迎多交流
  • 联系方式:[email protected]

More Repositories

1

prometheus

Prometheus官网的非官方中文手册,旨在为大家提供一个比较容易入手的文档。翻译得不好,请大家多多包涵,并帮忙修订校正
1,031
star
2

daprdocs

主要是介绍dapr以及精读dapr的源码
104
star
3

official_account

公众号第三方托管平台,包括公众号授权、微信支付和模板消息等公众号托管业务
Go
44
star
4

wx_relay_server

微信公众号第三方平台中继服务器,用于刷新公众号平台自身的token和托管的公众号token, 使开发者只关注微信公众号第三方平台的业务逻辑,同时业务实例可以反复重启,不会对已托管的公众号造成任何影响
Go
43
star
5

oklog

translation OKLog
Go
40
star
6

opentracing

OpenTracing分布式跟踪系统标准和源码阅读
22
star
7

istio-learning

istio框架及数据流和代码分析,了解整个istio的数据模型等
Go
21
star
8

message_middleware

为了促进产品的平台化建设, 把kafka消息队列从服务中抽象出来。让消息队列只关注消息的订阅和发布,使用微服务,减少与业务逻辑的耦合, 该服务支持多实例部署
Go
19
star
9

slicelement

Go library for finding element in slice type or operating set including union, interaction and difference.
Go
10
star
10

notebook

后端架构学习笔记, 学无止境
6
star
11

gaodemaps

gaode maps location data export
Python
3
star
12

jaeger

裁剪并汉化jaeger
Go
3
star
13

sms

短信服务,包括创蓝和云片网
Go
3
star
14

tchannel-go

针对uber的tchannel-go框架,进行代码结构优化, 并汉化代码
Go
2
star
15

go-sdk-wrapper

service to adapter dapr go-sdk.
Go
2
star
16

goide

Linux环境下支持go的vim集成环境搭建
Vim Script
1
star