Giter Site home page Giter Site logo

node-permission-architect's Introduction

Build Status NPM version Code Climate

NPM

Why another ACL manager?

Something that has bothered me about some ACL managers is how restricted they are. I often come across cases where dynamically determining the role based on more than ACL records is required. I also wanted to reflect different permissions based on the resources life cycle. I also wanted something that was not coupled to any sort of datasource. Sometimes you can do things statically, other times you can query a datasource to get what you need to know.

I wanted to provide a layer that clearly defined what handled determining the role and permissions of each part of the system.

Features

  • You provide the data layer
  • Built for async work-flows
  • Supports multiple instances, so you can provide different ACL mappings within the same process.
  • You can pass your own context/state to use within each Provider
  • Easy to migrate too from your existing ACL system (probably, let us know!)
  • Bunyan compatible logger

Some implementation details

  • If a method takes multiple models, they will always be in this order: Profile, Resource, Role, Permission.
  • null is considered intentionally not defined.

Model

SessionRegistry

An globally registred instance with an optional name.

var sessionRegistry.get();

// Or

var sessionRegstry.get('myInstance');

Profile

This represents an accessor of resources. In most cases, a User. It could also indicate a Group, Organization or any other sort accessor you which to check.

var profile = sessionRegistry.buildProfile('User', 1000, userModel);

Resource

This represents something to be accessed. Common cases are models: User, Profile, Post, etc. But could also reflect actual resources: A queue, ports, etc.

var resource = sessionRegistry.buildResource('Post', 2000, postModel);

RoleProvider

Every combination of Profile to Resource has to register a RoleProvider. This provider is tasks with determining what role best fits the provided profile and resource. You can statically code these, or have it look up the roles from your datasource.

var roleProvider = sessionRegistry.buildRoleProvider('User', 'Post', {
  getRoles: function(roleProvider, profile, resource, callback) {
    var role = this.sessionProvider.buildRole('owner', profile, resource);
    callback(null, [roll]);
  }
});

RoleProviderRegistry

After creating a RoleProvider you need to register it so future lookups can be completed.

sessionRegistry.registerRoleProvider(roleProvider);

PermissionProvider

PermissionProviders provided for each permission on a named Resource.

var create = sessionRegistry.buildPermissionProvider('create', {
  getPermission: function(permissionProvider, resource, role, cb) {
    return permissionProvider.getSessionRegistry().buildPermission(true, {}, permissionProvider);
  }
}
);

PermissionRegistry

A collection of PermissionProviders for a named Resource must be registered for future lookups.

sessionRegistry.registerPermissionProvider('Post', [create]);

Permission

Represents a permission derived from a PermissionProvided with a provided Resource.

sessionRegistry.buildPermisison(
  true, //granted or not
  {limit: 10}, //additional contextual information you can provided
  permissionProvider // reference to the permissionProvider that made this Permission
);

Usage

rolesFor

Find all the applicable Roles for the provided Profile and Resource.

sessionRegistry.rolesFor(profile, resource, function(err, roles) {
  // roles is an array of Role
});

## bestRoleFor

Find a single Role that is the best by weight.

sessionRegistry.bestRoleFor(profile, resource, function(err, role) { // role is a single Role });

getPermission

Fetch a Permission for a Resource being accessed with the provided Role.

sessionRegistry.getPermission('create', resource, role, function(err, permission) {
  if (permission.granted === false) {
    throw new Error('Permission denied');
  } else {
    // granted!
  }
}
});

node-permission-architect's People

Contributors

interlock avatar

Stargazers

Vytautas Barkauskas avatar  avatar Jehandad Kamal avatar Yosh avatar

Watchers

 avatar James Cloos avatar

Forkers

interlock

node-permission-architect's Issues

Session Interface

Provide interface that is implemented by the entry registry but also allows sub sessions based on those registered sessions.

Require Role's to be Registered

Building roles in the SecurityRegistry factory method skips the weight assignment and possibly lets roles that are not expected to be specified.

  • add registerRole(name, weight=0)
  • update buildRole(name) to require the role to be previously registered and assign the weight
  • throw Exception on buildRole if Role not registered

Add bunyan logger

Allow security-context to have a bunyan style logger instance assigned. Providers/Resolvers will log if present.

Support Promises

Waiting for native promises, but when they come we will add them.

Great gh_pages site

Setup gh_pages with a plain template for site, update package.json for new homepage

Reverse calling implementations in scope of their providers

Turns out this was a terrible idea, preventing parameterized classes from being used to implement similar functionality in practical applications.

To implementations method prototypes will be adjusted to accept the provider as a reference to compensate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.