21 #include "ldapconfigwidget.h"
22 #include "ldapsearch.h"
24 #include <kprogressdialog.h>
25 #include <kcombobox.h>
27 #include <klocalizedstring.h>
28 #include <klineedit.h>
29 #include <kmessagebox.h>
31 #include <QtCore/QObject>
36 #include <QPushButton>
37 #include <QRadioButton>
40 using namespace KLDAP;
42 class LdapConfigWidget::Private
46 : mParent( parent ), mFeatures( W_ALL ), mProg( 0 )
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;
83 KProgressDialog *mProg;
88 void 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 );
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 );
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 );
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 );
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 );
156 mPort->setRange( 0, 65535 );
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 );
169 mVersion->setRange( 2, 3 );
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 );
227 mainLayout->addWidget( label, row, 0 );
228 mainLayout->addWidget( mDn, row, 1, 1, 1 );
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 );
243 mainLayout->addWidget( label, row, 0 );
244 mainLayout->addWidget( mFilter, row, 1, 1, 3 );
248 if ( mFeatures & W_SECBOX ) {
252 mSecNo =
new QRadioButton( i18nc(
"@option:radio set no security",
"No" ), btgroup );
255 mSecTLS =
new QRadioButton( i18nc(
"@option:radio use TLS security",
"TLS" ), btgroup );
258 mSecSSL =
new QRadioButton( i18nc(
"@option:radio use SSL security",
"SSL" ), btgroup );
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 );
281 new QRadioButton( i18nc(
"@option:radio anonymous authentication",
"Anonymous" ), authbox );
285 new QRadioButton( i18nc(
"@option:radio simple authentication",
"Simple" ), authbox );
289 new QRadioButton( i18nc(
"@option:radio SASL authentication",
"SASL" ), authbox );
295 label =
new QLabel( i18n(
"SASL mechanism:" ), authbox );
297 mMech =
new KComboBox(
false, authbox );
299 mMech->setEditable(
true );
307 mQueryMech =
new QPushButton( i18n(
"Query Server" ), authbox );
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 );
322 void LdapConfigWidget::Private::sendQuery()
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() );
375 void LdapConfigWidget::Private::queryMechClicked()
379 if ( !mQResult.isEmpty() ) {
382 mMech->addItems( mQResult );
386 void LdapConfigWidget::Private::queryDNClicked()
390 if ( !mQResult.isEmpty() ) {
391 mDn->setText( mQResult.first() );
397 kDebug() <<
"object:" <<
object.toString();
398 mProg->progressBar()->setValue( mProg->progressBar()->value() + 1 );
404 it2 != end2; ++it2 ) {
410 void LdapConfigWidget::Private::loadResult(
LdapSearch *search )
417 void 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 );
442 void 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 );
467 void 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 );
492 void LdapConfigWidget::Private::setLDAPPort()
495 mPort->setValue( 389 );
499 void LdapConfigWidget::Private::setLDAPSPort()
502 mPort->setValue( 636 );
507 :
QWidget( parent, fl ), d( new Private( this ) )
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 );
615 switch ( server.
auth() ) {
617 if ( d->mAnonymous ) {
618 d->mAnonymous->setChecked(
true );
623 d->mSimple->setChecked(
true );
628 d->mSASL->setChecked(
true );
651 d->mUser->setText( user );
657 return d->mUser ? d->mUser->text() :
QString();
662 if ( d->mPassword ) {
663 d->mPassword->setText( password );
669 return d->mPassword ? d->mPassword->text() :
QString();
675 d->mBindDn->setText( binddn );
681 return d->mBindDn ? d->mBindDn->text() :
QString();
687 d->mRealm->setText( realm );
693 return d->mRealm ? d->mRealm->text() :
QString();
699 d->mHost->setText( host );
705 return d->mHost ? d->mHost->text() :
QString();
711 d->mPort->setValue( port );
717 return d->mPort ? d->mPort->value() : 389;
723 d->mVersion->setValue( version );
729 return d->mVersion ? d->mVersion->value() : 3;
735 d->mDn->setText( dn.toString() );
741 return d->mDn ? LdapDN( d->mDn->text() ) : LdapDN();
747 d->mFilter->setText( filter );
753 return d->mFilter ? d->mFilter->text() :
QString();
758 if ( d->mMech == 0 ) {
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 );
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 );
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 );
824 if ( d->mSimple->isChecked() ) {
827 if ( d->mSASL->isChecked() ) {
835 if ( d->mSizeLimit ) {
836 d->mSizeLimit->setValue( sizelimit );
842 return d->mSizeLimit ? d->mSizeLimit->value() : 0;
847 if ( d->mTimeLimit ) {
848 d->mTimeLimit->setValue( timelimit );
854 return d->mTimeLimit ? d->mTimeLimit->value() : 0;
859 if ( d->mPageSize ) {
860 d->mPageSize->setValue( pagesize );
866 return d->mPageSize ? d->mPageSize->value() : 0;
869 LdapConfigWidget::WinFlags LdapConfigWidget::features()
const
874 void LdapConfigWidget::setFeatures( LdapConfigWidget::WinFlags features )
876 d->mFeatures = features;
881 const int numberOfChild( ch.
count() );
882 for (
int i = 0; i < numberOfChild; ++i ) {
884 if ( widget && widget->
parent() == this ) {
893 #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.
const QObjectList & children() const
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 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.
int count(const T &value) const
QString fromUtf8(const char *str, int size)
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 clear()
Clears all server settings.
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.
void addLayout(QLayout *layout, int stretch)