Skip to content
프로젝트

소개

NodeJS용 계층적 역할 기반 접근 제어

보안 및 개인정보 보호

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
-1

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

RBAC

Hierarchical Role Based Access Control for Node.js

NPM version License: MIT

Install

npm install rbac

Usage

import { RBAC } from 'rbac';

const rbac = new RBAC({
  roles: ['superadmin', 'admin', 'user', 'guest'],
  permissions: {
    user: ['create', 'delete'],
    password: ['change', 'forgot'],
    article: ['create'],
    rbac: ['update'],
  },
  grants: {
    guest: ['create_user', 'forgot_password'],
    user: ['change_password'],
    admin: ['user', 'delete_user', 'update_rbac'],
    superadmin: ['admin'],
  },
});

await rbac.init();

Check permissions

const can = await rbac.can('admin', 'create', 'article');
if (can) {
  console.log('Admin is able to create article');
}

Or use a role instance:

const admin = await rbac.getRole('admin');
if (!admin) {
  console.log('Role does not exist');
} else {
  const can = await admin.can('create', 'article');
  if (can) {
    console.log('Admin is able to create article');
  }
}

Custom storage

RBAC uses in-memory storage by default. You can implement custom storage by extending the Storage class:

import { Storage } from 'rbac';

class MyStorage extends Storage {
  async add(item) { /* ... */ }
  async remove(item) { /* ... */ }
  async grant(role, child) { /* ... */ }
  async revoke(role, child) { /* ... */ }
  async get(name) { /* ... */ }
  async getRoles() { /* ... */ }
  async getPermissions() { /* ... */ }
  async getGrants(role) { /* ... */ }
}

const rbac = new RBAC({ storage: new MyStorage() });

Running Tests

npm test

Credits

Zlatko Fedor

License

MIT

관련 프로젝트 살펴보기

불러오는 중…