• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KLDAP Library

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

KDE's Doxygen guidelines are available online.

KLDAP Library

Skip menu "KLDAP Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal