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. |
Members
claims :Array.<String>
A list of current claims
Type:
- Array.<String>
trie :object
Returns current permissions Trie object
Type:
- object
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 |
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 |
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 |
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 |
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> |
[] |
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) |
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 |
Returns:
Allowed
- Type
- Boolean
dump() → {String}
Dumps current Trie to JSON.
Returns:
Trie in JSON format
- Type
- String
dumpBin() → {Buffer}
Dumps current Trie to bin format (msgpack5).
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 |
Returns:
this
- Type
- ShiroPerms
loadBin(data) → {ShiroPerms}
Loads Trie from a bin format data (msgpack5)
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer | Data to load |
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> |
[] |
Returns:
- Type
- ShiroPerms
reset() → {ShiroPerms}
Removes all permissions from the Trie
Returns:
this
- Type
- ShiroPerms
toString() → {String}
Print current claims in single string format
Returns:
- Type
- String