comparison Plugin/AuthorizationWebService.cpp @ 29:bc0431cb6b8f

fix for compatibility with simplified OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Dec 2018 21:16:54 +0100
parents c44013681a51
children c304ffca5d80
comparison
equal deleted inserted replaced
28:ae19947abf68 29:bc0431cb6b8f
69 { 69 {
70 body["token-key"] = token->GetKey(); 70 body["token-key"] = token->GetKey();
71 body["token-value"] = tokenValue; 71 body["token-value"] = tokenValue;
72 } 72 }
73 73
74 MemoryBuffer answerBody(context_); 74 MemoryBuffer answerBody;
75 MemoryBuffer answerHeaders(context_); 75 MemoryBuffer answerHeaders;
76 uint16_t httpStatus = 0; 76 uint16_t httpStatus = 0;
77 77
78 uint32_t headersCount = 0; 78 uint32_t headersCount = 0;
79 const char* headersKeys[2]; 79 const char* headersKeys[2];
80 const char* headersValues[2]; 80 const char* headersValues[2];
94 headersValues[headersCount] = "application/json"; 94 headersValues[headersCount] = "application/json";
95 headersCount++; 95 headersCount++;
96 96
97 std::string flatBody = body.toStyledString(); 97 std::string flatBody = body.toStyledString();
98 98
99 if (OrthancPluginHttpClient(context_, *answerBody, *answerHeaders, 99 if (OrthancPluginHttpClient(GetGlobalContext(), *answerBody, *answerHeaders,
100 &httpStatus, OrthancPluginHttpMethod_Post, 100 &httpStatus, OrthancPluginHttpMethod_Post,
101 url_.c_str(), headersCount, headersKeys, headersValues, 101 url_.c_str(), headersCount, headersKeys, headersValues,
102 flatBody.c_str(), flatBody.size(), 102 flatBody.c_str(), flatBody.size(),
103 username_.empty() ? NULL : username_.c_str(), 103 username_.empty() ? NULL : username_.c_str(),
104 password_.empty() ? NULL : password_.c_str(), 104 password_.empty() ? NULL : password_.c_str(),
118 !answer.isMember(GRANTED) || 118 !answer.isMember(GRANTED) ||
119 answer[GRANTED].type() != Json::booleanValue || 119 answer[GRANTED].type() != Json::booleanValue ||
120 (answer.isMember(VALIDITY) && 120 (answer.isMember(VALIDITY) &&
121 answer[VALIDITY].type() != Json::intValue)) 121 answer[VALIDITY].type() != Json::intValue))
122 { 122 {
123 LOG(ERROR) << "Syntax error in the result of the Web service"; 123 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); 124 "Syntax error in the result of the Web service");
125 } 125 }
126 126
127 validity = 0; 127 validity = 0;
128 if (answer.isMember(VALIDITY)) 128 if (answer.isMember(VALIDITY))
129 { 129 {
130 int tmp = answer[VALIDITY].asInt(); 130 int tmp = answer[VALIDITY].asInt();
131 if (tmp < 0) 131 if (tmp < 0)
132 { 132 {
133 LOG(ERROR) << "A validity duration cannot be negative"; 133 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); 134 "A validity duration cannot be negative");
135 } 135 }
136 136
137 validity = static_cast<unsigned int>(tmp); 137 validity = static_cast<unsigned int>(tmp);
138 } 138 }
139 139
140 return answer[GRANTED].asBool(); 140 return answer[GRANTED].asBool();
141 } 141 }
142 142
143 143
144 AuthorizationWebService::AuthorizationWebService(OrthancPluginContext* context,
145 const std::string& url) :
146 context_(context),
147 url_(url)
148 {
149 if (context_ == NULL)
150 {
151 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
152 }
153 }
154
155
156 void AuthorizationWebService::SetCredentials(const std::string& username, 144 void AuthorizationWebService::SetCredentials(const std::string& username,
157 const std::string& password) 145 const std::string& password)
158 { 146 {
159 username_ = username; 147 username_ = username;
160 password_ = password; 148 password_ = password;