Implemented request matching for the rbac system.

This commit is contained in:
Relintai 2022-01-06 11:49:35 +01:00
parent c934d36dcf
commit 9ed17fe193
3 changed files with 35 additions and 1 deletions

View File

@ -335,6 +335,18 @@ int String::compare(const String &other) const {
}
}
int String::first_difference_index(const String &other) const {
int c = size() < other.size() ? size() : other.size();
for (int i = 0; i < c; ++i) {
if (_data[i] != other._data[i]) {
return i;
}
}
return c;
}
void String::to_lower() {
for (int i = 0; i < _size; ++i) {
char c = _data[i];

View File

@ -42,6 +42,8 @@ public:
int compare(const String &other) const;
int first_difference_index(const String &other) const;
void to_lower();
String as_lower() const;

View File

@ -3,7 +3,27 @@
#include "core/http/request.h"
Ref<RBACPermission> RBACRank::match_request(Request *request) {
return Ref<RBACPermission>();
const String &full_path = request->get_path_full();
Ref<RBACPermission> perm;
int current_max = 0;
for (int i = 0; i < permissions.size(); ++i) {
Ref<RBACPermission> p;
if (!p.is_valid()) {
continue;
}
int c = full_path.first_difference_index(p->url);
if (c > current_max) {
perm = p;
current_max = c;
}
}
return perm;
}
bool RBACRank::get_permissions(Request *request) {