Class FilteredAdapter
java.lang.Object
org.casbin.jcasbin.persist.file_adapter.FilteredAdapter
- All Implemented Interfaces:
Adapter, FilteredAdapter
FilteredAdapter is the filtered file adapter for Casbin.
It can load policy from a file or save policy to a file and
supports loading of filtered policies.
- Since:
- 2020/6/8
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPolicy adds a policy rule to the storage.private booleanfilterLine(String line, FilteredAdapter.Filter filter) match the line.private booleanfilterWords(String[] line, String[] filter) match the words in the specific line.booleanIsFiltered returns true if the loaded policy has been filtered.voidloadFilteredPolicy(Model model, Object filter) loadFilteredPolicy loads only policy rules that match the filter.private voidloadFilteredPolicyFile(Model model, FilteredAdapter.Filter filter, Helper.loadPolicyLineHandler<String, Model> handler) loadFilteredPolicyFile loads only policy rules that match the filter from file.voidloadPolicy(Model model) loadPolicy loads all policy rules from the storage.voidremoveFilteredPolicy(String sec, String ptype, int fieldIndex, String... fieldValues) removeFilteredPolicy removes policy rules that match the filter from the storage.voidremovePolicy(String sec, String ptype, List<String> rule) removePolicy removes a policy rule from the storage.voidsavePolicy(Model model) savePolicy saves all policy rules to the storage.
-
Field Details
-
adapter
-
isFiltered
private boolean isFiltered -
filepath
-
-
Constructor Details
-
FilteredAdapter
-
-
Method Details
-
loadFilteredPolicy
loadFilteredPolicy loads only policy rules that match the filter.- Specified by:
loadFilteredPolicyin interfaceFilteredAdapter- Parameters:
model- the model.filter- the filter used to specify which type of policy should be loaded.- Throws:
CasbinAdapterException- if the file path or the type of the filter is incorrect.
-
loadFilteredPolicyFile
private void loadFilteredPolicyFile(Model model, FilteredAdapter.Filter filter, Helper.loadPolicyLineHandler<String, Model> handler) throws CasbinAdapterExceptionloadFilteredPolicyFile loads only policy rules that match the filter from file.- Throws:
CasbinAdapterException
-
filterLine
match the line. -
filterWords
-
isFiltered
public boolean isFiltered()Description copied from interface:FilteredAdapterIsFiltered returns true if the loaded policy has been filtered.- Specified by:
isFilteredin interfaceFilteredAdapter- Returns:
- true if have any filter roles.
-
loadPolicy
loadPolicy loads all policy rules from the storage.- Specified by:
loadPolicyin interfaceAdapter- Parameters:
model- the model.
-
savePolicy
savePolicy saves all policy rules to the storage.- Specified by:
savePolicyin interfaceAdapter- Parameters:
model- the model.
-
addPolicy
-
removePolicy
removePolicy removes a policy rule from the storage.- Specified by:
removePolicyin interfaceAdapter- Parameters:
sec- the section, "p" or "g".ptype- the policy type, "p", "p2", .. or "g", "g2", ..rule- the rule, like (sub, obj, act).
-
removeFilteredPolicy
removeFilteredPolicy removes policy rules that match the filter from the storage.- Specified by:
removeFilteredPolicyin interfaceAdapter- Parameters:
sec- the section, "p" or "g".ptype- the policy type, "p", "p2", .. or "g", "g2", ..fieldIndex- the policy rule's start index to be matched.fieldValues- the field values to be matched, value "" means not to match this field.
-