diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-18 11:40:41 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-18 11:40:45 +0200 |
commit | a7e7f7fdd2a9d38921476d57f305c9cd4459a556 (patch) | |
tree | d9ad3bdc3e275004a54f508025f0d52227ab18cb /examples/davresource | |
parent | ea2e02ad656640c17d520b5a22c168c3c1faef56 (diff) | |
download | sink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.tar.gz sink-a7e7f7fdd2a9d38921476d57f305c9cd4459a556.zip |
Avoid storing the password in the configuration
The password (or any other secret), is now cached in the client process
(in-memory only), and delivered to the resource via command.
The resource avoids doing any operations against the source until the
secret is available.
Diffstat (limited to 'examples/davresource')
-rw-r--r-- | examples/davresource/davresource.cpp | 30 | ||||
-rw-r--r-- | examples/davresource/davresource.h | 5 |
2 files changed, 20 insertions, 15 deletions
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp index 22c502f..fa5e612 100644 --- a/examples/davresource/davresource.cpp +++ b/examples/davresource/davresource.cpp | |||
@@ -132,8 +132,8 @@ public: | |||
132 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 132 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
133 | { | 133 | { |
134 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Addressbook>()) { | 134 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Addressbook>()) { |
135 | SinkLogCtx(mLogCtx) << "Synchronizing addressbooks:" << mResourceUrl.url(); | 135 | SinkLogCtx(mLogCtx) << "Synchronizing addressbooks:" << resourceUrl().url(); |
136 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); | 136 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(resourceUrl()); |
137 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] (const KAsync::Error &error) { | 137 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] (const KAsync::Error &error) { |
138 | if (error) { | 138 | if (error) { |
139 | SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString(); | 139 | SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString(); |
@@ -147,7 +147,7 @@ public: | |||
147 | auto ridList = QSharedPointer<QByteArrayList>::create(); | 147 | auto ridList = QSharedPointer<QByteArrayList>::create(); |
148 | auto total = QSharedPointer<int>::create(0); | 148 | auto total = QSharedPointer<int>::create(0); |
149 | auto progress = QSharedPointer<int>::create(0); | 149 | auto progress = QSharedPointer<int>::create(0); |
150 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); | 150 | auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(resourceUrl()); |
151 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { | 151 | auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { |
152 | synchronizeAddressbooks(collectionsFetchJob ->collections()); | 152 | synchronizeAddressbooks(collectionsFetchJob ->collections()); |
153 | return collectionsFetchJob->collections(); | 153 | return collectionsFetchJob->collections(); |
@@ -233,8 +233,20 @@ KAsync::Job<QByteArray> replay(const ApplicationDomain::Contact &contact, Sink:: | |||
233 | return KAsync::null<QByteArray>(); | 233 | return KAsync::null<QByteArray>(); |
234 | } | 234 | } |
235 | 235 | ||
236 | KDAV2::DavUrl resourceUrl() const | ||
237 | { | ||
238 | if (secret().isEmpty()) { | ||
239 | return {}; | ||
240 | } | ||
241 | auto resourceUrl = mServer; | ||
242 | resourceUrl.setUserName(mUsername); | ||
243 | resourceUrl.setPassword(secret()); | ||
244 | return KDAV2::DavUrl{resourceUrl, KDAV2::CardDav}; | ||
245 | } | ||
246 | |||
236 | public: | 247 | public: |
237 | KDAV2::DavUrl mResourceUrl; | 248 | QUrl mServer; |
249 | QString mUsername; | ||
238 | }; | 250 | }; |
239 | 251 | ||
240 | 252 | ||
@@ -242,14 +254,12 @@ DavResource::DavResource(const Sink::ResourceContext &resourceContext) | |||
242 | : Sink::GenericResource(resourceContext) | 254 | : Sink::GenericResource(resourceContext) |
243 | { | 255 | { |
244 | auto config = ResourceConfig::getConfiguration(resourceContext.instanceId()); | 256 | auto config = ResourceConfig::getConfiguration(resourceContext.instanceId()); |
245 | auto resourceUrl = QUrl::fromUserInput(config.value("server").toString()); | 257 | auto server = QUrl::fromUserInput(config.value("server").toString()); |
246 | resourceUrl.setUserName(config.value("username").toString()); | 258 | auto username = config.value("username").toString(); |
247 | resourceUrl.setPassword(config.value("password").toString()); | ||
248 | |||
249 | mResourceUrl = KDAV2::DavUrl(resourceUrl, KDAV2::CardDav); | ||
250 | 259 | ||
251 | auto synchronizer = QSharedPointer<ContactSynchronizer>::create(resourceContext); | 260 | auto synchronizer = QSharedPointer<ContactSynchronizer>::create(resourceContext); |
252 | synchronizer->mResourceUrl = mResourceUrl; | 261 | synchronizer->mServer = server; |
262 | synchronizer->mUsername = username; | ||
253 | setupSynchronizer(synchronizer); | 263 | setupSynchronizer(synchronizer); |
254 | 264 | ||
255 | setupPreprocessors(ENTITY_TYPE_CONTACT, QVector<Sink::Preprocessor*>() << new ContactPropertyExtractor); | 265 | setupPreprocessors(ENTITY_TYPE_CONTACT, QVector<Sink::Preprocessor*>() << new ContactPropertyExtractor); |
diff --git a/examples/davresource/davresource.h b/examples/davresource/davresource.h index db175a4..b4f9e5a 100644 --- a/examples/davresource/davresource.h +++ b/examples/davresource/davresource.h | |||
@@ -44,11 +44,6 @@ class DavResource : public Sink::GenericResource | |||
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | DavResource(const Sink::ResourceContext &resourceContext); | 46 | DavResource(const Sink::ResourceContext &resourceContext); |
47 | |||
48 | private: | ||
49 | QStringList listAvailableFolders(); | ||
50 | |||
51 | KDAV2::DavUrl mResourceUrl; | ||
52 | }; | 47 | }; |
53 | 48 | ||
54 | class DavResourceFactory : public Sink::ResourceFactory | 49 | class DavResourceFactory : public Sink::ResourceFactory |