Commit 10276732 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve async job

parent 5400b85a
Pipeline #41839 passed with stage
in 8 minutes and 51 seconds
......@@ -5,6 +5,15 @@
*/
#include "ldapclientsearchconfigreadconfigjob.h"
#include "ldapclient_debug.h"
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <kldap/ldapdn.h>
#include <qt5keychain/keychain.h>
using namespace QKeychain;
using namespace KLDAP;
LdapClientSearchConfigReadConfigJob::LdapClientSearchConfigReadConfigJob(QObject *parent)
: QObject(parent)
......@@ -17,7 +26,151 @@ LdapClientSearchConfigReadConfigJob::~LdapClientSearchConfigReadConfigJob()
}
bool LdapClientSearchConfigReadConfigJob::canStart() const
{
return true;
}
void LdapClientSearchConfigReadConfigJob::start()
{
//TODO
if (!canStart()) {
//Failed !
Q_EMIT configLoaded(mServer);
deleteLater();
return;
}
readConfig();
}
bool LdapClientSearchConfigReadConfigJob::active() const
{
return mActive;
}
void LdapClientSearchConfigReadConfigJob::setActive(bool newActive)
{
mActive = newActive;
}
int LdapClientSearchConfigReadConfigJob::serverIndex() const
{
return mServerIndex;
}
void LdapClientSearchConfigReadConfigJob::setServerIndex(int newServerIndex)
{
mServerIndex = newServerIndex;
}
KConfigGroup LdapClientSearchConfigReadConfigJob::config() const
{
return mConfig;
}
void LdapClientSearchConfigReadConfigJob::setConfig(const KConfigGroup &newConfig)
{
mConfig = newConfig;
}
void LdapClientSearchConfigReadConfigJob::readConfig()
{
QString prefix;
if (mActive) {
prefix = QStringLiteral("Selected");
}
const QString host = mConfig.readEntry(prefix + QStringLiteral("Host%1").arg(mServerIndex),
QString()).trimmed();
if (!host.isEmpty()) {
mServer.setHost(host);
}
const int port = mConfig.readEntry(prefix + QStringLiteral("Port%1").arg(mServerIndex), 389);
mServer.setPort(port);
const QString base = mConfig.readEntry(prefix + QStringLiteral("Base%1").arg(mServerIndex),
QString()).trimmed();
if (!base.isEmpty()) {
mServer.setBaseDn(KLDAP::LdapDN(base));
}
const QString user = mConfig.readEntry(prefix + QStringLiteral("User%1").arg(mServerIndex),
QString()).trimmed();
if (!user.isEmpty()) {
mServer.setUser(user);
}
const QString bindDN = mConfig.readEntry(prefix + QStringLiteral("Bind%1").arg(mServerIndex), QString()).trimmed();
if (!bindDN.isEmpty()) {
mServer.setBindDn(bindDN);
}
#if 0 //Port
const QString pwdBindBNEntry = prefix + QStringLiteral("PwdBind%1").arg(mServerIndex);
QString pwdBindDN = mConfig.readEntry(pwdBindBNEntry, QString());
if (!pwdBindDN.isEmpty()) {
if (d->askWallet && KMessageBox::Yes == KMessageBox::questionYesNo(nullptr, i18n("LDAP password is stored as clear text, do you want to store it in kwallet?"),
i18n("Store clear text password in Wallet"),
KStandardGuiItem::yes(),
KStandardGuiItem::no(),
QStringLiteral("DoAskToStoreToWallet"))) {
d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), 0);
if (d->wallet) {
connect(d->wallet, &KWallet::Wallet::walletClosed, this, &LdapClientSearchConfig::slotWalletClosed);
d->useWallet = true;
if (!d->wallet->hasFolder(QStringLiteral("ldapclient"))) {
d->wallet->createFolder(QStringLiteral("ldapclient"));
}
d->wallet->setFolder(QStringLiteral("ldapclient"));
d->wallet->writePassword(pwdBindBNEntry, pwdBindDN);
mConfig.deleteEntry(pwdBindBNEntry);
mConfig.sync();
}
}
mServer.setPassword(pwdBindDN);
} else if (d->askWallet) { //Look at in Wallet
//Move as async here.
d->wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), 0);
if (d->wallet) {
d->useWallet = true;
if (!d->wallet->setFolder(QStringLiteral("ldapclient"))) {
d->wallet->createFolder(QStringLiteral("ldapclient"));
d->wallet->setFolder(QStringLiteral("ldapclient"));
}
d->wallet->readPassword(pwdBindBNEntry, pwdBindDN);
if (!pwdBindDN.isEmpty()) {
mServer.setPassword(pwdBindDN);
}
} else {
d->useWallet = false;
}
}
#endif
mServer.setTimeLimit(mConfig.readEntry(prefix + QStringLiteral("TimeLimit%1").arg(mServerIndex), 0));
mServer.setSizeLimit(mConfig.readEntry(prefix + QStringLiteral("SizeLimit%1").arg(mServerIndex), 0));
mServer.setPageSize(mConfig.readEntry(prefix + QStringLiteral("PageSize%1").arg(mServerIndex), 0));
mServer.setVersion(mConfig.readEntry(prefix + QStringLiteral("Version%1").arg(mServerIndex), 3));
QString tmp = mConfig.readEntry(prefix + QStringLiteral("Security%1").arg(mServerIndex),
QStringLiteral("None"));
mServer.setSecurity(KLDAP::LdapServer::None);
if (tmp == QLatin1String("SSL")) {
mServer.setSecurity(KLDAP::LdapServer::SSL);
} else if (tmp == QLatin1String("TLS")) {
mServer.setSecurity(KLDAP::LdapServer::TLS);
}
tmp = mConfig.readEntry(prefix + QStringLiteral("Auth%1").arg(mServerIndex),
QStringLiteral("Anonymous"));
mServer.setAuth(KLDAP::LdapServer::Anonymous);
if (tmp == QLatin1String("Simple")) {
mServer.setAuth(KLDAP::LdapServer::Simple);
} else if (tmp == QLatin1String("SASL")) {
mServer.setAuth(KLDAP::LdapServer::SASL);
}
mServer.setMech(mConfig.readEntry(prefix + QStringLiteral("Mech%1").arg(mServerIndex), QString()));
mServer.setFilter(mConfig.readEntry(prefix + QStringLiteral("UserFilter%1").arg(mServerIndex), QString()));
mServer.setCompletionWeight(mConfig.readEntry(prefix + QStringLiteral("CompletionWeight%1").arg(mServerIndex), -1));
Q_EMIT configLoaded(mServer);
deleteLater();
}
......@@ -7,6 +7,9 @@
#ifndef LDAPCLIENTSEARCHCONFIGREADCONFIGJOB_H
#define LDAPCLIENTSEARCHCONFIGREADCONFIGJOB_H
#include <QObject>
#include <KConfigGroup>
#include <KLDAP/LdapServer>
namespace KLDAP {
class LdapClientSearchConfigReadConfigJob : public QObject
{
......@@ -15,7 +18,27 @@ public:
explicit LdapClientSearchConfigReadConfigJob(QObject *parent = nullptr);
~LdapClientSearchConfigReadConfigJob() override;
Q_REQUIRED_RESULT bool canStart() const;
void start();
Q_REQUIRED_RESULT bool active() const;
void setActive(bool newActive);
Q_REQUIRED_RESULT int serverIndex() const;
void setServerIndex(int newServerIndex);
Q_REQUIRED_RESULT KConfigGroup config() const;
void setConfig(const KConfigGroup &newConfig);
Q_SIGNALS:
void configLoaded(const KLDAP::LdapServer &server);
private:
void readConfig();
int mServerIndex = -1;
KConfigGroup mConfig;
bool mActive = false;
KLDAP::LdapServer mServer;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment