19 #include <QTextStream> 27 QgsDebugMsg( QStringLiteral(
"already registered an instance of QgsCredentials" ) );
41 bool QgsCredentials::get(
const QString &realm, QString &username, QString &password,
const QString &message )
43 QMutexLocker locker( &mMutex );
44 if ( mCredentialCache.contains( realm ) )
46 QPair<QString, QString> credentials = mCredentialCache.take( realm );
48 username = credentials.first;
49 password = credentials.second;
50 #if 0 // don't leak credentials on log 51 QgsDebugMsg( QStringLiteral(
"retrieved realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
54 if ( !password.isNull() )
59 if (
request( realm, username, password, message ) )
61 #if 0 // don't leak credentials on log 62 QgsDebugMsg( QStringLiteral(
"requested realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
75 #if 0 // don't leak credentials on log 76 QgsDebugMsg( QStringLiteral(
"inserting realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
78 QMutexLocker locker( &mMutex );
79 mCredentialCache.insert( realm, QPair<QString, QString>( username, password ) );
86 QgsDebugMsg( QStringLiteral(
"requested master password" ) );
114 Q_UNUSED( username );
115 Q_UNUSED( password );
122 Q_UNUSED( password );
137 QTextStream in( stdin, QIODevice::ReadOnly );
138 QTextStream out( stdout, QIODevice::WriteOnly );
140 out <<
"credentials for " << realm << endl;
141 if ( !message.isEmpty() )
142 out <<
"message: " << message << endl;
155 QTextStream in( stdin, QIODevice::ReadOnly );
156 QTextStream out( stdout, QIODevice::WriteOnly );
158 QString msg( stored ?
"Master password for authentication configs: " :
"Set master password for authentication configs: " );
bool getMasterPassword(QString &password, bool stored=false)
Interface for requesting credentials in QGIS in GUI independent way.
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
void setInstance(QgsCredentials *instance)
register instance
virtual bool requestMasterPassword(QString &password, bool stored=false)=0
request a master password
static QgsCredentials * instance()
retrieves instance
Default implementation of credentials interface.
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString())=0
request a password
Q_DECL_DEPRECATED void lock()
Lock the instance against access from multiple threads.
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
#define QgsDebugMsgLevel(str, level)
bool get(const QString &realm, QString &username, QString &password, const QString &message=QString())
Requests credentials for the specified realm.
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
Q_DECL_DEPRECATED 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.
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password