File indexing completed on 2025-02-02 05:08:38

0001 /*
0002     SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "setupautoconfigkolabldap.h"
0008 #include "ispdb/autoconfigkolabldap.h"
0009 #include "ldap.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 SetupAutoconfigKolabLdap::SetupAutoconfigKolabLdap(QObject *parent)
0014     : SetupObject(parent)
0015     , mIspdb(new AutoconfigKolabLdap(this))
0016 {
0017     connect(mIspdb, &AutoconfigKolabLdap::finished, this, &SetupAutoconfigKolabLdap::onIspdbFinished);
0018 }
0019 
0020 SetupAutoconfigKolabLdap::~SetupAutoconfigKolabLdap()
0021 {
0022     delete mIspdb;
0023 }
0024 
0025 void SetupAutoconfigKolabLdap::fillLdapServer(int i, QObject *o) const
0026 {
0027     const ldapServer isp = mIspdb->ldapServers().values().at(i);
0028     Ldap *ldapRes = qobject_cast<Ldap *>(o);
0029 
0030     // TODO: setting filter
0031 
0032     ldapRes->setServer(isp.hostname);
0033     ldapRes->setPort(isp.port);
0034     ldapRes->setBaseDn(isp.dn);
0035     ldapRes->setSecurity(isp.socketType);
0036     ldapRes->setVersion(isp.ldapVersion);
0037     ldapRes->setUser(isp.username);
0038     ldapRes->setPassword(isp.password);
0039     ldapRes->setBindDn(isp.bindDn);
0040 
0041     ldapRes->setRealm(isp.realm);
0042     ldapRes->setSaslMech(isp.saslMech);
0043 
0044     if (isp.pageSize != -1) {
0045         ldapRes->setPageSize(isp.pageSize);
0046     }
0047 
0048     if (isp.timeLimit != -1) {
0049         ldapRes->setPageSize(isp.timeLimit);
0050     }
0051 
0052     if (isp.sizeLimit != -1) {
0053         ldapRes->setPageSize(isp.sizeLimit);
0054     }
0055 
0056     // Anonymous is set by not setting the AuthenticationMethod
0057     if (isp.authentication == KLDAP::LdapServer::SASL) {
0058         ldapRes->setAuthenticationMethod(QStringLiteral("SASL"));
0059     } else if (isp.authentication == KLDAP::LdapServer::Simple) {
0060         ldapRes->setAuthenticationMethod(QStringLiteral("Simple"));
0061     }
0062 }
0063 
0064 int SetupAutoconfigKolabLdap::countLdapServers() const
0065 {
0066     return mIspdb->ldapServers().count();
0067 }
0068 
0069 void SetupAutoconfigKolabLdap::start()
0070 {
0071     mIspdb->start();
0072     Q_EMIT info(i18n("Searching for autoconfiguration..."));
0073 }
0074 
0075 void SetupAutoconfigKolabLdap::setEmail(const QString &email)
0076 {
0077     mIspdb->setEmail(email);
0078 }
0079 
0080 void SetupAutoconfigKolabLdap::setPassword(const QString &password)
0081 {
0082     mIspdb->setPassword(password);
0083 }
0084 
0085 void SetupAutoconfigKolabLdap::create()
0086 {
0087 }
0088 
0089 void SetupAutoconfigKolabLdap::destroy()
0090 {
0091 }
0092 
0093 void SetupAutoconfigKolabLdap::onIspdbFinished(bool status)
0094 {
0095     Q_EMIT ispdbFinished(status);
0096     if (status) {
0097         Q_EMIT info(i18n("Autoconfiguration found."));
0098     } else {
0099         Q_EMIT info(i18n("Autoconfiguration failed."));
0100     }
0101 }
0102 
0103 #include "moc_setupautoconfigkolabldap.cpp"