Casbin

Casbin

  • 문서
  • API
  • 편집기
  • IDE Plugins
  • Single Sign-On (SSO)
  • Forum
  • 도움말
  • 블로그
  • Pricing
  • Contact Sales
  • Languages icon한국어
    • English
    • 中文
    • Русский
    • Français
    • Deutsch
    • 日本語
    • 번역 참여하기
  • GitHub

›모델

기초

  • 개요(Overview)
  • 시작하기
  • 작동 원리
  • 자습서

모델

  • 지원하는 접근 제어 모델
  • 모델(Model) 문법
  • Effector
  • 함수
  • RBAC
  • RBAC with Pattern
  • RBAC + 도메인
  • Casbin RBAC v.s. RBAC96
  • ABAC
  • Priority Model
  • Super Admin

저장소

  • 모델(Model) 저장
  • 정책(Policy) 저장
  • 정책(Policy) 부분 집합 불러오기

확장 기능

  • Enforcers
  • 어댑터
  • 감시자
  • Dispatchers
  • 역할(Role) 관리자
  • 미들웨어
  • GraphQL Middlewares
  • Cloud Native Middlewares

API

  • API Overview
  • Management API
  • RBAC API
  • RBAC with Domains API
  • RoleManager API
  • Data Permissions

고급 사용법 (Advanced usage)

  • 멀티 스레딩
  • 벤치마크
  • Performance Optimization
  • Authorization of Kubernetes
  • Authorization of Service Mesh through Envoy

관리

  • 관리자 포탈
  • Casbin 서비스
  • 로깅 및 오류 처리
  • Frontend Usage

Editor

  • 온라인 편집기
  • IDE Plugins

자세히

  • Casbin 적용 사례
  • Contributing
  • Privacy Policy
  • Terms of Service
Translate

함수

Functions in matchers

You can even specify functions in a matcher to make it more powerful. You can use the built-in functions or specify your own function. All built-in functions take such a format(except keyGet and keyGet2):

bool function_name(string arg1, string arg2)

It returns whether arg1 matches arg2.

keyGet and keyGet2 will return the string which matching the wildcard, and return "" if nothing was matched.

The supported built-in functions are:

Functionarg1arg2Example
keyMatcha URL path like /alice_data/resource1a URL path or a * pattern like /alice_data/*keymatch_model.conf/keymatch_policy.csv
keyGeta URL path like /alice_data/resource1a URL path or a * pattern like /alice_data/*keyget_model.conf/keymatch_policy.csv
keyMatch2a URL path like /alice_data/resource1a URL path or a : pattern like /alice_data/:resourcekeymatch2_model.conf/keymatch2_policy.csv
keyGet2a URL path like /alice_data/resource1a URL path or : pattern like /alice_data/:resourcekeyget2_model.conf/keymatch2_policy.csv
keyMatch3a URL path like /alice_data/resource1a URL path or a {} pattern like /alice_data/{resource}https://github.com/casbin/casbin/blob/277c1a2b85698272f764d71a94d2595a8d425915/util/builtin_operators_test.go#L171-L196
keyMatch4a URL path like /alice_data/123/book/123a URL path or a {} pattern like /alice_data/{id}/book/{id}https://github.com/casbin/casbin/blob/277c1a2b85698272f764d71a94d2595a8d425915/util/builtin_operators_test.go#L208-L222
regexMatchany stringa regular expression patternkeymatch_model.conf/keymatch_policy.csv
ipMatchan IP address like 192.168.2.123an IP address or a CIDR like 192.168.2.0/24ipmatch_model.conf/ipmatch_policy.csv
globMatcha path-like path like /alice_data/resource1a glob pattern like /alice_data/*https://github.com/casbin/casbin/blob/277c1a2b85698272f764d71a94d2595a8d425915/util/builtin_operators_test.go#L426-L466

See details for above functions at: https://github.com/casbin/casbin/blob/master/util/builtin_operators_test.go

How to add a customized function

First prepare your function. It takes several parameters and return a bool:

func KeyMatch(key1 string, key2 string) bool {
    i := strings.Index(key2, "*")
    if i == -1 {
        return key1 == key2
    }

    if len(key1) > i {
        return key1[:i] == key2[:i]
    }
    return key1 == key2[:i]
}

Then wrap it with interface{} types:

func KeyMatchFunc(args ...interface{}) (interface{}, error) {
    name1 := args[0].(string)
    name2 := args[1].(string)

    return (bool)(KeyMatch(name1, name2)), nil
}

At last, register the function to the Casbin enforcer:

e.AddFunction("my_func", KeyMatchFunc)

Now, you can use the function in your model CONF like this:

[matchers]
m = r.sub == p.sub && my_func(r.obj, p.obj) && r.act == p.act
← EffectorRBAC →
  • Functions in matchers
  • How to add a customized function
Casbin
Docs
Getting StartedManagement APIRBAC APIMiddlewares
Community
Who's using Casbin?Stack Overflow
Casbin          jCasbin
Node-Casbin   PHP-CasbinPyCasbin          Casbin.NETCasbin-CPP        Casbin-RS
Follow @casbinHQ
Copyright © 2022 Casbin Organization