QGIS API Documentation  2.99.0-Master (19b062c)
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 
41 class CORE_EXPORT QgsCredentials
42 {
43  public:
44 
48  virtual ~QgsCredentials() = default;
49 
50  bool get( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() );
51  void put( const QString &realm, const QString &username, const QString &password );
52 
53  bool getMasterPassword( QString &password SIP_INOUT, bool stored = false );
54 
56  static QgsCredentials *instance();
57 
64  void lock();
65 
70  void unlock();
71 
76  QMutex *mutex() { return &mMutex; }
77 
78  protected:
79 
83  QgsCredentials() = default;
84 
86  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) = 0;
87 
89  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) = 0;
90 
92  void setInstance( QgsCredentials *instance );
93 
94  private:
95  Q_DISABLE_COPY( QgsCredentials )
96 
97 #ifdef SIP_RUN
98  QgsCredentials( const QgsCredentials & );
99 #endif
100 
102  QMap< QString, QPair<QString, QString> > mCredentialCache;
103 
105  static QgsCredentials *sInstance;
106 
107  QMutex mMutex;
108 };
109 
110 
117 class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
118 {
119  Q_OBJECT
120 
121  public:
123 
124  signals:
126  void destroyed();
127 
128  protected:
129  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
130  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
131 };
132 
133 
142 class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
143 {
144  Q_OBJECT
145 
146  public:
148 
149  signals:
151  void destroyed();
152 
153  protected:
154  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
155  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
156 };
157 
158 #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:64
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.