KLdap

ldapconfigwidget.cpp
1/*
2 This file is part of libkldap.
3 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "ldapconfigwidget.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include "ldapsearch.h"
12
13#include "ldap_widgets_debug.h"
14#include <KAuthorized>
15#include <KLineEditEventHandler>
16#include <KLocalizedString>
17#include <KMessageBox>
18#include <KPasswordLineEdit>
19#include <QComboBox>
20#include <QProgressDialog>
21
22#include <QCheckBox>
23#include <QFormLayout>
24#include <QObject>
25#include <QPushButton>
26#include <QRadioButton>
27#include <QSpinBox>
28
29using namespace KLDAPWidgets;
30
31class Q_DECL_HIDDEN LdapConfigWidget::LdapConfigWidgetPrivate
32{
33public:
34 LdapConfigWidgetPrivate(LdapConfigWidget *parent)
35 : mParent(parent)
36 {
37 mainLayout = new QFormLayout(mParent);
38 mainLayout->setContentsMargins(10, 0, 10, 0);
39 }
40
41 void setLDAPPort();
42 void setLDAPSPort();
43 void setAnonymous(bool on);
44 void setSimple(bool on);
45 void setSASL(bool on);
46 void queryDNClicked();
47 void queryMechClicked();
48 void loadData(KLDAPCore::LdapSearch *search, const KLDAPCore::LdapObject &object);
49 void loadResult(KLDAPCore::LdapSearch *search);
50 void sendQuery();
51 void initWidget();
52
53 LdapConfigWidget *const mParent;
54 QStringList mQResult;
55 QString mAttr;
56
57 QLineEdit *mUser = nullptr;
58 KPasswordLineEdit *mPassword = nullptr;
59 QLineEdit *mHost = nullptr;
60 QSpinBox *mPort = nullptr;
61 QSpinBox *mVersion = nullptr;
62 QSpinBox *mSizeLimit = nullptr;
63 QSpinBox *mTimeLimit = nullptr;
64 QSpinBox *mPageSize = nullptr;
65 QLineEdit *mDn = nullptr;
66 QLineEdit *mBindDn = nullptr;
67 QLineEdit *mRealm = nullptr;
68 QLineEdit *mFilter = nullptr;
69 QRadioButton *mAnonymous = nullptr;
70 QRadioButton *mSimple = nullptr;
71 QRadioButton *mSASL = nullptr;
72 QCheckBox *mSubTree = nullptr;
73 QPushButton *mEditButton = nullptr;
74 QPushButton *mQueryMech = nullptr;
75 QRadioButton *mSecNo = nullptr;
76 QRadioButton *mSecTLS = nullptr;
77 QRadioButton *mSecSSL = nullptr;
78 QComboBox *mMech = nullptr;
79
80 QProgressDialog *mProg = nullptr;
81
82 QFormLayout *mainLayout = nullptr;
83 WinFlags mFeatures = W_ALL;
84 bool mCancelled = false;
85};
86
87void LdapConfigWidget::LdapConfigWidgetPrivate::initWidget()
88{
89 if (mFeatures & W_USER) {
90 mUser = new QLineEdit(mParent);
92 mUser->setObjectName("kcfg_ldapuser"_L1);
93
94 mainLayout->addRow(i18n("User:"), mUser);
95 }
96
97 if (mFeatures & W_BINDDN) {
98 mBindDn = new QLineEdit(mParent);
100 mBindDn->setObjectName("kcfg_ldapbinddn"_L1);
101
102 mainLayout->addRow(i18n("Bind DN:"), mBindDn);
103 }
104
105 if (mFeatures & W_REALM) {
106 mRealm = new QLineEdit(mParent);
108 mRealm->setObjectName("kcfg_ldaprealm"_L1);
109
110 mainLayout->addRow(i18n("Realm:"), mRealm);
111 }
112
113 if (mFeatures & W_PASS) {
114 mPassword = new KPasswordLineEdit(mParent);
116 mPassword->setObjectName("kcfg_ldappassword"_L1);
117 mPassword->setRevealPasswordMode(KAuthorized::authorize(QStringLiteral("lineedit_reveal_password")) ? KPassword::RevealMode::OnlyNew
118 : KPassword::RevealMode::Never);
119
120 mainLayout->addRow(i18n("Password:"), mPassword);
121 }
122
123 if (mFeatures & W_HOST) {
124 mHost = new QLineEdit(mParent);
126 mHost->setObjectName("kcfg_ldaphost"_L1);
128 mainLayout->addRow(i18n("Host:"), mHost);
129 }
130
131 if (mFeatures & W_PORT) {
132 mPort = new QSpinBox(mParent);
133 mPort->setRange(0, 65535);
134 mPort->setObjectName("kcfg_ldapport"_L1);
135 mPort->setValue(389);
136
137 mainLayout->addRow(i18n("Port:"), mPort);
138 }
139
140 if (mFeatures & W_VER) {
141 mVersion = new QSpinBox(mParent);
142 mVersion->setRange(2, 3);
143 mVersion->setObjectName("kcfg_ldapver"_L1);
144 mVersion->setValue(3);
145 mainLayout->addRow(i18n("LDAP version:"), mVersion);
146 }
147
148 if (mFeatures & W_SIZELIMIT) {
149 mSizeLimit = new QSpinBox(mParent);
150 mSizeLimit->setRange(0, 9999999);
151 mSizeLimit->setObjectName("kcfg_ldapsizelimit"_L1);
152 mSizeLimit->setValue(0);
153 mSizeLimit->setSpecialValueText(i18nc("default ldap size limit", "Default"));
154 mainLayout->addRow(i18n("Size limit:"), mSizeLimit);
155 }
156
157 if (mFeatures & W_TIMELIMIT) {
158 mTimeLimit = new QSpinBox(mParent);
159 mTimeLimit->setRange(0, 9999999);
160 mTimeLimit->setObjectName("kcfg_ldaptimelimit"_L1);
161 mTimeLimit->setValue(0);
162 mTimeLimit->setSuffix(i18n(" sec"));
163 mTimeLimit->setSpecialValueText(i18nc("default ldap time limit", "Default"));
164 mainLayout->addRow(i18n("Time limit:"), mTimeLimit);
165 }
166
167 if (mFeatures & W_PAGESIZE) {
168 mPageSize = new QSpinBox(mParent);
169 mPageSize->setRange(0, 9999999);
170 mPageSize->setObjectName("kcfg_ldappagesize"_L1);
171 mPageSize->setValue(0);
172 mPageSize->setSpecialValueText(i18n("No paging"));
173 mainLayout->addRow(i18n("Page size:"), mPageSize);
174 }
175
176 if (mFeatures & W_DN) {
177 auto horizontalLayout = new QHBoxLayout;
178 mDn = new QLineEdit(mParent);
180 mDn->setObjectName("kcfg_ldapdn"_L1);
181 horizontalLayout->addWidget(mDn);
182
183 // without host query doesn't make sense
184 if (mHost) {
185 auto dnquery = new QPushButton(i18nc("@action:button", "Query Server"), mParent);
186 dnquery->setEnabled(false);
187 connect(dnquery, &QPushButton::clicked, mParent, [this]() {
188 queryDNClicked();
189 });
190 connect(mDn, &QLineEdit::textChanged, mParent, [dnquery](const QString &text) {
191 dnquery->setEnabled(!text.trimmed().isEmpty());
192 });
193 horizontalLayout->addWidget(dnquery);
194 }
195 mainLayout->addRow(i18nc("Distinguished Name", "DN:"), horizontalLayout);
196 }
197
198 if (mFeatures & W_FILTER) {
199 mFilter = new QLineEdit(mParent);
201 mFilter->setObjectName("kcfg_ldapfilter"_L1);
202
203 mainLayout->addRow(i18n("Filter:"), mFilter);
204 }
205
206 if (mFeatures & W_SECBOX) {
207 auto btgroup = new QWidget(mParent);
208 btgroup->setContentsMargins({0, 0, 0, 0});
209
210 auto hbox = new QHBoxLayout(btgroup);
211
212 mSecNo = new QRadioButton(i18nc("@option:radio set no security", "No"), btgroup);
213 mSecNo->setObjectName("kcfg_ldapnosec"_L1);
214 hbox->addWidget(mSecNo);
215 mSecTLS = new QRadioButton(i18nc("@option:radio use TLS security", "TLS"), btgroup);
216 mSecTLS->setObjectName("kcfg_ldaptls"_L1);
217 hbox->addWidget(mSecTLS);
218 mSecSSL = new QRadioButton(i18nc("@option:radio use SSL security", "SSL"), btgroup);
219 mSecSSL->setObjectName("kcfg_ldapssl"_L1);
220 hbox->addWidget(mSecSSL);
221
222 connect(mSecNo, &QRadioButton::clicked, mParent, [this]() {
223 setLDAPPort();
224 });
225 connect(mSecTLS, &QRadioButton::clicked, mParent, [this]() {
226 setLDAPPort();
227 });
228 connect(mSecSSL, &QRadioButton::clicked, mParent, [this]() {
229 setLDAPSPort();
230 });
231
232 mSecNo->setChecked(true);
233 mainLayout->addRow(i18n("Security:"), btgroup);
234 }
235
236 if (mFeatures & W_AUTHBOX) {
237 // invisible QWidget for auto-exclusive radiobutton
238 auto authbox = new QWidget(mParent);
239 authbox->setContentsMargins({0, 0, 0, 0});
240
241 auto hbox = new QHBoxLayout(authbox);
242
243 mAnonymous = new QRadioButton(i18nc("@option:radio anonymous authentication", "Anonymous"), authbox);
244 mAnonymous->setObjectName("kcfg_ldapanon"_L1);
245 hbox->addWidget(mAnonymous);
246 mSimple = new QRadioButton(i18nc("@option:radio simple authentication", "Simple"), authbox);
247 mSimple->setObjectName("kcfg_ldapsimple"_L1);
248 hbox->addWidget(mSimple);
249 mSASL = new QRadioButton(i18nc("@option:radio SASL authentication", "SASL"), authbox);
250 mSASL->setObjectName("kcfg_ldapsasl"_L1);
251 hbox->addWidget(mSASL);
252 mainLayout->addRow(i18n("Authentication:"), authbox);
253
254 hbox = new QHBoxLayout;
255 mMech = new QComboBox(mParent);
256 mMech->setObjectName("kcfg_ldapsaslmech"_L1);
257 mMech->addItem(QStringLiteral("DIGEST-MD5"));
258 mMech->addItem(QStringLiteral("GSSAPI"));
259 mMech->addItem(QStringLiteral("PLAIN"));
260 hbox->addWidget(mMech);
261
262 // without host query doesn't make sense
263 if (mHost) {
264 mQueryMech = new QPushButton(i18nc("@action:button", "Query Server"), authbox);
265 hbox->addWidget(mQueryMech);
266 connect(mQueryMech, &QPushButton::clicked, mParent, [this]() {
267 queryMechClicked();
268 });
269 }
270 mainLayout->addRow(i18n("SASL mechanism:"), hbox);
271
272 connect(mAnonymous, &QRadioButton::toggled, mParent, [this](bool b) {
273 setAnonymous(b);
274 });
275 connect(mSimple, &QRadioButton::toggled, mParent, [this](bool b) {
276 setSimple(b);
277 });
278 connect(mSASL, &QRadioButton::toggled, mParent, [this](bool b) {
279 setSASL(b);
280 });
281
282 mAnonymous->setChecked(true);
283 }
284}
285
286void LdapConfigWidget::LdapConfigWidgetPrivate::sendQuery()
287{
288 KLDAPCore::LdapServer _server(mParent->server());
289
290 mQResult.clear();
291 mCancelled = true;
292
293 if (mAttr == "supportedsaslmechanisms"_L1) {
294 _server.setAuth(KLDAPCore::LdapServer::Anonymous);
295 }
296
297 KLDAPCore::LdapUrl _url(_server.url());
298
299 _url.setDn(KLDAPCore::LdapDN(""_L1));
300 _url.setAttributes(QStringList(mAttr));
301 _url.setScope(KLDAPCore::LdapUrl::Base);
302
303 qCDebug(LDAP_LOG) << "sendQuery url:" << _url.toDisplayString();
304
306 connect(&search, &KLDAPCore::LdapSearch::data, mParent, [this](KLDAPCore::LdapSearch *s, const KLDAPCore::LdapObject &obj) {
307 loadData(s, obj);
308 });
309 connect(&search, &KLDAPCore::LdapSearch::result, mParent, [this](KLDAPCore::LdapSearch *s) {
310 loadResult(s);
311 });
312
313 if (!search.search(_url)) {
314 KMessageBox::error(mParent, search.errorString(), i18nc("@title:window", "Check server"));
315 return;
316 }
317
318 if (!mProg) {
319 mProg = new QProgressDialog(mParent);
320 mProg->setWindowTitle(i18nc("@title:window", "LDAP Query"));
321 mProg->setModal(true);
322 }
323 mProg->setLabelText(_url.toDisplayString());
324 mProg->setMaximum(1);
325 mProg->setMinimum(0);
326 mProg->setValue(0);
327 mProg->exec();
328 if (mCancelled) {
329 qCDebug(LDAP_LOG) << "query canceled!";
330 search.abandon();
331 } else {
332 if (search.error()) {
333 if (search.errorString().isEmpty()) {
334 KMessageBox::error(mParent, i18nc("%1 is a url to ldap server", "Unknown error connecting %1", _url.toDisplayString()));
335 } else {
336 KMessageBox::error(mParent, search.errorString());
337 }
338 }
339 }
340}
341
342void LdapConfigWidget::LdapConfigWidgetPrivate::queryMechClicked()
343{
344 mAttr = QStringLiteral("supportedsaslmechanisms");
345 sendQuery();
346 if (!mQResult.isEmpty()) {
347 mQResult.sort();
348 mMech->clear();
349 mMech->addItems(mQResult);
350 }
351}
352
353void LdapConfigWidget::LdapConfigWidgetPrivate::queryDNClicked()
354{
355 mAttr = QStringLiteral("namingcontexts");
356 sendQuery();
357 if (!mQResult.isEmpty()) {
358 mDn->setText(mQResult.constFirst());
359 }
360}
361
362void LdapConfigWidget::LdapConfigWidgetPrivate::loadData(KLDAPCore::LdapSearch *, const KLDAPCore::LdapObject &object)
363{
364 qCDebug(LDAP_LOG) << "object:" << object.toString();
365 mProg->setValue(mProg->value() + 1);
366 KLDAPCore::LdapAttrMap::ConstIterator end(object.attributes().constEnd());
367 for (KLDAPCore::LdapAttrMap::ConstIterator it = object.attributes().constBegin(); it != end; ++it) {
368 KLDAPCore::LdapAttrValue::ConstIterator end2((*it).constEnd());
369 for (KLDAPCore::LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) {
370 mQResult.push_back(QString::fromUtf8(*it2));
371 }
372 }
373}
374
375void LdapConfigWidget::LdapConfigWidgetPrivate::loadResult(KLDAPCore::LdapSearch *search)
376{
377 Q_UNUSED(search)
378 mCancelled = false;
379 mProg->close();
380}
381
382void LdapConfigWidget::LdapConfigWidgetPrivate::setAnonymous(bool on)
383{
384 if (!on) {
385 return;
386 }
387 if (mUser) {
388 mUser->setEnabled(false);
389 }
390 if (mPassword) {
391 mPassword->setEnabled(false);
392 }
393 if (mBindDn) {
394 mBindDn->setEnabled(false);
395 }
396 if (mRealm) {
397 mRealm->setEnabled(false);
398 }
399 if (mMech) {
400 mMech->setEnabled(false);
401 }
402 if (mQueryMech) {
403 mQueryMech->setEnabled(false);
404 }
405}
406
407void LdapConfigWidget::LdapConfigWidgetPrivate::setSimple(bool on)
408{
409 if (!on) {
410 return;
411 }
412 if (mUser) {
413 mUser->setEnabled(false);
414 }
415 if (mPassword) {
416 mPassword->setEnabled(true);
417 }
418 if (mBindDn) {
419 mBindDn->setEnabled(true);
420 }
421 if (mRealm) {
422 mRealm->setEnabled(false);
423 }
424 if (mMech) {
425 mMech->setEnabled(false);
426 }
427 if (mQueryMech) {
428 mQueryMech->setEnabled(false);
429 }
430}
431
432void LdapConfigWidget::LdapConfigWidgetPrivate::setSASL(bool on)
433{
434 if (!on) {
435 return;
436 }
437 if (mUser) {
438 mUser->setEnabled(true);
439 }
440 if (mPassword) {
441 mPassword->setEnabled(true);
442 }
443 if (mBindDn) {
444 mBindDn->setEnabled(true);
445 }
446 if (mRealm) {
447 mRealm->setEnabled(true);
448 }
449 if (mMech) {
450 mMech->setEnabled(true);
451 }
452 if (mQueryMech) {
453 mQueryMech->setEnabled(true);
454 }
455}
456
457void LdapConfigWidget::LdapConfigWidgetPrivate::setLDAPPort()
458{
459 if (mPort) {
460 mPort->setValue(389);
461 }
462}
463
464void LdapConfigWidget::LdapConfigWidgetPrivate::setLDAPSPort()
465{
466 if (mPort) {
467 mPort->setValue(636);
468 }
469}
470
472 : QWidget(parent, fl)
473 , d(new LdapConfigWidgetPrivate(this))
474{
475}
476
478 : QWidget(parent, fl)
479 , d(new LdapConfigWidgetPrivate(this))
480{
481 d->mFeatures = flags;
482
483 d->initWidget();
484}
485
487
489{
490 return server().url();
491}
492
494{
495 KLDAPCore::LdapServer _server;
496 _server.setUrl(url);
497 setServer(_server);
498}
499
501{
502 KLDAPCore::LdapServer _server;
503 if (d->mSecSSL && d->mSecSSL->isChecked()) {
504 _server.setSecurity(KLDAPCore::LdapServer::SSL);
505 } else if (d->mSecTLS && d->mSecTLS->isChecked()) {
506 _server.setSecurity(KLDAPCore::LdapServer::TLS);
507 } else {
508 _server.setSecurity(KLDAPCore::LdapServer::None);
509 }
510
511 if (d->mUser) {
512 _server.setUser(d->mUser->text());
513 }
514 if (d->mBindDn) {
515 _server.setBindDn(d->mBindDn->text());
516 }
517 if (d->mPassword) {
518 _server.setPassword(d->mPassword->password());
519 }
520 if (d->mRealm) {
521 _server.setRealm(d->mRealm->text());
522 }
523 if (d->mHost) {
524 _server.setHost(d->mHost->text());
525 }
526 if (d->mPort) {
527 _server.setPort(d->mPort->value());
528 }
529 if (d->mDn) {
530 _server.setBaseDn(KLDAPCore::LdapDN(d->mDn->text()));
531 }
532 if (d->mFilter) {
533 _server.setFilter(d->mFilter->text());
534 }
535 if (d->mVersion) {
536 _server.setVersion(d->mVersion->value());
537 }
538 if (d->mSizeLimit && d->mSizeLimit->value() != 0) {
539 _server.setSizeLimit(d->mSizeLimit->value());
540 }
541 if (d->mTimeLimit && d->mTimeLimit->value() != 0) {
542 _server.setTimeLimit(d->mTimeLimit->value());
543 }
544 if (d->mPageSize && d->mPageSize->value() != 0) {
545 _server.setPageSize(d->mPageSize->value());
546 }
547 if (d->mAnonymous && d->mAnonymous->isChecked()) {
548 _server.setAuth(KLDAPCore::LdapServer::Anonymous);
549 } else if (d->mSimple && d->mSimple->isChecked()) {
550 _server.setAuth(KLDAPCore::LdapServer::Simple);
551 } else if (d->mSASL && d->mSASL->isChecked()) {
552 _server.setAuth(KLDAPCore::LdapServer::SASL);
553 _server.setMech(d->mMech->currentText());
554 }
555 return _server;
556}
557
559{
560 switch (server.security()) {
561 case KLDAPCore::LdapServer::SSL:
562 if (d->mSecSSL) {
563 d->mSecSSL->setChecked(true);
564 }
565 break;
566 case KLDAPCore::LdapServer::TLS:
567 if (d->mSecTLS) {
568 d->mSecTLS->setChecked(true);
569 }
570 break;
571 case KLDAPCore::LdapServer::None:
572 if (d->mSecNo) {
573 d->mSecNo->setChecked(true);
574 }
575 break;
576 }
577
578 switch (server.auth()) {
579 case KLDAPCore::LdapServer::Anonymous:
580 if (d->mAnonymous) {
581 d->mAnonymous->setChecked(true);
582 }
583 break;
584 case KLDAPCore::LdapServer::Simple:
585 if (d->mSimple) {
586 d->mSimple->setChecked(true);
587 }
588 break;
589 case KLDAPCore::LdapServer::SASL:
590 if (d->mSASL) {
591 d->mSASL->setChecked(true);
592 }
593 break;
594 }
595
609}
610
612{
613 if (d->mUser) {
614 d->mUser->setText(user);
615 }
616}
617
618QString LdapConfigWidget::user() const
619{
620 return d->mUser ? d->mUser->text() : QString();
621}
622
624{
625 if (d->mPassword) {
626 d->mPassword->setPassword(password);
627 }
628}
629
630QString LdapConfigWidget::password() const
631{
632 return d->mPassword ? d->mPassword->password() : QString();
633}
634
636{
637 if (d->mBindDn) {
638 d->mBindDn->setText(binddn);
639 }
640}
641
642QString LdapConfigWidget::bindDn() const
643{
644 return d->mBindDn ? d->mBindDn->text() : QString();
645}
646
648{
649 if (d->mRealm) {
650 d->mRealm->setText(realm);
651 }
652}
653
654QString LdapConfigWidget::realm() const
655{
656 return d->mRealm ? d->mRealm->text() : QString();
657}
658
660{
661 if (d->mHost) {
662 d->mHost->setText(host);
663 }
664}
665
666QString LdapConfigWidget::host() const
667{
668 return d->mHost ? d->mHost->text() : QString();
669}
670
672{
673 if (d->mPort) {
674 d->mPort->setValue(port);
675 }
676}
677
678int LdapConfigWidget::port() const
679{
680 return d->mPort ? d->mPort->value() : 389;
681}
682
684{
685 if (d->mVersion) {
686 d->mVersion->setValue(version);
687 }
688}
689
690int LdapConfigWidget::version() const
691{
692 return d->mVersion ? d->mVersion->value() : 3;
693}
694
695void LdapConfigWidget::setDn(const KLDAPCore::LdapDN &dn)
696{
697 if (d->mDn) {
698 d->mDn->setText(dn.toString());
699 }
700}
701
702KLDAPCore::LdapDN LdapConfigWidget::dn() const
703{
704 return d->mDn ? KLDAPCore::LdapDN(d->mDn->text()) : KLDAPCore::LdapDN();
705}
706
708{
709 if (d->mFilter) {
710 d->mFilter->setText(filter);
711 }
712}
713
714QString LdapConfigWidget::filter() const
715{
716 return d->mFilter ? d->mFilter->text() : QString();
717}
718
720{
721 if (d->mMech == nullptr) {
722 return;
723 }
724 if (!mech.isEmpty()) {
725 int i = 0;
726 while (i < d->mMech->count()) {
727 if (d->mMech->itemText(i) == mech) {
728 break;
729 }
730 i++;
731 }
732 if (i == d->mMech->count()) {
733 d->mMech->addItem(mech);
734 }
735 d->mMech->setCurrentIndex(i);
736 }
737}
738
739QString LdapConfigWidget::mech() const
740{
741 return d->mMech ? d->mMech->currentText() : QString();
742}
743
744void LdapConfigWidget::setSecurity(Security security)
745{
746 switch (security) {
747 case None:
748 d->mSecNo->setChecked(true);
749 break;
750 case SSL:
751 d->mSecSSL->setChecked(true);
752 break;
753 case TLS:
754 d->mSecTLS->setChecked(true);
755 break;
756 }
757}
758
759LdapConfigWidget::Security LdapConfigWidget::security() const
760{
761 if (d->mSecTLS->isChecked()) {
762 return TLS;
763 }
764 if (d->mSecSSL->isChecked()) {
765 return SSL;
766 }
767 return None;
768}
769
771{
772 switch (auth) {
773 case Anonymous:
774 d->mAnonymous->setChecked(true);
775 break;
776 case Simple:
777 d->mSimple->setChecked(true);
778 break;
779 case SASL:
780 d->mSASL->setChecked(true);
781 break;
782 }
783}
784
785LdapConfigWidget::Auth LdapConfigWidget::auth() const
786{
787 if (d->mSimple->isChecked()) {
788 return Simple;
789 }
790 if (d->mSASL->isChecked()) {
791 return SASL;
792 }
793 return Anonymous;
794}
795
797{
798 if (d->mSizeLimit) {
799 d->mSizeLimit->setValue(sizelimit);
800 }
801}
802
803int LdapConfigWidget::sizeLimit() const
804{
805 return d->mSizeLimit ? d->mSizeLimit->value() : 0;
806}
807
809{
810 if (d->mTimeLimit) {
811 d->mTimeLimit->setValue(timelimit);
812 }
813}
814
815int LdapConfigWidget::timeLimit() const
816{
817 return d->mTimeLimit ? d->mTimeLimit->value() : 0;
818}
819
821{
822 if (d->mPageSize) {
823 d->mPageSize->setValue(pagesize);
824 }
825}
826
827int LdapConfigWidget::pageSize() const
828{
829 return d->mPageSize ? d->mPageSize->value() : 0;
830}
831
832LdapConfigWidget::WinFlags LdapConfigWidget::features() const
833{
834 return d->mFeatures;
835}
836
837void LdapConfigWidget::setFeatures(LdapConfigWidget::WinFlags features)
838{
839 d->mFeatures = features;
840
841 // First delete all the child widgets.
842 // FIXME: I hope it's correct
844 const int numberOfChild(ch.count());
845 for (int i = 0; i < numberOfChild; ++i) {
846 QWidget *widget = qobject_cast<QWidget *>(ch[i]);
847 if (widget && widget->parent() == this) {
848 delete (widget);
849 }
850 }
851
852 // Re-create child widgets according to the new flags
853 d->initWidget();
854}
855
856#include "moc_ldapconfigwidget.cpp"
static Q_INVOKABLE bool authorize(const QString &action)
This class represents an LDAP Object.
Definition ldapobject.h:31
This class starts a search operation on a LDAP server and returns the search values via a Qt signal.
Definition ldapsearch.h:33
QString errorString() const
Returns the error description of the search operation.
void result(KLDAPCore::LdapSearch *search)
Emitted when the searching finished.
int error() const
Returns the error code of the search operation (0 if no error).
void abandon()
Tries to abandon the search.
void data(KLDAPCore::LdapSearch *search, const KLDAPCore::LdapObject &obj)
Emitted for each result object.
bool search(const LdapServer &server, const QStringList &attributes=QStringList(), int count=0)
Starts a search operation on the LDAP server.
A class that contains LDAP server connection settings.
Definition ldapserver.h:27
QString realm() const
Returns the realm of the LDAP connection.
void setHost(const QString &host)
Sets the host of the LDAP connection.
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
Security security() const
Returns the security mode of the LDAP connection.
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
QString filter() const
Returns the filter string of the LDAP connection.
void setVersion(int version)
Sets the protocol version of the LDAP connection.
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
void setPassword(const QString &password)
Sets the password of the LDAP connection.
int timeLimit() const
Returns the time limit of the LDAP connection.
void setUser(const QString &user)
Sets the user of the LDAP connection.
QString password() const
Returns the password of the LDAP connection.
QString bindDn() const
Returns the bindDn of the LDAP connection.
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
int version() const
Returns the protocol version of the LDAP connection.
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
void setAuth(Auth authentication)
Sets the authentication method of the LDAP connection.
int port() const
Returns the port of the LDAP connection.
int sizeLimit() const
Returns the size limit of the LDAP connection.
void setPageSize(int size)
Sets the page size of the LDAP connection.
QString host() const
Returns the host of the LDAP connection.
int pageSize() const
Returns the page size of the LDAP connection.
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.
Auth auth() const
Returns the authentication method of the LDAP connection.
void setPort(int port)
Sets the port of the LDAP connection.
QString mech() const
Returns the mech of the LDAP connection.
void setFilter(const QString &filter)
Sets the filter string of the LDAP connection.
A special url class for LDAP.
Definition ldapurl.h:30
LDAP Configuration widget.
void setPassword(const QString &password)
Sets the password.
void hostNameChanged(const QString &)
void setSizeLimit(int sizelimit)
Sets the size limit.
void setMech(const QString &mech)
Sets the SASL Mechanism.
void setHost(const QString &host)
Sets the host name.
void setRealm(const QString &realm)
Sets the SASL realm.
void setVersion(int version)
Sets the LDAP protocol version.
void setUrl(const KLDAPCore::LdapUrl &url)
Set up the widget via an LDAP Url.
void setDn(const KLDAPCore::LdapDN &dn)
Sets the LDAP Base DN.
void setSecurity(Security security)
Sets the security type (None, SSL, TLS).
~LdapConfigWidget() override
Destructs a configuration widget.
KLDAPCore::LdapServer server() const
Returns an LdapServer object constructed from the settings given.
KLDAPCore::LdapUrl url() const
Returns a LDAP Url constructed from the settings given.
void setPageSize(int pagesize)
Sets the page size.
LdapConfigWidget(QWidget *parent=nullptr, Qt::WindowFlags fl={})
Constructs an empty configuration widget.
void setBindDn(const QString &binddn)
Sets the bind dn.
void setPort(int port)
Sets the LDAP port.
void setTimeLimit(int timelimit)
Sets the time limit.
void setAuth(Auth auth)
Sets the authentication type (Anonymous, Simple, SASL).
void setUser(const QString &user)
Sets the user name.
void setServer(const KLDAPCore::LdapServer &server)
Set up the widget via an LdapServer object.
void setFilter(const QString &filter)
Sets the LDAP Filter.
void setRevealPasswordMode(KPassword::RevealMode revealPasswordMode)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
const QList< QKeySequence > & end()
void setChecked(bool)
void clicked(bool checked)
void toggled(bool checked)
void setSpecialValueText(const QString &txt)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void addRow(QLayout *layout)
void textChanged(const QString &text)
qsizetype count() const const
ConstIterator
const QObjectList & children() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
void setObjectName(QAnyStringView name)
void setRange(int minimum, int maximum)
void setSuffix(const QString &suffix)
void setValue(int val)
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
QString trimmed() const const
typedef WindowFlags
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.