comparison Plugin/AuthorizationWebService.cpp @ 194:85859ec3aa7e

added support for roles/permissions edition
author Alain Mazy <am@orthanc.team>
date Fri, 14 Jun 2024 16:26:53 +0200
parents c4b908970ae4
children
comparison
equal deleted inserted replaced
188:c4b908970ae4 194:85859ec3aa7e
342 jsonProfile[USER_NAME].type() != Json::stringValue) 342 jsonProfile[USER_NAME].type() != Json::stringValue)
343 { 343 {
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 344 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
345 "Syntax error in the result of the Auth Web service, the format of the UserProfile is invalid"); 345 "Syntax error in the result of the Auth Web service, the format of the UserProfile is invalid");
346 } 346 }
347 // LOG(INFO) << jsonProfile.toStyledString();
347 348
348 profile.name = jsonProfile[USER_NAME].asString(); 349 profile.name = jsonProfile[USER_NAME].asString();
349 350
350 for (Json::ArrayIndex i = 0; i < jsonProfile[PERMISSIONS].size(); ++i) 351 for (Json::ArrayIndex i = 0; i < jsonProfile[PERMISSIONS].size(); ++i)
351 { 352 {
449 } 450 }
450 451
451 return false; 452 return false;
452 } 453 }
453 454
455 bool AuthorizationWebService::GetSettingsRoles(Json::Value& roles)
456 {
457 if (settingsRolesUrl_.empty())
458 {
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not get settings-roles if the 'WebServiceSettingsRolesUrl' is not configured");
460 }
461
462 Orthanc::WebServiceParameters authWebservice;
463
464 if (!username_.empty())
465 {
466 authWebservice.SetCredentials(username_, password_);
467 }
468
469 try
470 {
471 Orthanc::HttpClient authClient(authWebservice, "");
472 authClient.SetUrl(settingsRolesUrl_);
473 authClient.SetMethod(Orthanc::HttpMethod_Get);
474 authClient.AddHeader("Expect", "");
475 authClient.SetTimeout(10);
476
477 authClient.ApplyAndThrowException(roles);
478
479 return true;
480 }
481 catch (Orthanc::OrthancException& ex)
482 {
483 return false;
484 }
485
486 }
487
488 bool AuthorizationWebService::UpdateSettingsRoles(Json::Value& response, const Json::Value& roles)
489 {
490 if (settingsRolesUrl_.empty())
491 {
492 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not update settings-roles if the 'WebServiceSettingsRolesUrl' is not configured");
493 }
494
495 Orthanc::WebServiceParameters authWebservice;
496
497 if (!username_.empty())
498 {
499 authWebservice.SetCredentials(username_, password_);
500 }
501
502 try
503 {
504 std::string bodyAsString;
505 Orthanc::Toolbox::WriteFastJson(bodyAsString, roles);
506
507 Orthanc::HttpClient authClient(authWebservice, "");
508 authClient.SetUrl(settingsRolesUrl_);
509 authClient.AssignBody(bodyAsString);
510 authClient.SetMethod(Orthanc::HttpMethod_Put);
511 authClient.AddHeader("Content-Type", "application/json");
512 authClient.AddHeader("Expect", "");
513 authClient.SetTimeout(10);
514
515 authClient.ApplyAndThrowException(response);
516
517 return true;
518 }
519 catch (Orthanc::OrthancException& ex)
520 {
521 return false;
522 }
523
524 }
525
526
454 } 527 }