import { Injectable , Inject } from '@nestjs/common' ; import { AUTHZ_ENFORCER } from '../authz.constants' ; import * as casbin from 'casbin' ; /**
 * A wrapper of casbin RBAC API.
 * All methods are transformed to async in terms of possible IO operations
 * in the future.
 */ @ Injectable ( ) export class AuthZRBACService { constructor ( @ Inject ( AUTHZ_ENFORCER ) private readonly enforcer ) { } param { string } name param { string } domain returns { Promise < string [ ] > } memberof getRolesForUser ( name , domain ? ) { return this . enforcer . getRolesForUser ( name , domain ) ; } param { string } name param { string } domain returns { Promise < string [ ] > } memberof getUsersForRole ( name , domain ? ) { return this . enforcer . getUsersForRole ( name , domain ) ; } param { string } name param { string } role param { string } domain returns { Promise < boolean > } memberof hasRoleForUser ( name , role , domain ? ) { return this . enforcer . hasRoleForUser ( name , role , domain ) ; } param { string } user param { string } role param { string } domain returns { Promise < boolean > } memberof addRoleForUser ( user , role , domain ? ) { return this . enforcer . addRoleForUser ( user , role , domain ) ; } param { string } user param { string } role param { string } domain returns { Promise < boolean > } memberof deleteRoleForUser ( user , role , domain ? ) { return this . enforcer . deleteRoleForUser ( user , role , domain ) ; } param { string } user returns { Promise < boolean > } memberof deleteRolesForUser ( user , domain ? ) { return this . enforcer . deleteRolesForUser ( user , domain ) ; } param { string } user returns { Promise < boolean > } memberof async deleteUser ( user ) { return this . enforcer . deleteUser ( user ) ; } param { string } role returns { Promise < boolean > } memberof deleteRole ( role ) { return this . enforcer . deleteRole ( role ) ; } param { ... string [ ] } permission returns { Promise < boolean > } memberof deletePermission ( ... permission ) { return this . enforcer . deletePermission ( ... permission ) ; } param { string } userOrRole param { ... string [ ] } permission returns { Promise < boolean > } memberof addPermissionForUser ( userOrRole , ... permission ) { return this . enforcer . addPermissionForUser ( userOrRole , ... permission ) ; } param { string } userOrRole param { ... string [ ] } permission returns { Promise < boolean > } memberof deletePermissionForUser ( userOrRole , ... permission ) { return this . enforcer . deletePermissionForUser ( userOrRole , ... permission ) ; } param { string } userOrRole returns { Promise < boolean > } memberof deletePermissionsForUser ( userOrRole ) { return this . enforcer . deletePermissionsForUser ( userOrRole ) ; } param { string } userOrRole returns { Promise < string [ ] [ ] > } memberof getPermissionsForUser ( userOrRole ) { return this . enforcer . getPermissionsForUser ( userOrRole ) ; } param { string } user param { ... string [ ] } permission returns { Promise < boolean > } memberof hasPermissionForUser ( user , ... permission ) { return this . enforcer . hasPermissionForUser ( user , ... permission ) ; } param { string } name param { ... string [ ] } domain returns { Promise < string [ ] > } memberof getImplicitRolesForUser ( name , ... domain ) { return this . enforcer . getImplicitRolesForUser ( name , ... domain ) ; } param { string } user returns { Promise < string [ ] [ ] > } memberof getImplicitPermissionsForUser ( user , ... domain ) { return this . enforcer . getImplicitPermissionsForUser ( user , ... domain ) ; } /**
     * getImplicitUsersForPermission gets implicit users for a permission.
     * For example:
     * p, admin, data1, read
     * p, bob, data1, read
     * g, alice, admin
     *
     * getImplicitUsersForPermission("data1", "read") will get: ["alice", "bob"].
     * Note: only users will be returned, roles (2nd arg in "g") will be excluded.
     */ getImplicitUsersForPermission ( ... permission ) { return this . enforcer . getImplicitUsersForPermission ( ... permission ) ; } }