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

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