File indexing completed on 2024-12-22 04:45:43
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ldapsettingswidget.h" 0008 0009 #include <KLocalizedString> 0010 #include <KPasswordLineEdit> 0011 #include <QCheckBox> 0012 #include <QFormLayout> 0013 #include <QLabel> 0014 #include <QLineEdit> 0015 #include <QSpinBox> 0016 0017 LDapSettingsWidget::LDapSettingsWidget(RocketChatAccount *account, QWidget *parent) 0018 : SettingsWidgetBase(account, parent) 0019 , mEnabled(new QCheckBox(i18n("LDAP Enabled"), this)) 0020 , mHost(new QLineEdit(this)) 0021 , mPort(new QSpinBox(this)) 0022 , mReconnect(new QCheckBox(i18n("Reconnect"), this)) 0023 , mAuthenticationEnabled(new QCheckBox(i18n("Enabled"), this)) 0024 , mAuthenticationUserDN(new QLineEdit(this)) 0025 , mTimeouts(new QSpinBox(this)) 0026 , mConnectionTimeouts(new QSpinBox(this)) 0027 , mIdleTimeouts(new QSpinBox(this)) 0028 , mAuthenticationPassword(new KPasswordLineEdit(this)) 0029 { 0030 mEnabled->setObjectName(QStringLiteral("mEnabled")); 0031 mEnabled->setToolTip(i18n("Attempt to utilize LDAP for authentication.")); 0032 mMainLayout->addWidget(mEnabled); 0033 connectCheckBox(mEnabled, QStringLiteral("LDAP_Enable")); 0034 0035 mPort->setObjectName(QStringLiteral("mPort")); 0036 mPort->setMaximum(9999); 0037 mPort->setToolTip(i18n("Port to access LDAP. eg: 389 or 636 for LDAPS")); 0038 addSpinbox(i18n("Port"), mPort, QStringLiteral("LDAP_Port")); 0039 0040 mHost->setObjectName(QStringLiteral("mHost")); 0041 addLineEdit(i18n("Host"), mHost, QStringLiteral("LDAP_Host")); 0042 0043 mReconnect->setObjectName(QStringLiteral("mReconnect")); 0044 mReconnect->setToolTip(i18n("Try to reconnect automatically when connection is interrupted by some reason while executing operations.")); 0045 mMainLayout->addWidget(mReconnect); 0046 connectCheckBox(mReconnect, QStringLiteral("LDAP_Reconnect")); 0047 0048 auto authenticationLabel = createBoldLabel(i18n("Authentication")); 0049 authenticationLabel->setObjectName(QStringLiteral("authenticationLabel")); 0050 mMainLayout->addWidget(authenticationLabel); 0051 0052 mAuthenticationEnabled->setObjectName(QStringLiteral("mAuthenticationEnabled")); 0053 mMainLayout->addWidget(mAuthenticationEnabled); 0054 connectCheckBox(mAuthenticationEnabled, QStringLiteral("LDAP_Authentication")); 0055 0056 mAuthenticationUserDN->setObjectName(QStringLiteral("mAuthenticationUserDN")); 0057 addLineEdit(i18n("User DN"), mAuthenticationUserDN, QStringLiteral("LDAP_Authentication_UserDN")); 0058 mAuthenticationUserDN->setToolTip( 0059 i18n("The LDAP user that performs user lookups to authenticate other users when they sign in. This is typically a service account created specifically " 0060 "for third-party integrations. Use a fully qualified name, such as cn=Administrator,cn=Users,dc=Example,dc=com.")); 0061 0062 mAuthenticationPassword->setObjectName(QStringLiteral("mAuthenticationPassword")); 0063 addPasswordEdit(i18n("Password"), mAuthenticationPassword, QStringLiteral("LDAP_Authentication_Password")); 0064 0065 // Add password 0066 0067 auto timeoutLabel = createBoldLabel(i18n("Timeouts")); 0068 timeoutLabel->setObjectName(QStringLiteral("timeoutLabel")); 0069 mMainLayout->addWidget(timeoutLabel); 0070 0071 // Add timeouts 0072 mTimeouts->setObjectName(QStringLiteral("mTimeouts")); 0073 mTimeouts->setMaximum(99999); 0074 mTimeouts->setToolTip(i18n("How many milliseconds wait for a search result before return an error")); 0075 addSpinbox(i18n("Timeout (ms)"), mTimeouts, QStringLiteral("LDAP_Timeout")); 0076 0077 mConnectionTimeouts->setObjectName(QStringLiteral("mConnectionTimeouts")); 0078 mConnectionTimeouts->setMaximum(99999); 0079 mConnectionTimeouts->setToolTip(i18n("How many milliseconds wait for a search result before return an error")); 0080 addSpinbox(i18n("Connection Timeout (ms)"), mConnectionTimeouts, QStringLiteral("LDAP_Connect_Timeout")); 0081 0082 mIdleTimeouts->setObjectName(QStringLiteral("mIdleTimeouts")); 0083 mIdleTimeouts->setMaximum(99999); 0084 mIdleTimeouts->setToolTip( 0085 i18n("How many milliseconds wait after the latest LDAP operation until close the connection. (Each operation will open a new connection)")); 0086 addSpinbox(i18n("Idle Timeout (ms)"), mIdleTimeouts, QStringLiteral("LDAP_Idle_Timeout")); 0087 } 0088 0089 LDapSettingsWidget::~LDapSettingsWidget() = default; 0090 0091 void LDapSettingsWidget::initialize(const QMap<QString, QVariant> &mapSettings) 0092 { 0093 initializeWidget(mEnabled, mapSettings, true); 0094 initializeWidget(mHost, mapSettings); 0095 initializeWidget(mPort, mapSettings, 389); 0096 initializeWidget(mReconnect, mapSettings, false); 0097 initializeWidget(mAuthenticationEnabled, mapSettings); 0098 initializeWidget(mAuthenticationUserDN, mapSettings); 0099 initializeWidget(mTimeouts, mapSettings, 60000); 0100 initializeWidget(mConnectionTimeouts, mapSettings, 1000); 0101 initializeWidget(mIdleTimeouts, mapSettings, 1000); 0102 initializeWidget(mAuthenticationPassword, mapSettings); 0103 } 0104 0105 #include "moc_ldapsettingswidget.cpp"