21 #include "ldapconfigwidget.h"
22 #include "ldapsearch.h"
24 #include <kacceleratormanager.h>
25 #include <kprogressdialog.h>
26 #include <kcombobox.h>
28 #include <klocalizedstring.h>
29 #include <klineedit.h>
30 #include <kmessagebox.h>
32 #include <QtCore/QObject>
37 #include <QPushButton>
38 #include <QRadioButton>
41 using namespace KLDAP;
43 class LdapConfigWidget::Private
47 : mParent( parent ), mFeatures( W_ALL ), mProg( 0 )
49 mainLayout =
new QGridLayout( mParent );
50 mainLayout->setMargin( 0 );
55 void setAnonymous(
bool on );
56 void setSimple(
bool on );
57 void setSASL(
bool on );
58 void queryDNClicked();
59 void queryMechClicked();
73 QSpinBox *mPort, *mVersion, *mSizeLimit, *mTimeLimit, *mPageSize;
74 KLineEdit *mDn, *mBindDn, *mRealm;
76 QRadioButton *mAnonymous,*mSimple,*mSASL;
78 QPushButton *mEditButton;
79 QPushButton *mQueryMech;
80 QRadioButton *mSecNo,*mSecTLS,*mSecSSL;
84 KProgressDialog *mProg;
86 QGridLayout *mainLayout;
89 void LdapConfigWidget::Private::initWidget()
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;
102 if ( mFeatures & W_USER ) {
103 label =
new QLabel( i18n(
"User:" ), mParent );
104 mUser =
new KLineEdit( mParent );
105 mUser->setObjectName( QLatin1String(
"kcfg_ldapuser") );
107 mainLayout->addWidget( label, row, 0 );
108 mainLayout->addWidget( mUser, row, 1, 1, 3 );
112 if ( mFeatures & W_BINDDN ) {
113 label =
new QLabel( i18n(
"Bind DN:" ), mParent );
114 mBindDn =
new KLineEdit( mParent );
115 mBindDn->setObjectName( QLatin1String(
"kcfg_ldapbinddn") );
117 mainLayout->addWidget( label, row, 0 );
118 mainLayout->addWidget( mBindDn, row, 1, 1, 3 );
122 if ( mFeatures & W_REALM ) {
123 label =
new QLabel( i18n(
"Realm:" ), mParent );
124 mRealm =
new KLineEdit( mParent );
125 mRealm->setObjectName( QLatin1String(
"kcfg_ldaprealm") );
127 mainLayout->addWidget( label, row, 0 );
128 mainLayout->addWidget( mRealm, row, 1, 1, 3 );
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 );
138 mainLayout->addWidget( label, row, 0 );
139 mainLayout->addWidget( mPassword, row, 1, 1, 3 );
143 if ( mFeatures & W_HOST ) {
144 label =
new QLabel( i18n(
"Host:" ), mParent );
145 mHost =
new KLineEdit( mParent );
146 mHost->setObjectName( QLatin1String(
"kcfg_ldaphost") );
148 mainLayout->addWidget( label, row, 0 );
149 mainLayout->addWidget( mHost, row, 1, 1, 3 );
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 );
162 mainLayout->addWidget( label, row, col );
163 mainLayout->addWidget( mPort, row, col+1 );
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 );
177 if ( mFeatures & ( W_PORT | W_VER ) ) {
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 );
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 );
207 if ( mFeatures & ( W_SIZELIMIT | W_TIMELIMIT ) ) {
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 );
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") );
228 mainLayout->addWidget( label, row, 0 );
229 mainLayout->addWidget( mDn, row, 1, 1, 1 );
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 );
239 if ( mFeatures & W_FILTER ) {
240 label =
new QLabel( i18n(
"Filter:" ), mParent );
241 mFilter =
new KLineEdit( mParent );
242 mFilter->setObjectName( QLatin1String(
"kcfg_ldapfilter") );
244 mainLayout->addWidget( label, row, 0 );
245 mainLayout->addWidget( mFilter, row, 1, 1, 3 );
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 );
264 connect( mSecNo, SIGNAL(clicked()), mParent, SLOT(setLDAPPort()) );
265 connect( mSecTLS, SIGNAL(clicked()), mParent, SLOT(setLDAPPort()) );
266 connect( mSecSSL, SIGNAL(clicked()), mParent, SLOT(setLDAPSPort()) );
268 mSecNo->setChecked(
true );
272 if ( mFeatures & W_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 );
282 new QRadioButton( i18nc(
"@option:radio anonymous authentication",
"Anonymous" ), authbox );
283 mAnonymous->setObjectName( QLatin1String(
"kcfg_ldapanon") );
284 hbox->addWidget( mAnonymous );
286 new QRadioButton( i18nc(
"@option:radio simple authentication",
"Simple" ), authbox );
287 mSimple->setObjectName( QLatin1String(
"kcfg_ldapsimple") );
288 hbox->addWidget( mSimple );
290 new QRadioButton( i18nc(
"@option:radio SASL authentication",
"SASL" ), authbox );
291 mSASL->setObjectName( QLatin1String(
"kcfg_ldapsasl") );
292 hbox->addWidget( mSASL );
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 );
308 mQueryMech =
new QPushButton( i18n(
"Query Server" ), authbox );
309 hbox->addWidget( mQueryMech );
310 connect( mQueryMech, SIGNAL(clicked()), mParent, SLOT(queryMechClicked()) );
313 mainLayout->addWidget( authbox, row, 0, 2, 4 );
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)) );
319 mAnonymous->setChecked(
true );
323 void LdapConfigWidget::Private::sendQuery()
330 _url.setProtocol( ( mSecSSL && mSecSSL->isChecked() ) ? QLatin1String(
"ldaps") : QLatin1String(
"ldap") );
332 _url.setHost( mHost->text() );
335 _url.setPort( mPort->value() );
337 _url.
setDn( LdapDN( QLatin1String(
"") ) );
341 _url.
setExtension( QLatin1String(
"x-ver"), QString::number( mVersion->value() ) );
343 if ( mSecTLS && mSecTLS->isChecked() ) {
344 _url.
setExtension( QLatin1String(
"x-tls"), QLatin1String(
"") );
347 kDebug() <<
"sendQuery url:" << _url.prettyUrl();
355 if ( !search.
search( _url ) ) {
356 KMessageBox::error( mParent, search.
errorString() );
361 mProg =
new KProgressDialog( mParent );
362 mProg->setWindowTitle( i18n(
"LDAP Query" ) );
363 mProg->setModal(
true );
365 mProg->setLabelText( _url.prettyUrl() );
366 mProg->progressBar()->setRange( 0, 1 );
367 mProg->progressBar()->setValue( 0 );
370 kDebug() <<
"query canceled!";
373 if ( search.
error() ) {
374 KMessageBox::error( mParent, search.
errorString() );
379 void LdapConfigWidget::Private::queryMechClicked()
381 mAttr = QLatin1String(
"supportedsaslmechanisms");
383 if ( !mQResult.isEmpty() ) {
386 mMech->addItems( mQResult );
390 void LdapConfigWidget::Private::queryDNClicked()
392 mAttr = QLatin1String(
"namingcontexts");
394 if ( !mQResult.isEmpty() ) {
395 mDn->setText( mQResult.first() );
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();
406 LdapAttrValue::ConstIterator end2( ( *it ).constEnd() );
407 for ( LdapAttrValue::ConstIterator it2 = ( *it ).constBegin();
408 it2 != end2; ++it2 ) {
409 mQResult.push_back( QString::fromUtf8( *it2 ) );
414 void LdapConfigWidget::Private::loadResult(
LdapSearch *search )
421 void LdapConfigWidget::Private::setAnonymous(
bool on )
427 mUser->setEnabled(
false );
430 mPassword->setEnabled(
false );
433 mBindDn->setEnabled(
false );
436 mRealm->setEnabled(
false );
439 mMech->setEnabled(
false );
442 mQueryMech->setEnabled(
false );
446 void LdapConfigWidget::Private::setSimple(
bool on )
452 mUser->setEnabled(
false );
455 mPassword->setEnabled(
true );
458 mBindDn->setEnabled(
true );
461 mRealm->setEnabled(
false );
464 mMech->setEnabled(
false );
467 mQueryMech->setEnabled(
false );
471 void LdapConfigWidget::Private::setSASL(
bool on )
477 mUser->setEnabled(
true );
480 mPassword->setEnabled(
true );
483 mBindDn->setEnabled(
true );
486 mRealm->setEnabled(
true );
489 mMech->setEnabled(
true );
492 mQueryMech->setEnabled(
true );
496 void LdapConfigWidget::Private::setLDAPPort()
499 mPort->setValue( 389 );
503 void LdapConfigWidget::Private::setLDAPSPort()
506 mPort->setValue( 636 );
511 : QWidget( parent, fl ), d( new Private( this ) )
516 QWidget *parent, Qt::WindowFlags fl )
517 : QWidget( parent, fl ), d( new Private( this ) )
519 d->mFeatures = flags;
544 if ( d->mSecSSL && d->mSecSSL->isChecked() ) {
546 }
else if ( d->mSecTLS && d->mSecTLS->isChecked() ) {
553 _server.
setUser( d->mUser->text() );
558 if ( d->mPassword ) {
562 _server.
setRealm( d->mRealm->text() );
565 _server.
setHost( d->mHost->text() );
568 _server.
setPort( d->mPort->value() );
571 _server.
setBaseDn( LdapDN( d->mDn->text() ) );
579 if ( d->mSizeLimit && d->mSizeLimit->value() != 0 ) {
582 if ( d->mTimeLimit && d->mTimeLimit->value() != 0 ) {
585 if ( d->mPageSize && d->mPageSize->value() != 0 ) {
588 if ( d->mAnonymous && d->mAnonymous->isChecked() ) {
590 }
else if ( d->mSimple && d->mSimple->isChecked() ) {
592 }
else if ( d->mSASL && d->mSASL->isChecked() ) {
594 _server.
setMech( d->mMech->currentText() );
604 d->mSecSSL->setChecked(
true );
609 d->mSecTLS->setChecked(
true );
614 d->mSecNo->setChecked(
true );
619 switch ( server.
auth() ) {
621 if ( d->mAnonymous ) {
622 d->mAnonymous->setChecked(
true );
627 d->mSimple->setChecked(
true );
632 d->mSASL->setChecked(
true );
655 d->mUser->setText( user );
661 return d->mUser ? d->mUser->text() : QString();
666 if ( d->mPassword ) {
667 d->mPassword->setText( password );
673 return d->mPassword ? d->mPassword->text() : QString();
679 d->mBindDn->setText( binddn );
685 return d->mBindDn ? d->mBindDn->text() : QString();
691 d->mRealm->setText( realm );
697 return d->mRealm ? d->mRealm->text() : QString();
703 d->mHost->setText( host );
709 return d->mHost ? d->mHost->text() : QString();
715 d->mPort->setValue( port );
721 return d->mPort ? d->mPort->value() : 389;
727 d->mVersion->setValue( version );
733 return d->mVersion ? d->mVersion->value() : 3;
739 d->mDn->setText( dn.toString() );
745 return d->mDn ? LdapDN( d->mDn->text() ) : LdapDN();
751 d->mFilter->setText( filter );
757 return d->mFilter ? d->mFilter->text() : QString();
762 if ( d->mMech == 0 ) {
765 if ( !mech.isEmpty() ) {
767 while ( i < d->mMech->count() ) {
768 if ( d->mMech->itemText( i ) ==
mech ) {
773 if ( i == d->mMech->count() ) {
774 d->mMech->addItem( mech );
776 d->mMech->setCurrentIndex( i );
782 return d->mMech ? d->mMech->currentText() : QString();
787 switch ( security ) {
789 d->mSecNo->setChecked(
true );
792 d->mSecSSL->setChecked(
true );
795 d->mSecTLS->setChecked(
true );
802 if ( d->mSecTLS->isChecked() ) {
805 if ( d->mSecSSL->isChecked() ) {
815 d->mAnonymous->setChecked(
true );
818 d->mSimple->setChecked(
true );
821 d->mSASL->setChecked(
true );
828 if ( d->mSimple->isChecked() ) {
831 if ( d->mSASL->isChecked() ) {
839 if ( d->mSizeLimit ) {
840 d->mSizeLimit->setValue( sizelimit );
846 return d->mSizeLimit ? d->mSizeLimit->value() : 0;
851 if ( d->mTimeLimit ) {
852 d->mTimeLimit->setValue( timelimit );
858 return d->mTimeLimit ? d->mTimeLimit->value() : 0;
863 if ( d->mPageSize ) {
864 d->mPageSize->setValue( pagesize );
870 return d->mPageSize ? d->mPageSize->value() : 0;
873 LdapConfigWidget::WinFlags LdapConfigWidget::features()
const
878 void LdapConfigWidget::setFeatures( LdapConfigWidget::WinFlags features )
880 d->mFeatures = features;
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 ) {
897 #include "moc_ldapconfigwidget.cpp"
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
Authenticate via login and password.
QString mech() const
Returns the mech of the LDAP connection.
Azthenticate with the SASL framework.
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
void setAuth(Auth authentication)
Sets the authentication method of the LDAP connection.
int port() const
Returns the port of the LDAP connection.
bool search(const LdapServer &server, const QStringList &attributes=QStringList(), int count=0)
Starts a search operation on the LDAP server.
void abandon()
Tries to abandon the search.
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
void setScope(Scope scope)
Sets the scope part of the LDAP url.
Security security() const
Returns the security mode of the LDAP connection.
void setFilter(const QString &filter)
Sets the filter string of the LDAP connection.
A special url class for LDAP.
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
void setDn(const LdapDN &dn)
Sets the dn part of the LDAP url.
void setAttributes(const QStringList &attributes)
Sets the attributes part of the LDAP url.
void setPassword(const QString &password)
Sets the password of the LDAP connection.
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
QString errorString() const
Returns the error description of the search operation.
void setHost(const QString &host)
Sets the host of the LDAP connection.
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
int pageSize() const
Returns the page size of the LDAP connection.
Do not use any encryption.
int sizeLimit() const
Returns the size limit of the LDAP connection.
void setUser(const QString &user)
Sets the user of the LDAP connection.
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
A class that contains LDAP server connection settings.
void setPort(int port)
Sets the port of the LDAP connection.
QString host() const
Returns the host of the LDAP connection.
void setVersion(int version)
Sets the protocol version of the LDAP connection.
This class represents an LDAP Object.
void setExtension(const QString &key, const Extension &extension)
Sets the specified extension key with the value and criticality in extension.
void setPageSize(int size)
Sets the page size of the LDAP connection.
Only the same level as the url.
This class starts a search operation on a LDAP server and returns the search values via a Qt signal...
QString password() const
Returns the password of the LDAP connection.
int timeLimit() const
Returns the time limit of the LDAP connection.
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
QString bindDn() const
Returns the bindDn of the LDAP connection.
QString realm() const
Returns the realm of the LDAP connection.
int error() const
Returns the error code of the search operation (0 if no error).
QString filter() const
Returns the filter string of the LDAP connection.
int version() const
Returns the protocol version of the LDAP connection.
Auth auth() const
Returns the authentication method of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.