QGIS API Documentation  3.6.0-Noosa (5873452)
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_sip.h"
28 
41 class CORE_EXPORT QgsCredentials
42 {
43  public:
44 
48  virtual ~QgsCredentials() = default;
49 
65  bool get( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() );
66 
76  void put( const QString &realm, const QString &username, const QString &password );
77 
78  bool getMasterPassword( QString &password SIP_INOUT, bool stored = false );
79 
81  static QgsCredentials *instance();
82 
90  Q_DECL_DEPRECATED void lock() SIP_DEPRECATED;
91 
96  Q_DECL_DEPRECATED void unlock() SIP_DEPRECATED;
97 
102  Q_DECL_DEPRECATED QMutex *mutex() SIP_DEPRECATED
103  {
104  return &mMutex;
105  }
106 
107  protected:
108 
112  QgsCredentials() = default;
113 
115  virtual bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) = 0;
116 
118  virtual bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) = 0;
119 
121  void setInstance( QgsCredentials *instance );
122 
123  private:
124  Q_DISABLE_COPY( QgsCredentials )
125 
126 #ifdef SIP_RUN
127  QgsCredentials( const QgsCredentials & );
128 #endif
129 
131  QMap< QString, QPair<QString, QString> > mCredentialCache;
132 
134  static QgsCredentials *sInstance;
135 
136  QMutex mMutex;
137 };
138 
139 
146 class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
147 {
148  Q_OBJECT
149 
150  public:
152 
153  signals:
155  void destroyed();
156 
157  protected:
158  bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
159  bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
160 };
161 
162 
171 class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
172 {
173  Q_OBJECT
174 
175  public:
177 
178  signals:
180  void destroyed();
181 
182  protected:
183  bool request( const QString &realm, QString &username SIP_INOUT, QString &password SIP_INOUT, const QString &message = QString() ) override;
184  bool requestMasterPassword( QString &password SIP_INOUT, bool stored = false ) override;
185 };
186 
187 #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
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
Implementation of credentials interface for the console.
Q_DECL_DEPRECATED QMutex * mutex()
Returns pointer to mutex.