casbin/model/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::{rbac::RoleManager, Result};

#[cfg(feature = "incremental")]
use crate::emitter::EventData;

use parking_lot::RwLock;

use std::{collections::HashMap, sync::Arc};

mod assertion;
mod default_model;
pub mod function_map;

pub use assertion::{Assertion, AssertionMap};
pub use default_model::DefaultModel;
pub use function_map::*;

pub trait Model: Send + Sync {
    fn add_def(&mut self, sec: &str, key: &str, value: &str) -> bool;
    fn get_model(&self) -> &HashMap<String, AssertionMap>;
    fn get_mut_model(&mut self) -> &mut HashMap<String, AssertionMap>;
    fn build_role_links(
        &mut self,
        rm: Arc<RwLock<dyn RoleManager>>,
    ) -> Result<()>;
    #[cfg(feature = "incremental")]
    fn build_incremental_role_links(
        &mut self,
        rm: Arc<RwLock<dyn RoleManager>>,
        d: EventData,
    ) -> Result<()>;
    fn add_policy(&mut self, sec: &str, ptype: &str, rule: Vec<String>)
        -> bool;
    fn add_policies(
        &mut self,
        sec: &str,
        ptype: &str,
        rules: Vec<Vec<String>>,
    ) -> bool;
    fn get_policy(&self, sec: &str, ptype: &str) -> Vec<Vec<String>>;
    fn get_filtered_policy(
        &self,
        sec: &str,
        ptype: &str,
        field_index: usize,
        field_values: Vec<String>,
    ) -> Vec<Vec<String>>;
    fn has_policy(&self, sec: &str, ptype: &str, rule: Vec<String>) -> bool;
    fn get_values_for_field_in_policy(
        &self,
        sec: &str,
        ptype: &str,
        field_index: usize,
    ) -> Vec<String>;
    fn remove_policy(
        &mut self,
        sec: &str,
        ptype: &str,
        rule: Vec<String>,
    ) -> bool;
    fn remove_policies(
        &mut self,
        sec: &str,
        ptype: &str,
        rules: Vec<Vec<String>>,
    ) -> bool;
    fn clear_policy(&mut self);
    fn remove_filtered_policy(
        &mut self,
        sec: &str,
        ptype: &str,
        field_index: usize,
        field_values: Vec<String>,
    ) -> (bool, Vec<Vec<String>>);
    fn to_text(&self) -> String;
}