17#include "moc_qgscredentials.cpp"
29 QgsDebugError( QStringLiteral(
"already registered an instance of QgsCredentials" ) );
43bool QgsCredentials::get(
const QString &realm, QString &username, QString &password,
const QString &message,
bool requestCredentials )
46 const QMutexLocker locker( &mCacheMutex );
47 if ( mCredentialCache.contains( realm ) )
49 const QPair<QString, QString> credentials = mCredentialCache.take( realm );
50 username = credentials.first;
51 password = credentials.second;
52 QgsDebugMsgLevel( QStringLiteral(
"retrieved realm:%1 username:%2" ).arg( realm, username ), 2 );
54 if ( !password.isNull() )
59 if ( requestCredentials &&
request( realm, username, password, message ) )
61 QgsDebugMsgLevel( QStringLiteral(
"requested realm:%1 username:%2" ).arg( realm, username ), 2 );
73 const QMutexLocker locker( &mCacheMutex );
74 QgsDebugMsgLevel( QStringLiteral(
"inserting realm:%1 username:%2" ).arg( realm, username ), 2 );
75 mCredentialCache.insert( realm, QPair<QString, QString>( username, password ) );
110 Q_UNUSED( username );
111 Q_UNUSED( password );
118 Q_UNUSED( password );
133 QTextStream in( stdin, QIODevice::ReadOnly );
134 QTextStream out( stdout, QIODevice::WriteOnly );
136 out <<
"credentials for " << realm << Qt::endl;
137 if ( !message.isEmpty() )
138 out <<
"message: " << message << Qt::endl;
151 QTextStream in( stdin, QIODevice::ReadOnly );
152 QTextStream out( stdout, QIODevice::WriteOnly );
154 const QString msg( stored ?
"Master password for authentication configs: " :
"Set master password for authentication configs: " );
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
Default implementation of credentials interface.
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
Interface for requesting credentials in QGIS in GUI independent way.
virtual bool requestMasterPassword(QString &password, bool stored=false)=0
request a master password
void setInstance(QgsCredentials *instance)
register instance
static QgsCredentials * instance()
retrieves instance
void lock()
Lock the instance against access from multiple threads.
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 unlock()
Unlock the instance after being locked.
void put(const QString &realm, const QString &username, const QString &password)
Stores the correct username and password for the specified realm.
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString())=0
request a password
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)