QGIS API Documentation  2.99.0-Master (69af2f5)
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 <QMap>
21 #include <QMutex>
22 #include <QObject>
23 #include <QPair>
24 #include <QString>
25 
26 #include "qgis_core.h"
27 #include "qgis.h"
28 
40 class CORE_EXPORT QgsCredentials
41 {
42  public:
43 
44  virtual ~QgsCredentials() = default;
45 
46  bool get( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() );
47  void put( const QString &realm, const QString &username, const QString &password );
48 
49  bool getMasterPassword( QString &password SIP_INOUT, bool stored = false );
50 
52  static QgsCredentials *instance();
53 
60  void lock();
61 
66  void unlock();
67 
72  QMutex *mutex() { return &mMutex; }
73 
74  protected:
76 
78  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) = 0;
79 
81  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) = 0;
82 
84  void setInstance( QgsCredentials *instance );
85 
86  private:
87  Q_DISABLE_COPY( QgsCredentials )
88 
89 #ifdef SIP_RUN
90  QgsCredentials( const QgsCredentials & );
91 #endif
92 
94  QMap< QString, QPair<QString, QString> > mCredentialCache;
95 
97  static QgsCredentials *sInstance;
98 
99  QMutex mMutex;
100 };
101 
102 
108 class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
109 {
110  Q_OBJECT
111 
112  public:
114 
115  signals:
117  void destroyed();
118 
119  protected:
120  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
121  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
122 };
123 
124 
132 class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
133 {
134  Q_OBJECT
135 
136  public:
138 
139  signals:
141  void destroyed();
142 
143  protected:
144  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
145  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
146 };
147 
148 #endif
Interface for requesting credentials in QGIS in GUI independent way.
virtual bool requestMasterPassword(QString &password, bool stored=false)=0
request a master password
#define SIP_INOUT
Definition: qgis_sip.h:52
Default implementation of credentials interface.
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString())=0
request a password
Implementation of credentials interface for the console.
QMutex * mutex()
Return pointer to mutex.