mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Implemented request matching for the rbac system.
This commit is contained in:
parent
c934d36dcf
commit
9ed17fe193
@ -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];
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user