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
/// Manages role restrictions for fields
pub(crate) struct Restrictor {
/// Restriction tree
/// Children inherit role restrictions form parent.
/// Eg role 'admin' on path 'user' will also be on field 'user_address'.
qualified_fields: HashMap<String, Vec<String>>;
/// Fully nested path tree
/// If the tree does not contain an immediate parent path
/// the path is added to pending paths.
/// Paths also inherit role restrictions form parent paths.
paths: HashMap<String, Vec<String>>;
/// Paths that do not contain an immediate parent path in tree
/// Their required roles may not be complete as an immediate parent path
/// that is inserted after them may impose additional role restrictions.
/// After each path insertion, the orpahned paths are checked to be included
/// into the path tree.
/// In a good mapping sequence no orphaned paths should occur.
orphaned_paths: HashMap<String, Vec<String>>;
/// Validation cache to speed up validation.
/// Contains last validation result
last_path_validation: Option<(&str, bool)>;
}
impl Restrictor {
pub fn insert_field(qualified_field: &str, required_roles: Hashset<String>) {
}
/// Insert restricted path.
/// Restrictions will be inherited from parent path(s)
pub fn insert_path(path: &str, required_roles: Hashset<String>) {
}
/// Checks if a qualified field and its path contain the asserted roles.
/// If no roles are registered for a qualified field, this returns true
pub fn verify_field(qualified_field: &str, asserted_roles: Hashset<String>) -> bool {
true
}
}