メインコンテンツにスキップ

Domains API による RBAC

ドメインとRBAC用のよりフレンドリーなAPI。 この API は管理 API のサブセットです。 RBAC ユーザーはこの API を使用してコードを簡素化することができます。

参照

global variable e は Enforcer インスタンスです。

e, err := NewEnforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv")

GetUsersForRoleInDomain()

GetUsersForRoleInDomain は、ドメイン内のロールを持つユーザーを取得します。

例:

res := e.GetUsersForRoleInDomain("admin", "domain1")

GetRolesForUserInDomain()

GetRolesForUserInDomain は、ユーザーがドメイン内に持つロールを取得します。

例:

res := e.GetRolesForUserInDomain("admin", "domain1")

GetPermissionsForUserInDomain()

GetPermissionsForUserInDomain は、ドメイン内のユーザーまたはロールに対する権限を取得します。

例:

res := e.GetPermissionsForUserInDomain("alice", "domain1")

AddRoleForUserInDomain()

AddRoleForUserInDomain は、ドメイン内のユーザーにロールを追加します。 ユーザーがすでに役割を持っている場合は、false を返します。

例:

ok, err := e.AddRoleForUserInDomain("alice", "admin", "domain1")

DeleteRoleForUserInDomain()

DeleteRoleForUserInDomain は、ドメイン内のユーザーのロールを削除します。 役割を持たない場合は、false を返します。

例:

ok, err := e.DeleteRoleForUserInDomain("alice", "admin", "domain1")

DeleteRolesForUserInDomain()

DeleteRolesForUserInDomain は、ドメイン内のユーザーのすべてのロールを削除します。 ユーザーにロールがない場合は false を返します(影響を受けない場合)。

例:

ok, err := e.DeleteRolesForUserInDomain("alice", "domain1")

GetAllUsersByDomain()

GetAllUsersByDomain は、ドメインに関連付けられたすべてのユーザーを取得します。 モデルにドメインが定義されていない場合は、空の文字列配列を返します。

例:

res := e.GetAllUsersByDomain("domain1")

DeleteAllUsersByDomain()

DeleteAllUsersByDomain は、ドメインに関連付けられているすべてのユーザーを削除します。 モデルにドメインが定義されていない場合は false を返します。

例:

ok, err := e.DeleteAllUsersByDomain("domain1")

DeleteDomains()

DeleteDomains will delete all associated users and roles. パラメータが指定されていない場合は、すべてのドメインを削除します。

例:

ok, err := e.DeleteDomains("domain1", "domain2")

GetAllDomains()

GetAllDomainsはすべてのドメインを取得します。

例:

res, _ := e.GetAllDomains()
note

name::domainのようなドメインを扱っている場合、予期しない動作が発生する可能性があります。 In Casbin, :: is a reversed keyword, just like for, if in a programming language, we should never put :: in a domain.

GetImplicitUsersForResourceByDomain()

GetImplicitUsersForResourceByDomain return implicit user based on resource and domain.

For example:

p, admin, domain1, data1, read
p, admin, domain1, data1, write
p, admin, domain2, data2, read
p, admin, domain2, data2, write
g, alice, admin, domain1
g, bob, admin, domain2

GetImplicitUsersForResourceByDomain("data1", "domain1") will return [["alice", "domain1", "data1", "read"],["alice", "domain1", "data1", "write"]], nil

ImplicitUsers, err := e.GetImplicitUsersForResourceByDomain("data1", "domain1")
note

Only users will be returned, roles (2nd arg in "g") will be excluded.