Skip to content

Commit d90e72d

Browse files
authored
Merge pull request #46 from divy9881/built_in_functions_test
feat: Built in functions and role manager tests.
2 parents 0c9b70f + 401739a commit d90e72d

15 files changed

+466
-194
lines changed

casbin/casbin.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
<ClCompile Include="persist\file_adapter\file_adapter.cpp" />
199199
<ClCompile Include="persist\file_adapter\filtered_adapter.cpp" />
200200
<ClCompile Include="rbac\default_role_manager.cpp" />
201-
<ClCompile Include="rbac\group_role_manager.cpp" />
202201
<ClCompile Include="rbac_api.cpp" />
203202
<ClCompile Include="rbac_api_with_domains.cpp" />
204203
<ClCompile Include="util\array_equals.cpp" />
@@ -281,7 +280,6 @@
281280
<ClInclude Include="persist\watcher_ex.h" />
282281
<ClInclude Include="rbac.h" />
283282
<ClInclude Include="rbac\default_role_manager.h" />
284-
<ClInclude Include="rbac\group_role_manager.h" />
285283
<ClInclude Include="rbac\pch.h" />
286284
<ClInclude Include="rbac\role_manager.h" />
287285
<ClInclude Include="util.h" />

casbin/casbin.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@
216216
<ClCompile Include="rbac\default_role_manager.cpp">
217217
<Filter>Source Files\rbac</Filter>
218218
</ClCompile>
219-
<ClCompile Include="rbac\group_role_manager.cpp">
220-
<Filter>Source Files\rbac</Filter>
221-
</ClCompile>
222219
<ClCompile Include="persist\file_adapter\batch_file_adapter.cpp">
223220
<Filter>Source Files\persist\file_adapter</Filter>
224221
</ClCompile>
@@ -287,9 +284,6 @@
287284
<ClInclude Include="rbac\default_role_manager.h">
288285
<Filter>Header Files\rbac</Filter>
289286
</ClInclude>
290-
<ClInclude Include="rbac\group_role_manager.h">
291-
<Filter>Header Files\rbac</Filter>
292-
</ClInclude>
293287
<ClInclude Include="rbac\role_manager.h">
294288
<Filter>Header Files\rbac</Filter>
295289
</ClInclude>

casbin/ip_parser/parser/IP.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ IP :: IP() {
1313
}
1414

1515
IP IP :: Mask(IPMask mask) {
16-
IPMask mask_2(mask.begin(), mask.begin()+12);
17-
if(mask.size() == IPv6len && ip.size() == IPv4len && allFF(mask_2)) {
18-
IPMask mask_3(mask.begin() + 12, mask.end());
19-
mask = mask_3;
16+
if (mask.size() == IPv6len && ip.size() == IPv4len) {
17+
IPMask mask_2(mask.begin(), mask.begin() + 12);
18+
if (allFF(mask_2)) {
19+
IPMask mask_3(mask.begin() + 12, mask.end());
20+
mask = mask_3;
21+
}
2022
}
21-
IPMask ip_2(ip.begin(), ip.begin() + 12);
22-
if(mask.size() == IPv4len && ip.size() == IPv6len && equal(ip_2, v4InV6Prefix)) {
23-
IPMask ip_3(ip.begin() + 12, ip.end());
24-
ip = ip_3;
23+
if (mask.size() == IPv4len && ip.size() == IPv6len) {
24+
IPMask ip_2(ip.begin(), ip.begin() + 12);
25+
if (equal(ip_2, v4InV6Prefix)) {
26+
IPMask ip_3(ip.begin() + 12, ip.end());
27+
ip = ip_3;
28+
}
2529
}
2630
unsigned int n = int(ip.size());
2731
if(n != mask.size()) {

casbin/rbac.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define CASBIN_CPP_RBAC
33

44
#include "./rbac/default_role_manager.h"
5-
#include "./rbac/group_role_manager.h"
65
#include "./rbac/role_manager.h"
76

87
#endif

casbin/rbac/default_role_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ void Role :: AddRole(Role* role) {
2121
}
2222

2323
void Role :: DeleteRole(Role* role) {
24-
for (vector<Role*> :: iterator it = roles.begin() ; it != roles.end() ; it++) {
25-
if (!(*it)->name.compare(role->name)) {
26-
roles.erase(it);
24+
for (int i = 0; i < roles.size();i++) {
25+
if (!roles[i]->name.compare(role->name)) {
26+
roles.erase(roles.begin()+i);
2727
}
2828
}
2929
}

casbin/rbac/default_role_manager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,28 @@ class DefaultRoleManager : public RoleManager {
6969
// AddLink adds the inheritance link between role: name1 and role: name2.
7070
// aka role: name1 inherits role: name2.
7171
// domain is a prefix to the roles.
72-
void AddLink(string name1, string name2, vector<string> domain);
72+
void AddLink(string name1, string name2, vector<string> domain = vector<string>{});
7373

7474
/**
7575
* deleteLink deletes the inheritance link between role: name1 and role: name2.
7676
* aka role: name1 does not inherit role: name2 any more.
7777
* domain is a prefix to the roles.
7878
*/
79-
void DeleteLink(string name1, string name2, vector<string> domain);
79+
void DeleteLink(string name1, string name2, vector<string> domain = vector<string>{});
8080

8181
/**
8282
* hasLink determines whether role: name1 inherits role: name2.
8383
* domain is a prefix to the roles.
8484
*/
85-
bool HasLink(string name1, string name2, vector<string> domain);
85+
bool HasLink(string name1, string name2, vector<string> domain = vector<string>{});
8686

8787
/**
8888
* getRoles gets the roles that a subject inherits.
8989
* domain is a prefix to the roles.
9090
*/
91-
vector <string> GetRoles(string name, vector<string> domain);
91+
vector <string> GetRoles(string name, vector<string> domain = vector<string>{});
9292

93-
vector<string> GetUsers(string name, vector<string> domain);
93+
vector<string> GetUsers(string name, vector<string> domain = vector<string>{});
9494

9595
/**
9696
* printRoles prints all the roles to log.

casbin/rbac/group_role_manager.cpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

casbin/rbac/group_role_manager.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

casbin/rbac/role_manager.h

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,28 @@
66

77
using namespace std;
88

9+
// RoleManager provides interface to define the operations for managing roles.
910
class RoleManager {
1011
public:
11-
/**
12-
* Clear clears all stored data and resets the role manager to the initial state.
13-
*/
14-
virtual void Clear() = 0;
15-
16-
/**
17-
* AddLink adds the inheritance link between two roles. role: name1 and role: name2.
18-
* domain is a prefix to the roles.
19-
*
20-
* @param name1 the first role (or user).
21-
* @param name2 the second role.
22-
* @param domain the domain the roles belong to.
23-
*/
24-
virtual void AddLink(string name1, string name2, vector<string> domain) = 0;
25-
26-
/**
27-
* DeleteLink deletes the inheritance link between two roles. role: name1 and role: name2.
28-
* domain is a prefix to the roles.
29-
*
30-
* @param name1 the first role (or user).
31-
* @param name2 the second role.
32-
* @param domain the domain the roles belong to.
33-
*/
34-
virtual void DeleteLink(string name1, string name2, vector<string> domain) = 0;
35-
36-
/**
37-
* hasLink determines whether a link exists between two roles. role: name1 inherits role: name2.
38-
* domain is a prefix to the roles.
39-
*
40-
* @param name1 the first role (or a user).
41-
* @param name2 the second role.
42-
* @param domain the domain the roles belong to.
43-
* @return whether name1 inherits name2 (name1 has role name2).
44-
*/
45-
virtual bool HasLink(string name1, string name2, vector<string> domain) = 0;
46-
47-
/**
48-
* GetRoles gets the roles that a user inherits.
49-
* domain is a prefix to the roles.
50-
*
51-
* @param name the user (or a role).
52-
* @param domain the domain the roles belong to.
53-
* @return the roles.
54-
*/
55-
virtual vector<string> GetRoles(string name, vector<string> domain) = 0;
56-
57-
/**
58-
* GetUsers gets the users that inherits a role.
59-
* @param name the role.
60-
* @return the users.
61-
*/
62-
virtual vector<string> GetUsers(string name, vector<string> domain) = 0;
63-
64-
/**
65-
* PrintRoles prints all the roles to log.
66-
*/
67-
virtual void PrintRoles() = 0;
12+
// Clear clears all stored data and resets the role manager to the initial state.
13+
virtual void Clear() = 0;
14+
// AddLink adds the inheritance link between two roles. role: name1 and role: name2.
15+
// domain is a prefix to the roles (can be used for other purposes).
16+
virtual void AddLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
17+
// DeleteLink deletes the inheritance link between two roles. role: name1 and role: name2.
18+
// domain is a prefix to the roles (can be used for other purposes).
19+
virtual void DeleteLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
20+
// HasLink determines whether a link exists between two roles. role: name1 inherits role: name2.
21+
// domain is a prefix to the roles (can be used for other purposes).
22+
virtual bool HasLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
23+
// GetRoles gets the roles that a user inherits.
24+
// domain is a prefix to the roles (can be used for other purposes).
25+
virtual vector<string> GetRoles(string name, vector<string> domain = vector<string>{}) = 0;
26+
// GetUsers gets the users that inherits a role.
27+
// domain is a prefix to the users (can be used for other purposes).
28+
virtual vector<string> GetUsers(string name, vector<string> domain = vector<string>{}) = 0;
29+
// PrintRoles prints all the roles to log.
30+
virtual void PrintRoles() = 0;
6831
};
6932

7033
#endif

0 commit comments

Comments
 (0)