signon 8.54

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

credentialsdb_p.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of signon
4 *
5 * Copyright (C) 2009-2010 Nokia Corporation.
6 * Copyright (C) 2012 Canonical Ltd.
7 *
8 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * version 2.1 as published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25 #ifndef CREDENTIALS_DB_P_H
26 #define CREDENTIALS_DB_P_H
27
28 #include <QObject>
29 #include <QtSql>
30
31 #include "SignOn/abstract-secrets-storage.h"
32 #include "signonidentityinfo.h"
33
34 #define SSO_METADATADB_VERSION 2
35 #define SSO_SECRETSDB_VERSION 1
36
37 class TestDatabase;
38
39 namespace SignonDaemonNS {
40
45 class SecretsCache
46 {
47 friend class ::TestDatabase;
48 public:
49 class AuthCache
50 {
51 friend class SecretsCache;
52
53 private:
54 QString m_username;
55 QString m_password;
56 bool m_storePassword;
57 QHash<quint32,QVariantMap> m_blobData;
58 };
59
60 SecretsCache() {};
61 ~SecretsCache() {};
62
63 bool lookupCredentials(quint32 id,
64 QString &username,
65 QString &password) const;
66 QVariantMap lookupData(quint32 id, quint32 method) const;
67
68 void updateCredentials(quint32 id,
69 const QString &username,
70 const QString &password,
71 bool storePassword);
72 void updateData(quint32 id, quint32 method, const QVariantMap &data);
73
74 void storeToDB(SignOn::AbstractSecretsStorage *secretsStorage) const;
75 void clear();
76
77 private:
78 QHash<quint32, AuthCache> m_cache;
79 };
80
86 class SqlDatabase
87 {
88 friend class ::TestDatabase;
89 public:
94 SqlDatabase(const QString &hostname, const QString &connectionName,
95 int version);
96
100 virtual ~SqlDatabase();
101
105 bool init();
106
107 virtual bool createTables() = 0;
108 virtual bool clear() = 0;
109 virtual bool updateDB(int version);
110
115 bool connect();
119 void disconnect();
120
121 bool startTransaction();
122 bool commit();
123 void rollback();
124
128 bool connected() { return m_database.isOpen(); }
129
134 void setDatabaseName(const QString &databaseName) {
135 m_database.setDatabaseName(databaseName);
136 }
137
142 void setUsername(const QString &username) {
143 m_database.setUserName(username);
144 }
145
150 void setPassword(const QString &password) {
151 m_database.setPassword(password);
152 }
153
157 QString databaseName() const { return m_database.databaseName(); }
158
162 QString username() const { return m_database.userName(); }
163
167 QString password() const { return m_database.password(); }
168
169 QSqlQuery newQuery() const { return QSqlQuery(m_database); }
170
179 QSqlQuery exec(const QString &query);
180
189 QSqlQuery exec(QSqlQuery &query);
190
200 bool transactionalExec(const QStringList &queryList);
201
205 bool hasTables() const {
206 return m_database.tables().count() > 0 ? true : false;
207 }
208
212 static QStringList supportedDrivers() { return QSqlDatabase::drivers(); }
213
218 SignOn::CredentialsDBError lastError() const;
219 bool errorOccurred() const { return lastError().isValid(); };
220 void clearError() { m_lastError.clear(); }
221
227 static QString errorInfo(const QSqlError &error);
228
229 QString connectionName() const { return m_database.connectionName(); }
230
231 protected:
232 QStringList queryList(const QString &query_str);
233 QStringList queryList(QSqlQuery &query);
234 void setLastError(const QSqlError &sqlError);
235
236 private:
237 SignOn::CredentialsDBError m_lastError;
238
239 protected:
240 int m_version;
241 QSqlDatabase m_database;
242
243 friend class CredentialsDB;
244 };
245
246 class MetaDataDB: public SqlDatabase
247 {
248 friend class ::TestDatabase;
249 public:
250 MetaDataDB(const QString &name):
251 SqlDatabase(name, QLatin1String("SSO-metadata"),
252 SSO_METADATADB_VERSION) {}
253
254 bool createTables();
255 bool updateDB(int version);
256
257 QStringList methods(const quint32 id,
258 const QString &securityToken = QString());
259 quint32 insertMethod(const QString &method, bool *ok = 0);
260 quint32 methodId(const QString &method);
261 SignonIdentityInfo identity(const quint32 id);
262 QList<SignonIdentityInfo> identities(const QMap<QString, QString> &filter);
263
264 quint32 updateIdentity(const SignonIdentityInfo &info);
265 bool removeIdentity(const quint32 id);
266
267 bool clear();
268
269 QStringList accessControlList(const quint32 identityId);
270 QStringList ownerList(const quint32 identityId);
271
272 bool addReference(const quint32 id,
273 const QString &token,
274 const QString &reference);
275 bool removeReference(const quint32 id,
276 const QString &token,
277 const QString &reference = QString());
278 QStringList references(const quint32 id, const QString &token = QString());
279
280 private:
281 bool insertMethods(QMap<QString, QStringList> methods);
282 quint32 updateCredentials(const SignonIdentityInfo &info);
283 bool updateRealms(quint32 id, const QStringList &realms, bool isNew);
284 QStringList tableUpdates2();
285 };
286
287 } // namespace SignonDaemonNS
288
289 #endif // CREDENTIALSDB_P_H
SignonDaemonNS::SqlDatabase::startTransaction
bool startTransaction()
Definition: credentialsdb.cpp:193
SignonDaemonNS::SqlDatabase::connected
bool connected()
Definition: credentialsdb_p.h:128
SignonDaemonNS::SecretsCache::~SecretsCache
~SecretsCache()
Definition: credentialsdb_p.h:61
SignonDaemonNS::SqlDatabase::exec
QSqlQuery exec(const QString &query)
Executes a specific database query.
Definition: credentialsdb.cpp:209
SignonDaemonNS::SqlDatabase::password
QString password() const
Definition: credentialsdb_p.h:167
SignonDaemonNS::SqlDatabase::supportedDrivers
static QStringList supportedDrivers()
Definition: credentialsdb_p.h:212
SignonDaemonNS::MetaDataDB::createTables
bool createTables()
Definition: credentialsdb.cpp:376
SignonDaemonNS::SecretsCache::lookupCredentials
bool lookupCredentials(quint32 id, QString &username, QString &password) const
Definition: credentialsdb.cpp:44
SignonDaemonNS::MetaDataDB::identities
QList< SignonIdentityInfo > identities(const QMap< QString, QString > &filter)
Definition: credentialsdb.cpp:789
SignonDaemonNS::SqlDatabase::~SqlDatabase
virtual ~SqlDatabase()
Destroys the SqlDatabase object, closing the database connection.
Definition: credentialsdb.cpp:138
SignonDaemonNS::MetaDataDB::insertMethod
quint32 insertMethod(const QString &method, bool *ok=0)
Definition: credentialsdb.cpp:1163
SSO_METADATADB_VERSION
#define SSO_METADATADB_VERSION
Definition: credentialsdb_p.h:34
SignonDaemonNS::MetaDataDB::updateDB
bool updateDB(int version)
Definition: credentialsdb.cpp:626
SignonDaemonNS::MetaDataDB
Definition: credentialsdb_p.h:246
SignonDaemonNS::SqlDatabase::clearError
void clearError()
Definition: credentialsdb_p.h:220
SignonDaemonNS::SecretsCache
Caches credentials or BLOB authentication data.
Definition: credentialsdb_p.h:45
SignonDaemonNS::MetaDataDB::ownerList
QStringList ownerList(const quint32 identityId)
Definition: credentialsdb.cpp:1015
SignonDaemonNS::MetaDataDB::removeIdentity
bool removeIdentity(const quint32 id)
Definition: credentialsdb.cpp:974
SignonDaemonNS::MetaDataDB::references
QStringList references(const quint32 id, const QString &token=QString())
Definition: credentialsdb.cpp:1120
SignonDaemonNS::MetaDataDB::addReference
bool addReference(const quint32 id, const QString &token, const QString &reference)
Definition: credentialsdb.cpp:1023
signonidentityinfo.h
SignonDaemonNS::SecretsCache::storeToDB
void storeToDB(SignOn::AbstractSecretsStorage *secretsStorage) const
Definition: credentialsdb.cpp:86
SignonDaemonNS::SqlDatabase::commit
bool commit()
Definition: credentialsdb.cpp:198
SignonDaemonNS::SqlDatabase::lastError
SignOn::CredentialsDBError lastError() const
Definition: credentialsdb.cpp:270
SignonDaemonNS::MetaDataDB::updateIdentity
quint32 updateIdentity(const SignonIdentityInfo &info)
Definition: credentialsdb.cpp:819
SignonDaemonNS::SqlDatabase::setDatabaseName
void setDatabaseName(const QString &databaseName)
Sets the database name.
Definition: credentialsdb_p.h:134
SignonDaemonNS::SqlDatabase::SqlDatabase
SqlDatabase(const QString &hostname, const QString &connectionName, int version)
Constructs a SqlDatabase object using the given hostname.
Definition: credentialsdb.cpp:124
SignonDaemonNS::SecretsCache::clear
void clear()
Definition: credentialsdb.cpp:119
SignonDaemonNS::SqlDatabase::setPassword
void setPassword(const QString &password)
Sets the password for the database connection.
Definition: credentialsdb_p.h:150
SignonDaemonNS::SqlDatabase::init
bool init()
Connects to the DB and if necessary creates the tables.
Definition: credentialsdb.cpp:144
SignonDaemonNS::MetaDataDB::removeReference
bool removeReference(const quint32 id, const QString &token, const QString &reference=QString())
Definition: credentialsdb.cpp:1070
SignonDaemonNS::SqlDatabase::connect
bool connect()
Creates the database connection.
Definition: credentialsdb.cpp:178
SignonDaemonNS::SqlDatabase::errorOccurred
bool errorOccurred() const
Definition: credentialsdb_p.h:219
SignonDaemonNS::SqlDatabase::databaseName
QString databaseName() const
Definition: credentialsdb_p.h:157
SignonDaemonNS::SqlDatabase::m_database
QSqlDatabase m_database
Definition: credentialsdb_p.h:241
SignonDaemonNS::SecretsCache::lookupData
QVariantMap lookupData(quint32 id, quint32 method) const
Definition: credentialsdb.cpp:58
SignonDaemonNS::MetaDataDB::accessControlList
QStringList accessControlList(const quint32 identityId)
Definition: credentialsdb.cpp:1007
SignonDaemonNS::SqlDatabase::m_version
int m_version
Definition: credentialsdb_p.h:240
SignonDaemonNS::SqlDatabase::transactionalExec
bool transactionalExec(const QStringList &queryList)
Executes a specific database set of queryes (INSERTs, UPDATEs, DELETEs) in a transaction context (No ...
Definition: credentialsdb.cpp:240
SignonDaemonNS::SqlDatabase::rollback
void rollback()
Definition: credentialsdb.cpp:203
SignonDaemonNS::SqlDatabase::disconnect
void disconnect()
Destroys the database connection.
Definition: credentialsdb.cpp:188
SignonDaemonNS::SqlDatabase::clear
virtual bool clear()=0
SignonDaemonNS::SignonIdentityInfo
Daemon side representation of identity information.
Definition: signonidentityinfo.h:43
SignonDaemonNS::CredentialsDB
Manages the credentials I/O.
Definition: credentialsdb.h:66
SignonDaemonNS::SqlDatabase::newQuery
QSqlQuery newQuery() const
Definition: credentialsdb_p.h:169
SignonDaemonNS::SecretsCache::updateCredentials
void updateCredentials(quint32 id, const QString &username, const QString &password, bool storePassword)
Definition: credentialsdb.cpp:63
SignonDaemonNS::MetaDataDB::MetaDataDB
MetaDataDB(const QString &name)
Definition: credentialsdb_p.h:250
SignonDaemonNS::SqlDatabase::connectionName
QString connectionName() const
Definition: credentialsdb_p.h:229
SignonDaemonNS::SqlDatabase::updateDB
virtual bool updateDB(int version)
Definition: credentialsdb.cpp:171
SignonDaemonNS::SqlDatabase::setLastError
void setLastError(const QSqlError &sqlError)
Definition: credentialsdb.cpp:275
SignonDaemonNS::SecretsCache::SecretsCache
SecretsCache()
Definition: credentialsdb_p.h:60
SignonDaemonNS::SqlDatabase::hasTables
bool hasTables() const
Definition: credentialsdb_p.h:205
SignonDaemonNS::MetaDataDB::identity
SignonIdentityInfo identity(const quint32 id)
Definition: credentialsdb.cpp:716
SignonDaemonNS::SqlDatabase::username
QString username() const
Definition: credentialsdb_p.h:162
SignonDaemonNS::SqlDatabase::setUsername
void setUsername(const QString &username)
Sets the username for the database connection.
Definition: credentialsdb_p.h:142
SignonDaemonNS::MetaDataDB::methodId
quint32 methodId(const QString &method)
Definition: credentialsdb.cpp:700
SignonDaemonNS::MetaDataDB::clear
bool clear()
Definition: credentialsdb.cpp:991
SignonDaemonNS::MetaDataDB::methods
QStringList methods(const quint32 id, const QString &securityToken=QString())
Definition: credentialsdb.cpp:677
SignonDaemonNS::SqlDatabase::errorInfo
static QString errorInfo(const QSqlError &error)
Serializes a SQL error into a string.
Definition: credentialsdb.cpp:289
SignonDaemonNS::SecretsCache::AuthCache
Definition: credentialsdb_p.h:49
SignonDaemonNS::SqlDatabase
Will be used manage the SQL database interaction.
Definition: credentialsdb_p.h:86
SignonDaemonNS::SqlDatabase::createTables
virtual bool createTables()=0
QMap
Definition: backupifadaptor.h:19
SignonDaemonNS::SecretsCache::updateData
void updateData(quint32 id, quint32 method, const QVariantMap &data)
Definition: credentialsdb.cpp:76
QList
Definition: backupifadaptor.h:18
SignonDaemonNS::SqlDatabase::queryList
QStringList queryList(const QString &query_str)
Definition: credentialsdb.cpp:317