19 #include <QTextStream> 27 QgsDebugMsg(
"already registered an instance of QgsCredentials" );
41 bool QgsCredentials::get(
const QString &realm, QString &username, QString &password,
const QString &message )
43 if ( mCredentialCache.contains( realm ) )
45 QPair<QString, QString> credentials = mCredentialCache.take( realm );
46 username = credentials.first;
47 password = credentials.second;
48 QgsDebugMsg( QString(
"retrieved realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
50 if ( !password.isNull() )
54 if (
request( realm, username, password, message ) )
56 QgsDebugMsg( QString(
"requested realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
61 QgsDebugMsg( QString(
"unset realm:%1" ).arg( realm ) );
68 QgsDebugMsg( QString(
"inserting realm:%1 username:%2 password:%3" ).arg( realm, username, password ) );
69 mCredentialCache.insert( realm, QPair<QString, QString>( username, password ) );
104 Q_UNUSED( username );
105 Q_UNUSED( password );
112 Q_UNUSED( password );
127 QTextStream in( stdin, QIODevice::ReadOnly );
128 QTextStream out( stdout, QIODevice::WriteOnly );
130 out <<
"credentials for " << realm << endl;
131 if ( !message.isEmpty() )
132 out <<
"message: " << message << endl;
145 QTextStream in( stdin, QIODevice::ReadOnly );
146 QTextStream out( stdout, QIODevice::WriteOnly );
148 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
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
bool get(const QString &realm, QString &username, QString &password, const QString &message=QString())
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
void unlock()
Unlock the instance after being locked.
void put(const QString &realm, const QString &username, const QString &password)
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password