QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsCredentials Class Referenceabstract

Interface for requesting credentials in QGIS in GUI independent way. More...

#include <qgscredentials.h>

Inheritance diagram for QgsCredentials:
Inheritance graph
[legend]

Public Member Functions

virtual ~QgsCredentials ()=default
 
bool get (const QString &realm, QString &username, QString &password, const QString &message=QString(), bool requestCredentials=true)
 Requests credentials for the specified realm.
 
bool getMasterPassword (QString &password, bool stored=false)
 
void lock ()
 Lock the instance against access from multiple threads.
 
QMutex * mutex ()
 Returns pointer to mutex.
 
void put (const QString &realm, const QString &username, const QString &password)
 Stores the correct username and password for the specified realm.
 
void unlock ()
 Unlock the instance after being locked.
 

Static Public Member Functions

static QgsCredentialsinstance ()
 retrieves instance
 

Protected Member Functions

 QgsCredentials ()=default
 
virtual bool request (const QString &realm, QString &username, QString &password, const QString &message=QString())=0
 request a password
 
virtual bool requestMasterPassword (QString &password, bool stored=false)=0
 request a master password
 
void setInstance (QgsCredentials *instance)
 register instance
 

Detailed Description

Interface for requesting credentials in QGIS in GUI independent way.

This class provides abstraction of a dialog for requesting credentials to the user. By default QgsCredentials will be used if not overridden with other credential creator function.

QGIS application uses QgsCredentialDialog class for displaying a dialog to the user.

Caller can use the mutex to synchronize authentications to avoid requesting credentials for the same resource several times.

Object deletes itself when it's not needed anymore. Children should use signal destroyed() to be notified of the deletion

Definition at line 45 of file qgscredentials.h.

Constructor & Destructor Documentation

◆ ~QgsCredentials()

virtual QgsCredentials::~QgsCredentials ( )
virtualdefault

◆ QgsCredentials()

QgsCredentials::QgsCredentials ( )
protecteddefault

Member Function Documentation

◆ get()

bool QgsCredentials::get ( const QString &  realm,
QString &  username,
QString &  password,
const QString &  message = QString(),
bool  requestCredentials = true 
)

Requests credentials for the specified realm.

If existing credentials exist for the given realm, these will be returned. Otherwise the credential handler will prompt for the correct username and password if requestCredentials is set to True.

The retrieved or user-entered details will be stored in username and password.

Optionally, a specific message can be used to advise users of the context for the credentials request.

Note
This method will not automatically store the newly obtained credentials. Callers must manually call put() after verifying that the obtained credentials are correct.
See also
put()

Definition at line 42 of file qgscredentials.cpp.

◆ getMasterPassword()

bool QgsCredentials::getMasterPassword ( QString &  password,
bool  stored = false 
)

Definition at line 77 of file qgscredentials.cpp.

◆ instance()

QgsCredentials * QgsCredentials::instance ( )
static

retrieves instance

Definition at line 34 of file qgscredentials.cpp.

◆ lock()

void QgsCredentials::lock ( )

Lock the instance against access from multiple threads.

This does not really lock access to get/put methods, it will just prevent other threads to lock the instance and continue the execution. When the class is used from non-GUI threads, they should call lock() before the get/put calls to avoid race conditions.

Definition at line 87 of file qgscredentials.cpp.

◆ mutex()

QMutex * QgsCredentials::mutex ( )
inline

Returns pointer to mutex.

Definition at line 99 of file qgscredentials.h.

◆ put()

void QgsCredentials::put ( const QString &  realm,
const QString &  username,
const QString &  password 
)

Stores the correct username and password for the specified realm.

These values will be used for all future calls to get() for the same realm, without requesting users to re-enter them. It is the caller's responsibility to ensure that only valid username and password combinations are used with this method.

See also
get()

Definition at line 70 of file qgscredentials.cpp.

◆ request()

virtual bool QgsCredentials::request ( const QString &  realm,
QString &  username,
QString &  password,
const QString &  message = QString() 
)
protectedpure virtual

request a password

Implemented in QgsCredentialsNone, QgsCredentialsConsole, and QgsCredentialDialog.

◆ requestMasterPassword()

virtual bool QgsCredentials::requestMasterPassword ( QString &  password,
bool  stored = false 
)
protectedpure virtual

request a master password

Implemented in QgsCredentialsNone, QgsCredentialsConsole, and QgsCredentialDialog.

◆ setInstance()

void QgsCredentials::setInstance ( QgsCredentials instance)
protected

register instance

Definition at line 24 of file qgscredentials.cpp.

◆ unlock()

void QgsCredentials::unlock ( )

Unlock the instance after being locked.

Definition at line 92 of file qgscredentials.cpp.


The documentation for this class was generated from the following files: