21#include "ldapconfigwidget.h"
22#include "ldapsearch.h"
24#include <kprogressdialog.h>
27#include <klocalizedstring.h>
29#include <kmessagebox.h>
31#include <QtCore/QObject>
37#include <QRadioButton>
42class LdapConfigWidget::Private
46 : mParent( parent ), mFeatures( W_ALL ), mProg( 0 )
48 mainLayout =
new QGridLayout( mParent );
49 mainLayout->setMargin( 0 );
54 void setAnonymous(
bool on );
55 void setSimple(
bool on );
56 void setSASL(
bool on );
57 void queryDNClicked();
58 void queryMechClicked();
72 QSpinBox *mPort, *mVersion, *mSizeLimit, *mTimeLimit, *mPageSize;
73 KLineEdit *mDn, *mBindDn, *mRealm;
75 QRadioButton *mAnonymous,*mSimple,*mSASL;
77 QPushButton *mEditButton;
78 QPushButton *mQueryMech;
79 QRadioButton *mSecNo,*mSecTLS,*mSecSSL;
83 KProgressDialog *mProg;
85 QGridLayout *mainLayout;
88void LdapConfigWidget::Private::initWidget()
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;
101 if ( mFeatures & W_USER ) {
102 label =
new QLabel( i18n(
"User:" ), mParent );
103 mUser =
new KLineEdit( mParent );
104 mUser->setObjectName( QLatin1String(
"kcfg_ldapuser") );
106 mainLayout->addWidget( label, row, 0 );
107 mainLayout->addWidget( mUser, row, 1, 1, 3 );
111 if ( mFeatures & W_BINDDN ) {
112 label =
new QLabel( i18n(
"Bind DN:" ), mParent );
113 mBindDn =
new KLineEdit( mParent );
114 mBindDn->setObjectName( QLatin1String(
"kcfg_ldapbinddn") );
116 mainLayout->addWidget( label, row, 0 );
117 mainLayout->addWidget( mBindDn, row, 1, 1, 3 );
121 if ( mFeatures & W_REALM ) {
122 label =
new QLabel( i18n(
"Realm:" ), mParent );
123 mRealm =
new KLineEdit( mParent );
124 mRealm->setObjectName( QLatin1String(
"kcfg_ldaprealm") );
126 mainLayout->addWidget( label, row, 0 );
127 mainLayout->addWidget( mRealm, row, 1, 1, 3 );
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 );
137 mainLayout->addWidget( label, row, 0 );
138 mainLayout->addWidget( mPassword, row, 1, 1, 3 );
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 );
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 );
161 mainLayout->addWidget( label, row, col );
162 mainLayout->addWidget( mPort, row, col+1 );
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 );
176 if ( mFeatures & ( W_PORT | W_VER ) ) {
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 );
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 );
206 if ( mFeatures & ( W_SIZELIMIT | W_TIMELIMIT ) ) {
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 );
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") );
227 mainLayout->addWidget( label, row, 0 );
228 mainLayout->addWidget( mDn, row, 1, 1, 1 );
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 );
238 if ( mFeatures & W_FILTER ) {
239 label =
new QLabel( i18n(
"Filter:" ), mParent );
240 mFilter =
new KLineEdit( mParent );
241 mFilter->setObjectName( QLatin1String(
"kcfg_ldapfilter") );
243 mainLayout->addWidget( label, row, 0 );
244 mainLayout->addWidget( mFilter, row, 1, 1, 3 );
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 );
263 connect( mSecNo, SIGNAL(clicked()), mParent, SLOT(setLDAPPort()) );
264 connect( mSecTLS, SIGNAL(clicked()), mParent, SLOT(setLDAPPort()) );
265 connect( mSecSSL, SIGNAL(clicked()), mParent, SLOT(setLDAPSPort()) );
267 mSecNo->setChecked(
true );
271 if ( mFeatures & W_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 );
281 new QRadioButton( i18nc(
"@option:radio anonymous authentication",
"Anonymous" ), authbox );
282 mAnonymous->setObjectName( QLatin1String(
"kcfg_ldapanon") );
283 hbox->addWidget( mAnonymous );
285 new QRadioButton( i18nc(
"@option:radio simple authentication",
"Simple" ), authbox );
286 mSimple->setObjectName( QLatin1String(
"kcfg_ldapsimple") );
287 hbox->addWidget( mSimple );
289 new QRadioButton( i18nc(
"@option:radio SASL authentication",
"SASL" ), authbox );
290 mSASL->setObjectName( QLatin1String(
"kcfg_ldapsasl") );
291 hbox->addWidget( mSASL );
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 );
307 mQueryMech =
new QPushButton( i18n(
"Query Server" ), authbox );
308 hbox->addWidget( mQueryMech );
309 connect( mQueryMech, SIGNAL(clicked()), mParent, SLOT(queryMechClicked()) );
312 mainLayout->addWidget( authbox, row, 0, 2, 4 );
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)) );
318 mAnonymous->setChecked(
true );
322void LdapConfigWidget::Private::sendQuery()
329 if ( mAttr == QLatin1String(
"supportedsaslmechanisms") ) {
335 _url.setDn( LdapDN( QLatin1String(
"") ) );
336 _url.setAttributes( QStringList( mAttr ) );
339 kDebug() <<
"sendQuery url:" << _url.prettyUrl();
347 if ( !search.
search( _url ) ) {
348 KMessageBox::error( mParent, search.
errorString() );
353 mProg =
new KProgressDialog( mParent );
354 mProg->setWindowTitle( i18n(
"LDAP Query" ) );
355 mProg->setModal(
true );
357 mProg->setLabelText( _url.prettyUrl() );
358 mProg->progressBar()->setRange( 0, 1 );
359 mProg->progressBar()->setValue( 0 );
362 kDebug() <<
"query canceled!";
365 if ( search.
error() ) {
367 KMessageBox::error( mParent, i18nc(
"%1 is a url to ldap server",
"Unknown error connecting %1", _url.prettyUrl() ) );
369 KMessageBox::error( mParent, search.
errorString() );
375void LdapConfigWidget::Private::queryMechClicked()
377 mAttr = QLatin1String(
"supportedsaslmechanisms");
379 if ( !mQResult.isEmpty() ) {
382 mMech->addItems( mQResult );
386void LdapConfigWidget::Private::queryDNClicked()
388 mAttr = QLatin1String(
"namingcontexts");
390 if ( !mQResult.isEmpty() ) {
391 mDn->setText( mQResult.first() );
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();
402 LdapAttrValue::ConstIterator end2( ( *it ).constEnd() );
403 for ( LdapAttrValue::ConstIterator it2 = ( *it ).constBegin();
404 it2 != end2; ++it2 ) {
405 mQResult.push_back( QString::fromUtf8( *it2 ) );
410void LdapConfigWidget::Private::loadResult(
LdapSearch *search )
417void LdapConfigWidget::Private::setAnonymous(
bool on )
423 mUser->setEnabled(
false );
426 mPassword->setEnabled(
false );
429 mBindDn->setEnabled(
false );
432 mRealm->setEnabled(
false );
435 mMech->setEnabled(
false );
438 mQueryMech->setEnabled(
false );
442void LdapConfigWidget::Private::setSimple(
bool on )
448 mUser->setEnabled(
false );
451 mPassword->setEnabled(
true );
454 mBindDn->setEnabled(
true );
457 mRealm->setEnabled(
false );
460 mMech->setEnabled(
false );
463 mQueryMech->setEnabled(
false );
467void LdapConfigWidget::Private::setSASL(
bool on )
473 mUser->setEnabled(
true );
476 mPassword->setEnabled(
true );
479 mBindDn->setEnabled(
true );
482 mRealm->setEnabled(
true );
485 mMech->setEnabled(
true );
488 mQueryMech->setEnabled(
true );
492void LdapConfigWidget::Private::setLDAPPort()
495 mPort->setValue( 389 );
499void LdapConfigWidget::Private::setLDAPSPort()
502 mPort->setValue( 636 );
507 : QWidget( parent, fl ), d( new Private( this ) )
512 QWidget *parent, Qt::WindowFlags fl )
513 : QWidget( parent, fl ), d( new Private( this ) )
515 d->mFeatures = flags;
540 if ( d->mSecSSL && d->mSecSSL->isChecked() ) {
542 }
else if ( d->mSecTLS && d->mSecTLS->isChecked() ) {
549 _server.
setUser( d->mUser->text() );
554 if ( d->mPassword ) {
558 _server.
setRealm( d->mRealm->text() );
561 _server.
setHost( d->mHost->text() );
564 _server.
setPort( d->mPort->value() );
567 _server.
setBaseDn( LdapDN( d->mDn->text() ) );
575 if ( d->mSizeLimit && d->mSizeLimit->value() != 0 ) {
578 if ( d->mTimeLimit && d->mTimeLimit->value() != 0 ) {
581 if ( d->mPageSize && d->mPageSize->value() != 0 ) {
584 if ( d->mAnonymous && d->mAnonymous->isChecked() ) {
586 }
else if ( d->mSimple && d->mSimple->isChecked() ) {
588 }
else if ( d->mSASL && d->mSASL->isChecked() ) {
590 _server.
setMech( d->mMech->currentText() );
600 d->mSecSSL->setChecked(
true );
605 d->mSecTLS->setChecked(
true );
610 d->mSecNo->setChecked(
true );
617 if ( d->mAnonymous ) {
618 d->mAnonymous->setChecked(
true );
623 d->mSimple->setChecked(
true );
628 d->mSASL->setChecked(
true );
651 d->mUser->setText( user );
655QString LdapConfigWidget::user()
const
657 return d->mUser ? d->mUser->text() : QString();
662 if ( d->mPassword ) {
663 d->mPassword->setText( password );
667QString LdapConfigWidget::password()
const
669 return d->mPassword ? d->mPassword->text() : QString();
675 d->mBindDn->setText( binddn );
679QString LdapConfigWidget::bindDn()
const
681 return d->mBindDn ? d->mBindDn->text() : QString();
687 d->mRealm->setText( realm );
691QString LdapConfigWidget::realm()
const
693 return d->mRealm ? d->mRealm->text() : QString();
699 d->mHost->setText( host );
703QString LdapConfigWidget::host()
const
705 return d->mHost ? d->mHost->text() : QString();
711 d->mPort->setValue( port );
715int LdapConfigWidget::port()
const
717 return d->mPort ? d->mPort->value() : 389;
723 d->mVersion->setValue( version );
727int LdapConfigWidget::version()
const
729 return d->mVersion ? d->mVersion->value() : 3;
735 d->mDn->setText( dn.toString() );
739LdapDN LdapConfigWidget::dn()
const
741 return d->mDn ? LdapDN( d->mDn->text() ) : LdapDN();
747 d->mFilter->setText( filter );
751QString LdapConfigWidget::filter()
const
753 return d->mFilter ? d->mFilter->text() : QString();
758 if ( d->mMech == 0 ) {
761 if ( !mech.isEmpty() ) {
763 while ( i < d->mMech->count() ) {
764 if ( d->mMech->itemText( i ) == mech ) {
769 if ( i == d->mMech->count() ) {
770 d->mMech->addItem( mech );
772 d->mMech->setCurrentIndex( i );
776QString LdapConfigWidget::mech()
const
778 return d->mMech ? d->mMech->currentText() : QString();
783 switch ( security ) {
785 d->mSecNo->setChecked(
true );
788 d->mSecSSL->setChecked(
true );
791 d->mSecTLS->setChecked(
true );
796LdapConfigWidget::Security LdapConfigWidget::security()
const
798 if ( d->mSecTLS->isChecked() ) {
801 if ( d->mSecSSL->isChecked() ) {
811 d->mAnonymous->setChecked(
true );
814 d->mSimple->setChecked(
true );
817 d->mSASL->setChecked(
true );
822LdapConfigWidget::Auth LdapConfigWidget::auth()
const
824 if ( d->mSimple->isChecked() ) {
827 if ( d->mSASL->isChecked() ) {
835 if ( d->mSizeLimit ) {
836 d->mSizeLimit->setValue( sizelimit );
840int LdapConfigWidget::sizeLimit()
const
842 return d->mSizeLimit ? d->mSizeLimit->value() : 0;
847 if ( d->mTimeLimit ) {
848 d->mTimeLimit->setValue( timelimit );
852int LdapConfigWidget::timeLimit()
const
854 return d->mTimeLimit ? d->mTimeLimit->value() : 0;
859 if ( d->mPageSize ) {
860 d->mPageSize->setValue( pagesize );
864int LdapConfigWidget::pageSize()
const
866 return d->mPageSize ? d->mPageSize->value() : 0;
869LdapConfigWidget::WinFlags LdapConfigWidget::features()
const
874void LdapConfigWidget::setFeatures( LdapConfigWidget::WinFlags features )
876 d->mFeatures = features;
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 ) {
893#include "moc_ldapconfigwidget.cpp"
This class represents an LDAP Object.
This class starts a search operation on a LDAP server and returns the search values via a Qt signal.
QString errorString() const
Returns the error description of the search operation.
int error() const
Returns the error code of the search operation (0 if no error).
void abandon()
Tries to abandon the search.
bool search(const LdapServer &server, const QStringList &attributes=QStringList(), int count=0)
Starts a search operation on the LDAP server.
A class that contains LDAP server connection settings.
QString realm() const
Returns the realm of the LDAP connection.
void setHost(const QString &host)
Sets the host of the LDAP connection.
@ Simple
Authenticate via login and password.
@ SASL
Azthenticate with the SASL framework.
@ Anonymous
Do no authentication.
void setMech(const QString &mech)
Sets the mech of the LDAP connection.
Security security() const
Returns the security mode of the LDAP connection.
void setSecurity(Security mode)
Sets the security mode of the LDAP connection.
void setSizeLimit(int sizelimit)
Sets the size limit of the LDAP connection.
LdapUrl url() const
Returns the server parameters as an RFC2255 compliant LDAP Url.
QString filter() const
Returns the filter string of the LDAP connection.
void setVersion(int version)
Sets the protocol version of the LDAP connection.
LdapDN baseDn() const
Returns the baseDn of the LDAP connection.
void setPassword(const QString &password)
Sets the password of the LDAP connection.
int timeLimit() const
Returns the time limit of the LDAP connection.
void setUser(const QString &user)
Sets the user of the LDAP connection.
QString password() const
Returns the password of the LDAP connection.
QString bindDn() const
Returns the bindDn of the LDAP connection.
void setTimeLimit(int limit)
Sets the time limit of the LDAP connection.
void setRealm(const QString &realm)
Sets the realm of the LDAP connection.
int version() const
Returns the protocol version of the LDAP connection.
void setUrl(const LdapUrl &url)
Sets the server parameters from an RFC2255 compliant LDAP url.
void setAuth(Auth authentication)
Sets the authentication method of the LDAP connection.
int port() const
Returns the port of the LDAP connection.
int sizeLimit() const
Returns the size limit of the LDAP connection.
void setPageSize(int size)
Sets the page size of the LDAP connection.
QString host() const
Returns the host of the LDAP connection.
int pageSize() const
Returns the page size of the LDAP connection.
void setBindDn(const QString &bindDn)
Sets the bindDn of the LDAP connection.
void setBaseDn(const LdapDN &baseDn)
Sets the baseDn of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.
Auth auth() const
Returns the authentication method of the LDAP connection.
@ None
Do not use any encryption.
void setPort(int port)
Sets the port of the LDAP connection.
QString mech() const
Returns the mech of the LDAP connection.
void setFilter(const QString &filter)
Sets the filter string of the LDAP connection.
A special url class for LDAP.
@ Base
Only the same level as the url.