Skip to content

Commit

Permalink
Merge pull request #46 from divy9881/built_in_functions_test
Browse files Browse the repository at this point in the history
feat: Built in functions and role manager tests.
  • Loading branch information
hsluoyz authored Jun 25, 2020
2 parents 0c9b70f + 401739a commit d90e72d
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 194 deletions.
2 changes: 0 additions & 2 deletions casbin/casbin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@
<ClCompile Include="persist\file_adapter\file_adapter.cpp" />
<ClCompile Include="persist\file_adapter\filtered_adapter.cpp" />
<ClCompile Include="rbac\default_role_manager.cpp" />
<ClCompile Include="rbac\group_role_manager.cpp" />
<ClCompile Include="rbac_api.cpp" />
<ClCompile Include="rbac_api_with_domains.cpp" />
<ClCompile Include="util\array_equals.cpp" />
Expand Down Expand Up @@ -281,7 +280,6 @@
<ClInclude Include="persist\watcher_ex.h" />
<ClInclude Include="rbac.h" />
<ClInclude Include="rbac\default_role_manager.h" />
<ClInclude Include="rbac\group_role_manager.h" />
<ClInclude Include="rbac\pch.h" />
<ClInclude Include="rbac\role_manager.h" />
<ClInclude Include="util.h" />
Expand Down
6 changes: 0 additions & 6 deletions casbin/casbin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@
<ClCompile Include="rbac\default_role_manager.cpp">
<Filter>Source Files\rbac</Filter>
</ClCompile>
<ClCompile Include="rbac\group_role_manager.cpp">
<Filter>Source Files\rbac</Filter>
</ClCompile>
<ClCompile Include="persist\file_adapter\batch_file_adapter.cpp">
<Filter>Source Files\persist\file_adapter</Filter>
</ClCompile>
Expand Down Expand Up @@ -287,9 +284,6 @@
<ClInclude Include="rbac\default_role_manager.h">
<Filter>Header Files\rbac</Filter>
</ClInclude>
<ClInclude Include="rbac\group_role_manager.h">
<Filter>Header Files\rbac</Filter>
</ClInclude>
<ClInclude Include="rbac\role_manager.h">
<Filter>Header Files\rbac</Filter>
</ClInclude>
Expand Down
20 changes: 12 additions & 8 deletions casbin/ip_parser/parser/IP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ IP :: IP() {
}

IP IP :: Mask(IPMask mask) {
IPMask mask_2(mask.begin(), mask.begin()+12);
if(mask.size() == IPv6len && ip.size() == IPv4len && allFF(mask_2)) {
IPMask mask_3(mask.begin() + 12, mask.end());
mask = mask_3;
if (mask.size() == IPv6len && ip.size() == IPv4len) {
IPMask mask_2(mask.begin(), mask.begin() + 12);
if (allFF(mask_2)) {
IPMask mask_3(mask.begin() + 12, mask.end());
mask = mask_3;
}
}
IPMask ip_2(ip.begin(), ip.begin() + 12);
if(mask.size() == IPv4len && ip.size() == IPv6len && equal(ip_2, v4InV6Prefix)) {
IPMask ip_3(ip.begin() + 12, ip.end());
ip = ip_3;
if (mask.size() == IPv4len && ip.size() == IPv6len) {
IPMask ip_2(ip.begin(), ip.begin() + 12);
if (equal(ip_2, v4InV6Prefix)) {
IPMask ip_3(ip.begin() + 12, ip.end());
ip = ip_3;
}
}
unsigned int n = int(ip.size());
if(n != mask.size()) {
Expand Down
1 change: 0 additions & 1 deletion casbin/rbac.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define CASBIN_CPP_RBAC

#include "./rbac/default_role_manager.h"
#include "./rbac/group_role_manager.h"
#include "./rbac/role_manager.h"

#endif
6 changes: 3 additions & 3 deletions casbin/rbac/default_role_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ void Role :: AddRole(Role* role) {
}

void Role :: DeleteRole(Role* role) {
for (vector<Role*> :: iterator it = roles.begin() ; it != roles.end() ; it++) {
if (!(*it)->name.compare(role->name)) {
roles.erase(it);
for (int i = 0; i < roles.size();i++) {
if (!roles[i]->name.compare(role->name)) {
roles.erase(roles.begin()+i);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions casbin/rbac/default_role_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,28 @@ class DefaultRoleManager : public RoleManager {
// AddLink adds the inheritance link between role: name1 and role: name2.
// aka role: name1 inherits role: name2.
// domain is a prefix to the roles.
void AddLink(string name1, string name2, vector<string> domain);
void AddLink(string name1, string name2, vector<string> domain = vector<string>{});

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

/**
* hasLink determines whether role: name1 inherits role: name2.
* domain is a prefix to the roles.
*/
bool HasLink(string name1, string name2, vector<string> domain);
bool HasLink(string name1, string name2, vector<string> domain = vector<string>{});

/**
* getRoles gets the roles that a subject inherits.
* domain is a prefix to the roles.
*/
vector <string> GetRoles(string name, vector<string> domain);
vector <string> GetRoles(string name, vector<string> domain = vector<string>{});

vector<string> GetUsers(string name, vector<string> domain);
vector<string> GetUsers(string name, vector<string> domain = vector<string>{});

/**
* printRoles prints all the roles to log.
Expand Down
42 changes: 0 additions & 42 deletions casbin/rbac/group_role_manager.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions casbin/rbac/group_role_manager.h

This file was deleted.

77 changes: 20 additions & 57 deletions casbin/rbac/role_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,28 @@

using namespace std;

// RoleManager provides interface to define the operations for managing roles.
class RoleManager {
public:
/**
* Clear clears all stored data and resets the role manager to the initial state.
*/
virtual void Clear() = 0;

/**
* AddLink adds the inheritance link between two roles. role: name1 and role: name2.
* domain is a prefix to the roles.
*
* @param name1 the first role (or user).
* @param name2 the second role.
* @param domain the domain the roles belong to.
*/
virtual void AddLink(string name1, string name2, vector<string> domain) = 0;

/**
* DeleteLink deletes the inheritance link between two roles. role: name1 and role: name2.
* domain is a prefix to the roles.
*
* @param name1 the first role (or user).
* @param name2 the second role.
* @param domain the domain the roles belong to.
*/
virtual void DeleteLink(string name1, string name2, vector<string> domain) = 0;

/**
* hasLink determines whether a link exists between two roles. role: name1 inherits role: name2.
* domain is a prefix to the roles.
*
* @param name1 the first role (or a user).
* @param name2 the second role.
* @param domain the domain the roles belong to.
* @return whether name1 inherits name2 (name1 has role name2).
*/
virtual bool HasLink(string name1, string name2, vector<string> domain) = 0;

/**
* GetRoles gets the roles that a user inherits.
* domain is a prefix to the roles.
*
* @param name the user (or a role).
* @param domain the domain the roles belong to.
* @return the roles.
*/
virtual vector<string> GetRoles(string name, vector<string> domain) = 0;

/**
* GetUsers gets the users that inherits a role.
* @param name the role.
* @return the users.
*/
virtual vector<string> GetUsers(string name, vector<string> domain) = 0;

/**
* PrintRoles prints all the roles to log.
*/
virtual void PrintRoles() = 0;
// Clear clears all stored data and resets the role manager to the initial state.
virtual void Clear() = 0;
// AddLink adds the inheritance link between two roles. role: name1 and role: name2.
// domain is a prefix to the roles (can be used for other purposes).
virtual void AddLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
// DeleteLink deletes the inheritance link between two roles. role: name1 and role: name2.
// domain is a prefix to the roles (can be used for other purposes).
virtual void DeleteLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
// HasLink determines whether a link exists between two roles. role: name1 inherits role: name2.
// domain is a prefix to the roles (can be used for other purposes).
virtual bool HasLink(string name1, string name2, vector<string> domain = vector<string>{}) = 0;
// GetRoles gets the roles that a user inherits.
// domain is a prefix to the roles (can be used for other purposes).
virtual vector<string> GetRoles(string name, vector<string> domain = vector<string>{}) = 0;
// GetUsers gets the users that inherits a role.
// domain is a prefix to the users (can be used for other purposes).
virtual vector<string> GetUsers(string name, vector<string> domain = vector<string>{}) = 0;
// PrintRoles prints all the roles to log.
virtual void PrintRoles() = 0;
};

#endif
Loading

0 comments on commit d90e72d

Please sign in to comment.