QGIS API Documentation
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 
101 class CORE_EXPORT QgsCredentialsNone : public QObject, public QgsCredentials
102 {
103  Q_OBJECT
104 
105  public:
107 
108  signals:
110  void destroyed();
111 
112  protected:
113  virtual bool request( const QString& realm, QString &username, QString &password, const QString& message = QString::null ) override;
114  virtual bool requestMasterPassword( QString &password, bool stored = false ) override;
115 };
116 
117 
125 class CORE_EXPORT QgsCredentialsConsole : public QObject, public QgsCredentials
126 {
127  Q_OBJECT
128 
129  public:
131 
132  signals:
134  void destroyed();
135 
136  protected:
137  virtual bool request( const QString& realm, QString &username, QString &password, const QString& message = QString::null ) override;
138  virtual bool requestMasterPassword( QString &password, bool stored = false ) override;
139 };
140 
141 #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.
void destroyed(QObject *obj)
QMutex * mutex()
Return pointer to mutex.