QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgscredentials.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscredentials.h - interface for requesting credentials
3 ----------------------
4 begin : February 2010
5 copyright : (C) 2010 by Juergen E. Fischer
6 email : jef at norbit dot de
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
17#ifndef QGSCREDENTIALS_H
18#define QGSCREDENTIALS_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QMap>
24#include <QMutex>
25#include <QObject>
26#include <QPair>
27#include <QString>
28
45class CORE_EXPORT QgsCredentials
46{
47 public:
48
49 virtual ~QgsCredentials() = default;
50
66 bool get( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString(), bool requestCredentials = true );
67
77 void put( const QString &realm, const QString &username, const QString &password );
78
79 bool getMasterPassword( QString &password SIP_INOUT, bool stored = false );
80
82 static QgsCredentials *instance();
83
89 void lock();
90
94 void unlock();
95
99 QMutex *mutex() { return &mAuthMutex; }
100
101 protected:
102
103 QgsCredentials() = default;
104
106 virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) = 0;
107
109 virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) = 0;
110
113
114 private:
115 Q_DISABLE_COPY( QgsCredentials )
116
117#ifdef SIP_RUN
119#endif
120
122 QMap< QString, QPair<QString, QString> > mCredentialCache;
123
125 static QgsCredentials *sInstance;
126
128 QMutex mAuthMutex;
129
131 QMutex mCacheMutex;
132};
133
134
141class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
142{
143 Q_OBJECT
144
145 public:
147
148 signals:
150 void destroyed();
151
152 protected:
153 bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
154 bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
155};
156
157
166class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
167{
168 Q_OBJECT
169
170 public:
172
173 signals:
175 void destroyed();
176
177 protected:
178 bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
179 bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
180};
181
182#endif
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
void destroyed()
signals that object will be destroyed and shouldn't be used anymore
bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
void destroyed()
signals that object will be destroyed and shouldn't be used anymore
bool request(const QString &realm, QString &username, QString &password, const QString &message=QString()) override
request a password
QMutex * mutex()
Returns pointer to mutex.
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.
QgsCredentials()=default
bool getMasterPassword(QString &password, bool stored=false)
virtual ~QgsCredentials()=default
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 SIP_INOUT
Definition qgis_sip.h:79