Mercurial > hg > orthanc-authorization
diff 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 |
line wrap: on
line diff
--- a/Plugin/AuthorizationWebService.cpp Thu May 30 21:59:01 2024 +0200 +++ b/Plugin/AuthorizationWebService.cpp Fri Jun 14 16:26:53 2024 +0200 @@ -344,6 +344,7 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Syntax error in the result of the Auth Web service, the format of the UserProfile is invalid"); } + // LOG(INFO) << jsonProfile.toStyledString(); profile.name = jsonProfile[USER_NAME].asString(); @@ -451,4 +452,76 @@ return false; } + bool AuthorizationWebService::GetSettingsRoles(Json::Value& roles) + { + if (settingsRolesUrl_.empty()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not get settings-roles if the 'WebServiceSettingsRolesUrl' is not configured"); + } + + Orthanc::WebServiceParameters authWebservice; + + if (!username_.empty()) + { + authWebservice.SetCredentials(username_, password_); + } + + try + { + Orthanc::HttpClient authClient(authWebservice, ""); + authClient.SetUrl(settingsRolesUrl_); + authClient.SetMethod(Orthanc::HttpMethod_Get); + authClient.AddHeader("Expect", ""); + authClient.SetTimeout(10); + + authClient.ApplyAndThrowException(roles); + + return true; + } + catch (Orthanc::OrthancException& ex) + { + return false; + } + + } + + bool AuthorizationWebService::UpdateSettingsRoles(Json::Value& response, const Json::Value& roles) + { + if (settingsRolesUrl_.empty()) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadRequest, "Can not update settings-roles if the 'WebServiceSettingsRolesUrl' is not configured"); + } + + Orthanc::WebServiceParameters authWebservice; + + if (!username_.empty()) + { + authWebservice.SetCredentials(username_, password_); + } + + try + { + std::string bodyAsString; + Orthanc::Toolbox::WriteFastJson(bodyAsString, roles); + + Orthanc::HttpClient authClient(authWebservice, ""); + authClient.SetUrl(settingsRolesUrl_); + authClient.AssignBody(bodyAsString); + authClient.SetMethod(Orthanc::HttpMethod_Put); + authClient.AddHeader("Content-Type", "application/json"); + authClient.AddHeader("Expect", ""); + authClient.SetTimeout(10); + + authClient.ApplyAndThrowException(response); + + return true; + } + catch (Orthanc::OrthancException& ex) + { + return false; + } + + } + + }