MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / verifyToken

Method verifyToken

plugins/plugin_utils/plugin_HTTP.cpp:337–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337bool BZFSHTTPAuth::verifyToken(const HTTPRequest& request, HTTPReply& reply) {
338 // build up the groups list
339 std::string token, user;
340 request.getParam("token", token);
341 request.getParam("user", user);
342
343 std::vector<std::string> groups;
344
345 std::map<int, std::vector<std::string> >::iterator itr = authLevels.begin();
346
347 while (itr != authLevels.end()) {
348 for (size_t i = 0; i < itr->second.size(); i++) {
349 std::string& perm = itr->second[i];
350
351 std::vector<std::string> groupsWithPerm;
352
353 if (compare_nocase(perm, "ADMIN") == 0) {
354 groupsWithPerm = findGroupsWithAdmin();
355 }
356 else {
357 groupsWithPerm = findGroupsWithPerm(perm);
358 }
359
360 // only add groups that are not in the list yet
361 for (size_t g = 0; g < groupsWithPerm.size(); g++) {
362 if (std::find(groups.begin(), groups.end(), groupsWithPerm[g]) == groups.end()) {
363 groups.push_back(groupsWithPerm[g]);
364 }
365 }
366 }
367 itr++;
368 }
369
370 PendingTokenTask* task = new PendingTokenTask;
371
372 if (!user.size() || !token.size()) {
373 reply.body += "Invalid response";
374 reply.docType = HTTPReply::eText;
375 return true;
376 }
377 task->requestID = request.requestID;
378 task->URL = "http://my.bzflag.org/db/";
379 task->URL += "?action=CHECKTOKENS&checktokens=" + url_encode(user);
380 if (!ipIsLocal(request.ip)) {
381 task->URL += "@" + request.ip;
382 }
383 task->URL += "%3D" + token;
384
385 task->URL += "&groups=";
386 for (size_t g = 0; g < groups.size(); g++) {
387 task->URL += groups[g];
388 if (g + 1 < groups.size()) {
389 task->URL += "%0D%0A";
390 }
391 }
392
393 // give the task to bzfs and let it do it, when it's done it'll be processed
394 bz_addURLJob(task->URL.c_str(), task);

Callers

nothing calls this directly

Calls 12

findGroupsWithAdminFunction · 0.85
findGroupsWithPermFunction · 0.85
ipIsLocalFunction · 0.85
bz_addURLJobFunction · 0.85
c_strMethod · 0.80
compare_nocaseFunction · 0.70
url_encodeFunction · 0.70
getParamMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected