Mercurial > hg > orthanc
changeset 2669:eaf10085ffa1 jobs
no passwords in public content of jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 09 Jun 2018 14:15:32 +0200 |
parents | d26dd081df97 |
children | c5646f766b3e |
files | Core/JobsEngine/JobsRegistry.cpp Core/JobsEngine/JobsRegistry.h Core/WebServiceParameters.cpp Core/WebServiceParameters.h OrthancServer/OrthancInitialization.cpp OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp |
diffstat | 6 files changed, 62 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -50,6 +50,7 @@ static const char* JOBS_REGISTRY = "JobsRegistry"; static const char* MAX_COMPLETED_JOBS = "MaxCompletedJobs"; static const char* CREATION_TIME = "CreationTime"; + static const char* LAST_CHANGE_TIME = "LastChangeTime"; static const char* RUNTIME = "Runtime"; @@ -226,6 +227,11 @@ return lastStateChangeTime_; } + void SetLastStateChangeTime(const boost::posix_time::ptime& time) + { + lastStateChangeTime_ = time; + } + const boost::posix_time::time_duration& GetRuntime() const { return runtime_; @@ -282,6 +288,7 @@ target[STATE] = EnumerationToString(state_); target[PRIORITY] = priority_; target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_); + target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_); target[RUNTIME] = static_cast<unsigned int>(runtime_.total_milliseconds()); return true; } @@ -294,7 +301,6 @@ JobHandler(IJobUnserializer& unserializer, const Json::Value& serialized) : - lastStateChangeTime_(boost::posix_time::microsec_clock::universal_time()), pauseScheduled_(false), cancelScheduled_(false) { @@ -303,17 +309,13 @@ priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY); creationTime_ = boost::posix_time::from_iso_string (SerializationToolbox::ReadString(serialized, CREATION_TIME)); + lastStateChangeTime_ = boost::posix_time::from_iso_string + (SerializationToolbox::ReadString(serialized, LAST_CHANGE_TIME)); runtime_ = boost::posix_time::milliseconds (SerializationToolbox::ReadInteger(serialized, RUNTIME)); retryTime_ = creationTime_; - if (state_ == JobState_Retry || - state_ == JobState_Running) - { - state_ = JobState_Pending; - } - job_.reset(unserializer.UnserializeJob(serialized[JOB])); job_->GetJobType(jobType_); job_->Start(); @@ -591,7 +593,8 @@ void JobsRegistry::SubmitInternal(std::string& id, - JobHandler* handlerRaw) + JobHandler* handlerRaw, + bool keepLastChangeTime) { if (handlerRaw == NULL) { @@ -600,6 +603,8 @@ std::auto_ptr<JobHandler> handler(handlerRaw); + boost::posix_time::ptime lastChangeTime = handler->GetLastStateChangeTime(); + boost::mutex::scoped_lock lock(mutex_); CheckInvariants(); @@ -633,6 +638,11 @@ throw OrthancException(ErrorCode_InternalError); } + if (keepLastChangeTime) + { + handler->SetLastStateChangeTime(lastChangeTime); + } + jobsIndex_.insert(std::make_pair(id, handler.release())); LOG(INFO) << "New job submitted with priority " << priority << ": " << id; @@ -645,7 +655,7 @@ IJob* job, // Takes ownership int priority) { - SubmitInternal(id, new JobHandler(job, priority)); + SubmitInternal(id, new JobHandler(job, priority), false); } @@ -653,7 +663,7 @@ int priority) { std::string id; - SubmitInternal(id, new JobHandler(job, priority)); + SubmitInternal(id, new JobHandler(job, priority), false); } @@ -1250,9 +1260,9 @@ for (Json::Value::ArrayIndex i = 0; i < s[JOBS].size(); i++) { std::auto_ptr<JobHandler> job(new JobHandler(unserializer, s[JOBS][i])); - + std::string id; - SubmitInternal(id, job.release()); + SubmitInternal(id, job.release(), true); } } }
--- a/Core/JobsEngine/JobsRegistry.h Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.h Sat Jun 09 14:15:32 2018 +0200 @@ -113,7 +113,8 @@ void RemoveRetryJob(JobHandler* handler); void SubmitInternal(std::string& id, - JobHandler* handler); + JobHandler* handler, + bool keepLastChangeTime); public: JobsRegistry() :
--- a/Core/WebServiceParameters.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/WebServiceParameters.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -130,6 +130,11 @@ SetUsername(""); SetPassword(""); } + else if (peer.size() == 2) + { + LOG(ERROR) << "The HTTP password is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } else if (peer.size() == 3) { SetUsername(peer.get(1u, "").asString()); @@ -178,12 +183,25 @@ SetUsername(GetStringMember(peer, "Username", "")); SetPassword(GetStringMember(peer, "Password", "")); + if (!username_.empty() && + !peer.isMember("Password")) + { + LOG(ERROR) << "The HTTP password is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } + #if ORTHANC_SANDBOXED == 0 if (peer.isMember("CertificateFile")) { SetClientCertificate(GetStringMember(peer, "CertificateFile", ""), GetStringMember(peer, "CertificateKeyFile", ""), GetStringMember(peer, "CertificateKeyPassword", "")); + + if (!peer.isMember("CertificateKeyPassword")) + { + LOG(ERROR) << "The password for the HTTPS certificate is not provided"; + throw OrthancException(ErrorCode_BadFileFormat); + } } #endif @@ -229,7 +247,8 @@ } - void WebServiceParameters::ToJson(Json::Value& value) const + void WebServiceParameters::ToJson(Json::Value& value, + bool includePasswords) const { if (advancedFormat_) { @@ -240,7 +259,11 @@ !password_.empty()) { value["Username"] = username_; - value["Password"] = password_; + + if (includePasswords) + { + value["Password"] = password_; + } } if (!certificateFile_.empty()) @@ -253,7 +276,8 @@ value["CertificateKeyFile"] = certificateKeyFile_; } - if (!certificateKeyPassword_.empty()) + if (!certificateKeyPassword_.empty() && + includePasswords) { value["CertificateKeyPassword"] = certificateKeyPassword_; } @@ -267,7 +291,11 @@ !password_.empty()) { value.append(username_); - value.append(password_); + + if (includePasswords) + { + value.append(password_); + } } } } @@ -283,6 +311,7 @@ target["CertificateKeyFile"] = certificateKeyFile_; target["CertificateKeyPassword"] = certificateKeyPassword_; target["PKCS11"] = pkcs11Enabled_; + target["AdvancedFormat"] = advancedFormat_; } @@ -304,5 +333,6 @@ } pkcs11Enabled_ = SerializationToolbox::ReadBoolean(serialized, "PKCS11"); + advancedFormat_ = SerializationToolbox::ReadBoolean(serialized, "AdvancedFormat"); } }
--- a/Core/WebServiceParameters.h Fri Jun 08 18:08:48 2018 +0200 +++ b/Core/WebServiceParameters.h Sat Jun 09 14:15:32 2018 +0200 @@ -128,7 +128,8 @@ void FromJson(const Json::Value& peer); - void ToJson(Json::Value& value) const; + void ToJson(Json::Value& value, + bool includePasswords) const; void Serialize(Json::Value& target) const; };
--- a/OrthancServer/OrthancInitialization.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -960,7 +960,7 @@ peers.removeMember(symbolicName); Json::Value v; - peer.ToJson(v); + peer.ToJson(v, true); peers[symbolicName] = v; }
--- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Fri Jun 08 18:08:48 2018 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Sat Jun 09 14:15:32 2018 +0200 @@ -98,7 +98,7 @@ SetOfInstancesJob::GetPublicContent(value); Json::Value v; - peer_.ToJson(v); + peer_.ToJson(v, false /* don't include passwords */); value["Peer"] = v; }