Class: ShiroPerms

ShiroPerms(claimsopt)

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

Constructor

new ShiroPerms(claimsopt)

Creates a new ShiroPerms instance with specified claims. Claims may be added or removed later.
Parameters:
Name Type Attributes Default Description
claims Array.<String> <optional>
[] Claims to create the object with.
Source:

Members

claims :Array.<String>

A list of current claims
Type:
  • Array.<String>
Source:

trie :object

Returns current permissions Trie object
Type:
  • object
Source:

Methods

(static) from(…claims) → {ShiroPerms}

Creates new ShiroPerms object from a list of claims
Parameters:
Name Type Attributes Description
claims String | Array.<String> <repeatable>
Claims list
Source:
Returns:
Type
ShiroPerms

(static) fromBin(data) → {ShiroPerms}

Creates new ShiroPerms object from a Trie object in bin format (msgpack5)
Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
ShiroPerms

(static) fromTrie(trieopt) → {ShiroPerms}

Creates new ShiroPerms object from a Trie object
Parameters:
Name Type Attributes Default Description
trie Object | String <optional>
{} Trie object or JSON
Source:
Returns:
Type
ShiroPerms

_claims(reversedopt) → {Array.<String>}

Method used to transverse the trie and produce a list of claims. Reversed option is used internally to produce a compact list of claims.
Parameters:
Name Type Attributes Default Description
reversed Boolean <optional>
false If true, claims are output in backwards
Source:
Returns:
List of claims present in the trie
Type
Array.<String>

add(claimsopt) → {ShiroPerms}

Add claims to permission Trie Accept multiple claim string with claims separated by space char ' '
Parameters:
Name Type Attributes Default Description
claims String | Array.<String> <optional>
[]
Source:
Returns:
Type
ShiroPerms
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');

check(permissionsopt, anyopt) → {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 ' '
Parameters:
Name Type Attributes Default Description
permissions String | Array.<String> <optional>
[] Permisssions to be checked
any Boolean <optional>
false If true, checks for any permission (OR). Checks all permissions otherwise (AND)
Source:
Returns:
Allowed
Type
Boolean

checkAny(permissionsopt) → {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 ' '
Parameters:
Name Type Attributes Default Description
permissions String | Array.<String> <optional>
[] Permisssions to be checked
Source:
Returns:
Allowed
Type
Boolean

dump() → {String}

Dumps current Trie to JSON.
Source:
Returns:
Trie in JSON format
Type
String

dumpBin() → {Buffer}

Dumps current Trie to bin format (msgpack5).
Source:
Returns:
Type
Buffer

load(trieopt) → {ShiroPerms}

Set internal Trie object. Useful to import permission dumps or an external Trie object. Accept Trie object in JSON format
Parameters:
Name Type Attributes Default Description
trie Object | String <optional>
{} Trie object or JSON string to load
Source:
Returns:
this
Type
ShiroPerms

loadBin(data) → {ShiroPerms}

Loads Trie from a bin format data (msgpack5)
Parameters:
Name Type Description
data Buffer Data to load
Source:
Returns:
Type
ShiroPerms

remove(claimsopt) → {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 ' '
Parameters:
Name Type Attributes Default Description
claims String | Array.<String> <optional>
[]
Source:
Returns:
Type
ShiroPerms

reset() → {ShiroPerms}

Removes all permissions from the Trie
Source:
Returns:
this
Type
ShiroPerms

toString() → {String}

Print current claims in single string format
Source:
Returns:
Type
String