Why do it?
LuciadCPillar allows you to connect to several web services. In practice, such web services are often access-restricted: they require authentication through a username and a password before they grant access.
How to do it?
By configuring a custom ICredentialsProvider
in the LuciadCPillar Environment
class, you can provide credentials.
You must create the Environment
class when you start using the LuciadCPillar library.
For more information about using the environment, see the
first map application sample.
Implementation notes
Implementations of |
The interface offers several methods that allow you to implement caching of user credentials supplied through a login panel.
When registering an ICredentialsProvider
on the Environment
, you can indicate if you want to make use of an internal credentials caching implementation in LuciadCPillar, or if you want
to perform the caching yourself.
The internal loader within LuciadCPillar supports these authentication schemes:
-
Basic
-
Digest
Integration in UI frameworks
The samples offer a ICredentialsProvider
implementation
that opens a credentials dialog.
The ICredentialsProvider
sends back as the result the credentials entered in the dialog form.
/** * This implementation of `ICredentialsProvider` relies on the _internal_ caching functionality offered * within LuciadCPillar (see Environment#withCredentialsProvider). Therefore, only the `getCredentials` * method is implemented and it always presents a user dialog to get the user information. */ class QtSampleCredentialsProvider final : public luciad::ICredentialsProvider { public: explicit QtSampleCredentialsProvider() : _parent(nullptr) { } void setParent(QObject* parent) { _parent = parent; } std::shared_ptr<luciad::Credentials> getCredentials(const luciad::AuthenticationScope& authenticationScope) override { return _parent ? QtCredentialsDialog::getCredentials(_parent, authenticationScope) : nullptr; } void confirmCredentials(const luciad::AuthenticationScope& authenticationScope, const std::shared_ptr<luciad::Credentials>& credentials) override { } void removeCredentials(const luciad::AuthenticationScope& authenticationScope, const std::shared_ptr<luciad::Credentials>& credentials) override { } private: QObject* _parent; };
This code snippet shows how to configure the ICredentialsProvider
on the Environment
.
In this configuration, LuciadCPillar caches the credentials itself.
std::shared_ptr<Environment> environment = Environment::createInitializer() .withLicenseText(licenseText) .withLoggingBackend(std::make_shared<SpdlogLoggingBackend>("sample_dataformats.log")) .withCredentialsProvider(credentialsProvider, true) .initialize();