QGIS API Documentation  2.12.0-Lyon
qgscredentials.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscredentials.h - interface for requesting credentials
3  ----------------------
4  begin : Feburary 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 
37 class CORE_EXPORT QgsCredentials
38 {
39  public:
41  virtual ~QgsCredentials();
42 
43  bool get( const QString& realm, QString &username, QString &password, const QString& message = QString::null );
44  void put( const QString& realm, const QString& username, const QString& password );
45 
46  bool getMasterPassword( QString &password, bool stored = false );
47 
49  static QgsCredentials *instance();
50 
57  void lock();
58 
63  void unlock();
64 
69  QMutex *mutex() { return &mMutex; }
70 
71  protected:
73 
75  virtual bool request( const QString& realm, QString &username, QString &password, const QString& message = QString::null ) = 0;
76 
78  virtual bool requestMasterPassword( QString &password, bool stored = false ) = 0;
79 
81  void setInstance( QgsCredentials *theInstance );
82 
83  private:
84  Q_DISABLE_COPY( QgsCredentials )
85 
86 
87  QMap< QString, QPair<QString, QString> > mCredentialCache;
88 
90  static QgsCredentials *smInstance;
91 
92  QMutex mMutex;
93 };
94 
95 
103 class CORE_EXPORT QgsCredentialsConsole : 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 #endif
Interface for requesting credentials in QGIS in GUI independent way.
Default implementation of credentials interface.
QMutex * mutex()
Return pointer to mutex.