signon  8.42
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 #include "signonidentityinfo.h"
40 
41 #define SSO_MAX_TOKEN_STORAGE (4*1024) // 4 kB for token store/identity/method
42 
43 class TestDatabase;
44 
45 namespace SignonDaemonNS {
46 
52  Validated = 0x0001,
53  RememberPassword = 0x0002,
54  UserNameIsSecret = 0x0004,
55 };
56 
57 class MetaDataDB;
58 class SecretsCache;
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);
110  QList<SignonIdentityInfo> credentials(const QMap<QString, QString> &filter);
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 private:
138  SignOn::AbstractSecretsStorage *secretsStorage;
139  SecretsCache *m_secretsCache;
140  MetaDataDB *metaDataDB;
141  SignOn::CredentialsDBError _lastError;
142  SignOn::CredentialsDBError noSecretsDB;
143 };
144 
145 } // namespace SignonDaemonNS
146 
147 #endif // CREDENTIALSDB_H