signon  8.58
credentialsdb.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: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
9  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * version 2.1 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  */
25 
32 #ifndef CREDENTIALS_DB_H
33 #define CREDENTIALS_DB_H
34 
35 #include <QObject>
36 #include <QtSql>
37 
38 #include "SignOn/abstract-secrets-storage.h"
39 
40 #define SSO_MAX_TOKEN_STORAGE (4*1024) // 4 kB for token store/identity/method
41 
42 class TestDatabase;
43 
44 namespace SignonDaemonNS {
45 
51  Validated = 0x0001,
52  RememberPassword = 0x0002,
53  UserNameIsSecret = 0x0004,
54 };
55 
56 class MetaDataDB;
57 class SecretsCache;
58 class SignonIdentityInfo;
59 
66 class CredentialsDB: public QObject
67 {
68  Q_OBJECT
69  Q_DISABLE_COPY(CredentialsDB)
70 
71  friend class ::TestDatabase;
72 
73  class ErrorMonitor
74  {
75  public:
76  /* The constructor clears the errors in CredentialsDB, MetaDataDB and
77  * SecretsDB. */
79  /* The destructor collects the errors and sets
80  * CredentialsDB::_lastError to the appropriate value. */
81  ~ErrorMonitor();
82  private:
83  CredentialsDB *_db;
84  };
85  friend class ErrorMonitor;
86 
87 public:
88  CredentialsDB(const QString &metaDataDbName,
89  SignOn::AbstractSecretsStorage *secretsStorage);
91 
92  bool init();
98  bool openSecretsDB(const QString &secretsDbName);
99  bool isSecretsDBOpen();
100  void closeSecretsDB();
101 
102  SignOn::CredentialsDBError lastError() const;
103  bool errorOccurred() const { return lastError().isValid(); };
104 
105  QStringList methods(const quint32 id,
106  const QString &securityToken = QString());
107  bool checkPassword(const quint32 id,
108  const QString &username, const QString &password);
109  SignonIdentityInfo credentials(const quint32 id, bool queryPassword = true);
111 
112  quint32 insertCredentials(const SignonIdentityInfo &info);
113  quint32 updateCredentials(const SignonIdentityInfo &info);
114  bool removeCredentials(const quint32 id);
115 
116  bool clear();
117 
118  QStringList accessControlList(const quint32 identityId);
119  QStringList ownerList(const quint32 identityId);
120  QString credentialsOwnerSecurityToken(const quint32 identityId);
121 
122  QVariantMap loadData(const quint32 id, const QString &method);
123  bool storeData(const quint32 id,
124  const QString &method,
125  const QVariantMap &data);
126  bool removeData(const quint32 id, const QString &method = QString());
127 
128  bool addReference(const quint32 id,
129  const QString &token,
130  const QString &reference);
131  bool removeReference(const quint32 id,
132  const QString &token,
133  const QString &reference = QString());
134  QStringList references(const quint32 id,
135  const QString &token = QString());
136 
137 Q_SIGNALS:
138  void credentialsUpdated(quint32 id);
139 
140 private:
141  SignOn::AbstractSecretsStorage *secretsStorage;
142  SecretsCache *m_secretsCache;
143  MetaDataDB *metaDataDB;
144  SignOn::CredentialsDBError _lastError;
145  SignOn::CredentialsDBError noSecretsDB;
146 };
147 
148 } // namespace SignonDaemonNS
149 
150 #endif // CREDENTIALSDB_H
bool removeData(const quint32 id, const QString &method=QString())
QStringList references(const quint32 id, const QString &token=QString())
QStringList accessControlList(const quint32 identityId)
quint32 insertCredentials(const SignonIdentityInfo &info)
quint32 updateCredentials(const SignonIdentityInfo &info)
Caches credentials or BLOB authentication data.
SignOn::CredentialsDBError lastError() const
void credentialsUpdated(quint32 id)
bool storeData(const quint32 id, const QString &method, const QVariantMap &data)
bool addReference(const quint32 id, const QString &token, const QString &reference)
bool removeCredentials(const quint32 id)
QVariantMap loadData(const quint32 id, const QString &method)
QString credentialsOwnerSecurityToken(const quint32 identityId)
SignonIdentityInfo credentials(const quint32 id, bool queryPassword=true)
IdentityFlags
Flags to be stored into database.
Definition: credentialsdb.h:50
bool removeReference(const quint32 id, const QString &token, const QString &reference=QString())
bool openSecretsDB(const QString &secretsDbName)
This method will open the DB file containing the user secrets.
CredentialsDB(const QString &metaDataDbName, SignOn::AbstractSecretsStorage *secretsStorage)
QStringList methods(const quint32 id, const QString &securityToken=QString())
Daemon side representation of identity information.
bool checkPassword(const quint32 id, const QString &username, const QString &password)
Manages the credentials I/O.
Definition: credentialsdb.h:66
QStringList ownerList(const quint32 identityId)