Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shiro-perms

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shiro-perms

Apache Shiro permission style using Trie data structure

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132
decreased by-40.54%
Maintainers
1
Weekly downloads
 
Created
Source

ShiroPerms

Defines and checks permissions with claims written in Apache Shiro style and use a Trie data structure for performance

Kind: global class

  • ShiroPerms
    • new ShiroPerms([claims])
    • instance
      • .claims : Array.<String>
      • .trie : object
      • .reset()ShiroPerms
      • .add([claims])ShiroPerms
      • .remove([claims])ShiroPerms
      • .check([permissions], [any])Boolean
      • .checkAny([permissions])Boolean
      • .toString()String
      • .load([trie])ShiroPerms
      • .dump()String
    • static

new ShiroPerms([claims])

Creates a new ShiroPerms instance with specified claims. Claims may be added or removed later.

ParamTypeDefaultDescription
[claims]Array.<String>[]Claims to create the object with.

shiroPerms.claims : Array.<String>

A list of current claims

Kind: instance property of ShiroPerms

shiroPerms.trie : object

Returns current permissions Trie object

Kind: instance property of ShiroPerms

shiroPerms.reset() ⇒ ShiroPerms

Removes all permissions from the Trie

Kind: instance method of ShiroPerms
Returns: ShiroPerms - this

shiroPerms.add([claims]) ⇒ ShiroPerms

Add claims to permission Trie Accept multiple claim string with claims separated by space char ' '

Kind: instance method of ShiroPerms

ParamTypeDefault
[claims]String | Array.<String>[]

Example

// Single claim
perms.add('store:view');

// Claim array
perms.add(['store:view', 'store:edit:1234']);

// Mutiple claim string
perms.add('store:view store:edit:1234');

shiroPerms.remove([claims]) ⇒ ShiroPerms

Remove claims from the Trie. Claims in Shiro compact format are not allowed, e.g. 'store:view,edit'. Accept multiple claim string with claims separated by space char ' '

Kind: instance method of ShiroPerms

ParamTypeDefault
[claims]String | Array.<String>[]

shiroPerms.check([permissions], [any]) ⇒ Boolean

Verify permissions against current Trie. Multiple permissions input may be compared using AND/OR logic operator controlled by 'any' parameter. Permission in Shiro compact format are not allowed, e.g. 'store:view,edit'. Accept multiple claim string with claims separated by space char ' '

Kind: instance method of ShiroPerms
Returns: Boolean - Allowed

ParamTypeDefaultDescription
[permissions]String | Array.<String>[]Permisssions to be checked
[any]BooleanfalseIf true, checks for any permission (OR). Checks all permissions otherwise (AND)

shiroPerms.checkAny([permissions]) ⇒ Boolean

Verify ANY permissions against current Trie. Alias of 'check()' method with flag 'any' set to false. Permission in Shiro compact format are not allowed, e.g. 'store:view,edit'. Accept multiple claim string with claims separated by space char ' '

Kind: instance method of ShiroPerms
Returns: Boolean - Allowed

ParamTypeDefaultDescription
[permissions]String | Array.<String>[]Permisssions to be checked

shiroPerms.toString() ⇒ String

Print current claims in single string format

Kind: instance method of ShiroPerms

shiroPerms.load([trie]) ⇒ ShiroPerms

Set internal Trie object. Useful to import permission dumps or an external Trie object. Accept Trie object in JSON format

Kind: instance method of ShiroPerms
Returns: ShiroPerms - this

ParamTypeDefaultDescription
[trie]Object | String{}Trie object or JSON string to load

shiroPerms.dump() ⇒ String

Dumps current Trie to JSON.

Kind: instance method of ShiroPerms
Returns: String - Trie in JSON format

ShiroPerms.from(...claims) ⇒ ShiroPerms

Creates new ShiroPerms object from a list of claims

Kind: static method of ShiroPerms

ParamTypeDescription
...claimsString | Array.<String>Claims list

ShiroPerms.fromTrie([trie]) ⇒ ShiroPerms

Creates new ShiroPerms object from a Trie object

Kind: static method of ShiroPerms

ParamTypeDefaultDescription
[trie]Object | String{}Trie object or JSON

Keywords

FAQs

Package last updated on 29 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc