32#include "moc_qgsauthconfigedit.cpp"
34using namespace Qt::StringLiterals;
39 , mDataProvider( dataprovider )
45 if ( !disabled && !authcfg.isEmpty() )
50 if ( disabled || !idok )
52 mAuthNotifyLayout =
new QVBoxLayout;
53 this->setLayout( mAuthNotifyLayout );
56 if ( !authcfg.isEmpty() )
58 msg +=
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg );
60 mAuthNotify =
new QLabel( msg,
this );
61 mAuthNotifyLayout->addWidget( mAuthNotify );
64 buttonBox->button( QDialogButtonBox::Save )->setEnabled(
false );
69 connect( btnClear, &QToolButton::clicked,
this, &QgsAuthConfigEdit::btnClear_clicked );
70 connect( leName, &QLineEdit::textChanged,
this, &QgsAuthConfigEdit::leName_textChanged );
71 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
72 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigEdit::saveConfig );
73 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigEdit::resetConfig );
74 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [] {
QgsHelp::openHelp( u
"auth_system/auth_overview.html#authentication-configurations"_s ); } );
76 populateAuthMethods();
78 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ), stkwAuthMethods, &QStackedWidget::setCurrentIndex );
79 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this] { validateAuth(); } );
83 if ( cmbAuthMethods->count() > 0 )
85 cmbAuthMethods->setCurrentIndex( 0 );
86 stkwAuthMethods->setCurrentIndex( 0 );
99void QgsAuthConfigEdit::populateAuthMethods()
104 QMap<QString, const QgsAuthMethodMetadata *> descmap;
105 const auto constAuthMethodKeys = authMethodKeys;
106 for (
const QString &authMethodKey : constAuthMethodKeys )
111 QgsDebugError( u
"Load auth method instance FAILED for auth method key (%1)"_s.arg( authMethodKey ) );
117 QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
118 for ( it = descmap.begin(); it != descmap.end(); ++it )
120 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>(
QgsApplication::authManager()->authMethodEditWidget( it.value()->key(),
this ) );
123 QgsDebugError( u
"Load auth method edit widget FAILED for auth method key (%1)"_s.arg( it.value()->key() ) );
128 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
129 stkwAuthMethods->addWidget( editWidget );
133void QgsAuthConfigEdit::loadConfig()
135 const bool emptyAuthCfg = mAuthCfg.isEmpty();
136 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
149 QgsAuthMethodConfig mconfig;
152 QgsDebugError( u
"Loading FAILED for authcfg: %1"_s.arg( mAuthCfg ) );
156 if ( !mconfig.
isValid(
true ) )
158 QgsDebugError( u
"Loading FAILED for authcfg (%1): invalid config"_s.arg( mAuthCfg ) );
163 leName->setText( mconfig.
name() );
164 leResource->setText( mconfig.
uri() );
165 authCfgEdit->setAuthConfigId( mconfig.
id() );
172 if ( authMethodKey.isEmpty() )
174 QgsDebugError( u
"Loading FAILED for authcfg (%1): no auth method found"_s.arg( mAuthCfg ) );
178 if ( mconfig.
method() != authMethodKey )
180 QgsDebugError( u
"Loading FAILED for authcfg (%1): auth method and key mismatch"_s.arg( mAuthCfg ) );
184 const int indx = authMethodIndex( authMethodKey );
187 QgsDebugError( u
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'"_s.arg( mAuthCfg, authMethodKey ) );
188 if ( cmbAuthMethods->count() > 0 )
190 cmbAuthMethods->setCurrentIndex( 0 );
191 stkwAuthMethods->setCurrentIndex( 0 );
196 cmbAuthMethods->setCurrentIndex( indx );
197 stkwAuthMethods->setCurrentIndex( indx );
199 QgsAuthMethodEdit *editWidget = currentEditWidget();
202 QgsDebugError( u
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)"_s.arg( mAuthCfg, authMethodKey ) );
209void QgsAuthConfigEdit::resetConfig()
216void QgsAuthConfigEdit::saveConfig()
221 const QString authMethodKey = cmbAuthMethods->currentData().toString();
223 QgsAuthMethodEdit *editWidget = currentEditWidget();
233 QgsDebugError( u
"Save auth config FAILED when loading auth method instance from key (%1)"_s.arg( authMethodKey ) );
237 QgsAuthMethodConfig mconfig;
238 mconfig.
setName( leName->text() );
239 mconfig.
setUri( leResource->text() );
246 QgsDebugError( u
"Save auth config FAILED: config invalid"_s );
250 const QString authCfgId( authCfgEdit->configId() );
251 if ( !mAuthCfg.isEmpty() )
253 if ( authCfgId == mAuthCfg )
255 mconfig.
setId( mAuthCfg );
262 QgsDebugError( u
"Updating auth config FAILED for authcfg: %1"_s.arg( mAuthCfg ) );
267 mconfig.
setId( authCfgId );
275 mAuthCfg = authCfgId;
279 QgsDebugError( u
"Storing new auth config with user-created unique ID FAILED"_s );
283 else if ( mAuthCfg.isEmpty() )
285 if ( authCfgId.isEmpty() )
289 mAuthCfg = mconfig.
id();
299 mconfig.
setId( authCfgId );
302 mAuthCfg = authCfgId;
307 QgsDebugError( u
"Storing new auth config with user-created unique ID FAILED"_s );
315void QgsAuthConfigEdit::btnClear_clicked()
317 QgsAuthMethodEdit *editWidget = currentEditWidget();
329void QgsAuthConfigEdit::clearAll()
333 authCfgEdit->clear();
335 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
337 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->widget( i ) );
347void QgsAuthConfigEdit::validateAuth()
349 bool authok = !leName->text().isEmpty();
351 QgsAuthMethodEdit *editWidget = currentEditWidget();
360 authok = authok && authCfgEdit->validate();
362 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
365void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
371int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
373 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
378 return qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->currentWidget() );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
void authenticationConfigStored(const QString &authcfg)
Emit generated id when a new config is saved to auth database.
void authenticationConfigUpdated(const QString &authcfg)
Emit current id when an existing config is updated in auth database.
QgsAuthConfigEdit(QWidget *parent=nullptr, const QString &authcfg=QString(), const QString &dataprovider=QString())
Create a dialog for editing an authentication configuration.
void validityChanged(bool valid)
Validity of the ID has changed.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
QStringList configIds() const
Gets list of authentication ids from database.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Gets authentication method from the config/provider cache via its key.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Gets keys of supported authentication methods.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
QString configAuthMethodKey(const QString &authcfg) const
Gets key of authentication method associated with config ID.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
QString method() const
Textual key of the associated authentication method.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
void setName(const QString &name)
Sets name of configuration.
void setConfigMap(const QgsStringMap &map)
Set extended configuration map.
void setVersion(int version)
Sets version of the configuration.
const QString name() const
Gets name of configuration.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
QgsStringMap configMap() const
Gets extended configuration, mapped to key/value pairs of QStrings.
void setMethod(const QString &method)
void setUri(const QString &uri)
void setId(const QString &id)
Sets auth config ID.
Abstract base class for the edit widget of authentication method plugins.
virtual bool validateConfig()=0
Validate the configuration of subclasses.
void validityChanged(bool valid)
Emitted when the configuration validatity changes.
virtual void clearConfig()=0
Clear GUI controls in subclassed widget.
virtual QgsStringMap configMap() const =0
The configuration key-vale map of subclasses.
virtual void loadConfig(const QgsStringMap &configmap)=0
Load an existing config map into subclassed widget.
int version() const
Increment this if method is significantly updated, allow updater code to be written for previously st...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)