-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoleBasecAccessControlAnalyzer.java
98 lines (80 loc) · 2.61 KB
/
RoleBasecAccessControlAnalyzer.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package de.buw.fm4se.rbac;
import java.util.Set;
import de.buw.fm4se.rbac.exec.LimbooleExecutor;
/**
* This code needs to be implemented by translating FMs to input for Limboole
* and interpreting the output
*
*/
public class RoleBasecAccessControlAnalyzer {
RbacTableReader rbac;
public RoleBasecAccessControlAnalyzer(String csvFile) {
rbac = new RbacTableReader(csvFile);
}
/**
* TODO Check if each of the given roles has all of the given permissions
*
* Solve it by using a transaltion to Limboole rather than a direct search in
* the RBAC table!
*
* @param roles
* @param permissions
* @return
*/
public boolean everyUserWithRoleHasPermissions(Set<String> roles, Set<String> permissions) {
String formula = RoleBasedAccessControlTableTranslator.translateToFormula(rbac);
// TODO: implement this method by translating the problem to Limboole
// check validity of formula by checking unsatisfiability
return !checkSat(formula);
}
/**
* TODO Check if only users with the given role have the given permission
*
* Solve it by using a transaltion to Limboole rather than a direct search in
* the RBAC table!
*
* @param role
* @param permission
* @return
*/
public boolean onlyUserWithRoleHasPermission(String role, String permission) {
String formula = RoleBasedAccessControlTableTranslator.translateToFormula(rbac);
// TODO: implement this method by translating the problem to Limboole
// check validity of formula by checking unsatisfiability
return !checkSat(formula);
}
/**
* TODO Check that no user can have the given two permissions at the same time
*
* Solve it by using a transaltion to Limboole rather than a direct search in
* the RBAC table!
*
* @param permission1
* @param permission2
* @return
*/
public boolean noUserHasBothPermissions(String permission1, String permission2) {
String formula = RoleBasedAccessControlTableTranslator.translateToFormula(rbac);
// TODO: implement this method by translating the problem to Limboole
// check validity of formula by checking unsatisfiability
return !checkSat(formula);
}
/**
* Check satisfiability of the formula using Limboole
*
* @param formula
* @return
*/
public boolean checkSat(String formula) {
String result;
try {
result = LimbooleExecutor.runLimboole(formula, true);
} catch (Exception e) {
throw new RuntimeException("Evaluation for formula via Limboole unsusscessful", e);
}
if (result.contains("UNSATISFIABLE")) {
return false;
}
return true;
}
}