Skip to content

Commit

Permalink
feat: implementing authz using casbin
Browse files Browse the repository at this point in the history
Signed-off-by: daz-3ux <[email protected]>
  • Loading branch information
Daz-3ux committed Oct 8, 2023
1 parent 2bbd299 commit da9d33a
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/devel/zh-CN/conversions/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjgwMTY5MjIsImlkIjowLCJuYmYiOjE
- PUT 用于更新,是一个幂等操作

## 授权 - Authorization - Authz
- 使用 RBAC (Role-Based Access Control) 模型进行授权
- 使用 ACL (Access Control List) 模型进行授权
- 基于 [casbin](./useCasbin.md) 进行开发
-
- TODO: 实现使用 RBAC (Role-Based Access Control) 模型进行授权
8 changes: 4 additions & 4 deletions docs/devel/zh-CN/conversions/useCasbin.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
- 也就是对 API 路径进行授权
- 授权策略:

| A | B | C | D |
|---|------|----------------|--------------------------|
| p | root | /v1/users* | (GET)(POST)(PUT)(DELETE) |
| p | bob | /v1/users/belm | (GET)(POST)(PUT)(DELETE) |
| A | B | C | D |
|---|------|---------------|--------------------------|
| p | root | /v1/users* | (GET)(POST)(PUT)(DELETE) |
| p | bob | /v1/users/bob | (GET)(POST)(PUT)(DELETE) |

- 因为要对每一个 HTTP 进行授权, 所以将授权功能封装为中间件
25 changes: 24 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.21.0
require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/casbin/casbin/v2 v2.77.2
github.com/casbin/gorm-adapter/v3 v3.20.0
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/uuid v1.1.2
github.com/google/uuid v1.3.0
github.com/gosuri/uitable v0.0.4
github.com/jasonsoft/go-short-id v0.0.0-20180410073244-6ed30cc4305d
github.com/jinzhu/copier v0.4.0
Expand All @@ -25,18 +26,31 @@ require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/glebarez/go-sqlite v1.20.3 // indirect
github.com/glebarez/sqlite v1.7.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -46,12 +60,14 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microsoft/go-mssqldb v0.17.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.28.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230126093431-47fa9a501578 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
Expand All @@ -70,4 +86,11 @@ require (
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.4.4 // indirect
gorm.io/driver/sqlserver v1.4.1 // indirect
gorm.io/plugin/dbresolver v1.3.0 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.20.3 // indirect
)
Loading

0 comments on commit da9d33a

Please sign in to comment.