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, [] {
75 QgsHelp::openHelp( u
"auth_system/auth_overview.html#authentication-configurations"_s );
78 populateAuthMethods();
80 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ), stkwAuthMethods, &QStackedWidget::setCurrentIndex );
81 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this] { validateAuth(); } );
85 if ( cmbAuthMethods->count() > 0 )
87 cmbAuthMethods->setCurrentIndex( 0 );
88 stkwAuthMethods->setCurrentIndex( 0 );
101void QgsAuthConfigEdit::populateAuthMethods()
106 QMap<QString, const QgsAuthMethodMetadata *> descmap;
107 const auto constAuthMethodKeys = authMethodKeys;
108 for (
const QString &authMethodKey : constAuthMethodKeys )
113 QgsDebugError( u
"Load auth method instance FAILED for auth method key (%1)"_s.arg( authMethodKey ) );
119 QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
120 for ( it = descmap.begin(); it != descmap.end(); ++it )
122 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>(
127 QgsDebugError( u
"Load auth method edit widget FAILED for auth method key (%1)"_s.arg( it.value()->key() ) );
132 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
133 stkwAuthMethods->addWidget( editWidget );
137void QgsAuthConfigEdit::loadConfig()
139 const bool emptyAuthCfg = mAuthCfg.isEmpty();
140 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
153 QgsAuthMethodConfig mconfig;
156 QgsDebugError( u
"Loading FAILED for authcfg: %1"_s.arg( mAuthCfg ) );
160 if ( !mconfig.
isValid(
true ) )
162 QgsDebugError( u
"Loading FAILED for authcfg (%1): invalid config"_s.arg( mAuthCfg ) );
167 leName->setText( mconfig.
name() );
168 leResource->setText( mconfig.
uri() );
169 authCfgEdit->setAuthConfigId( mconfig.
id() );
176 if ( authMethodKey.isEmpty() )
178 QgsDebugError( u
"Loading FAILED for authcfg (%1): no auth method found"_s.arg( mAuthCfg ) );
182 if ( mconfig.
method() != authMethodKey )
184 QgsDebugError( u
"Loading FAILED for authcfg (%1): auth method and key mismatch"_s.arg( mAuthCfg ) );
188 const int indx = authMethodIndex( authMethodKey );
191 QgsDebugError( u
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'"_s
192 .arg( mAuthCfg, authMethodKey ) );
193 if ( cmbAuthMethods->count() > 0 )
195 cmbAuthMethods->setCurrentIndex( 0 );
196 stkwAuthMethods->setCurrentIndex( 0 );
201 cmbAuthMethods->setCurrentIndex( indx );
202 stkwAuthMethods->setCurrentIndex( indx );
204 QgsAuthMethodEdit *editWidget = currentEditWidget();
207 QgsDebugError( u
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)"_s
208 .arg( mAuthCfg, authMethodKey ) );
215void QgsAuthConfigEdit::resetConfig()
222void QgsAuthConfigEdit::saveConfig()
227 const QString authMethodKey = cmbAuthMethods->currentData().toString();
229 QgsAuthMethodEdit *editWidget = currentEditWidget();
239 QgsDebugError( u
"Save auth config FAILED when loading auth method instance from key (%1)"_s.arg( authMethodKey ) );
243 QgsAuthMethodConfig mconfig;
244 mconfig.
setName( leName->text() );
245 mconfig.
setUri( leResource->text() );
252 QgsDebugError( u
"Save auth config FAILED: config invalid"_s );
256 const QString authCfgId( authCfgEdit->configId() );
257 if ( !mAuthCfg.isEmpty() )
259 if ( authCfgId == mAuthCfg )
261 mconfig.
setId( mAuthCfg );
268 QgsDebugError( u
"Updating auth config FAILED for authcfg: %1"_s.arg( mAuthCfg ) );
273 mconfig.
setId( authCfgId );
281 mAuthCfg = authCfgId;
285 QgsDebugError( u
"Storing new auth config with user-created unique ID FAILED"_s );
289 else if ( mAuthCfg.isEmpty() )
291 if ( authCfgId.isEmpty() )
295 mAuthCfg = mconfig.
id();
305 mconfig.
setId( authCfgId );
308 mAuthCfg = authCfgId;
313 QgsDebugError( u
"Storing new auth config with user-created unique ID FAILED"_s );
321void QgsAuthConfigEdit::btnClear_clicked()
323 QgsAuthMethodEdit *editWidget = currentEditWidget();
335void QgsAuthConfigEdit::clearAll()
339 authCfgEdit->clear();
341 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
343 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->widget( i ) );
353void QgsAuthConfigEdit::validateAuth()
355 bool authok = !leName->text().isEmpty();
357 QgsAuthMethodEdit *editWidget = currentEditWidget();
366 authok = authok && authCfgEdit->validate();
368 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
371void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
377int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
379 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
384 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)