ShiroPerms
Defines and checks permissions with claims written in Apache Shiro style
and use a Trie data structure for performance
Kind: global class
new ShiroPerms([claims])
Creates a new ShiroPerms instance with specified claims.
Claims may be added or removed later.
Param | Type | Default | Description |
---|
[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
Param | Type | Default |
---|
[claims] | String | Array.<String> | [] |
Example
perms.add('store:view');
perms.add(['store:view', 'store:edit:1234']);
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
Param | Type | Default |
---|
[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
Param | Type | Default | Description |
---|
[permissions] | String | Array.<String> | [] | Permisssions to be checked |
[any] | Boolean | false | If 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
Param | Type | Default | Description |
---|
[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
Param | Type | Default | Description |
---|
[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
Param | Type | Description |
---|
...claims | String | Array.<String> | Claims list |
ShiroPerms.fromTrie([trie]) ⇒ ShiroPerms
Creates new ShiroPerms object from a Trie object
Kind: static method of ShiroPerms
Param | Type | Default | Description |
---|
[trie] | Object | String | {} | Trie object or JSON |