QGIS API Documentation  2.99.0-Master (314842d)
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 <QString>
21 #include <QObject>
22 #include <QPair>
23 #include <QMap>
24 #include <QMutex>
25 
26 #include "qgis_core.h"
27 
39 class CORE_EXPORT QgsCredentials
40 {
41  public:
42 
43  virtual ~QgsCredentials() = default;
44 
45  bool get( const QString &realm, QString &username, QString &password, const QString &message = QString::null );
46  void put( const QString &realm, const QString &username, const QString &password );
47 
48  bool getMasterPassword( QString &password, bool stored = false );
49 
51  static QgsCredentials *instance();
52 
59  void lock();
60 
65  void unlock();
66 
71  QMutex *mutex() { return &mMutex; }
72 
73  protected:
75 
77  virtual bool request( const QString &realm, QString &username, QString &password, const QString &message = QString::null ) = 0;
78 
80  virtual bool requestMasterPassword( QString &password, bool stored = false ) = 0;
81 
83  void setInstance( QgsCredentials *instance );
84 
85  private:
86  Q_DISABLE_COPY( QgsCredentials )
87 
88 
89  QMap< QString, QPair<QString, QString> > mCredentialCache;
90 
92  static QgsCredentials *sInstance;
93 
94  QMutex mMutex;
95 };
96 
97 
103 class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
104 {
105  Q_OBJECT
106 
107  public:
109 
110  signals:
112  void destroyed();
113 
114  protected:
115  virtual bool request( const QString &realm, QString &username, QString &password, const QString &message = QString::null ) override;
116  virtual bool requestMasterPassword( QString &password, bool stored = false ) override;
117 };
118 
119 
127 class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
128 {
129  Q_OBJECT
130 
131  public:
133 
134  signals:
136  void destroyed();
137 
138  protected:
139  virtual bool request( const QString &realm, QString &username, QString &password, const QString &message = QString::null ) override;
140  virtual bool requestMasterPassword( QString &password, bool stored = false ) override;
141 };
142 
143 #endif
Interface for requesting credentials in QGIS in GUI independent way.
virtual bool requestMasterPassword(QString &password, bool stored=false)=0
request a master password
Default implementation of credentials interface.
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString::null)=0
request a password
Implementation of credentials interface for the console.
QMutex * mutex()
Return pointer to mutex.