signon  8.58
credentialsdb.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * This file is part of signon
00004  *
00005  * Copyright (C) 2009-2010 Nokia Corporation.
00006  * Copyright (C) 2012 Canonical Ltd.
00007  *
00008  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00009  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public License
00013  * version 2.1 as published by the Free Software Foundation.
00014  *
00015  * This library is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00023  * 02110-1301 USA
00024  */
00025 
00032 #ifndef CREDENTIALS_DB_H
00033 #define CREDENTIALS_DB_H
00034 
00035 #include <QObject>
00036 #include <QtSql>
00037 
00038 #include "SignOn/abstract-secrets-storage.h"
00039 
00040 #define SSO_MAX_TOKEN_STORAGE (4*1024) // 4 kB for token store/identity/method
00041 
00042 class TestDatabase;
00043 
00044 namespace SignonDaemonNS {
00045 
00050 enum IdentityFlags {
00051     Validated = 0x0001,
00052     RememberPassword = 0x0002,
00053     UserNameIsSecret = 0x0004,
00054 };
00055 
00056 class MetaDataDB;
00057 class SecretsCache;
00058 class SignonIdentityInfo;
00059 
00066 class CredentialsDB: public QObject
00067 {
00068     Q_OBJECT
00069     Q_DISABLE_COPY(CredentialsDB)
00070 
00071     friend class ::TestDatabase;
00072 
00073     class ErrorMonitor
00074     {
00075     public:
00076         /* The constructor clears the errors in CredentialsDB, MetaDataDB and
00077          * SecretsDB. */
00078         ErrorMonitor(CredentialsDB *db);
00079         /* The destructor collects the errors and sets
00080          * CredentialsDB::_lastError to the appropriate value. */
00081         ~ErrorMonitor();
00082     private:
00083         CredentialsDB *_db;
00084     };
00085     friend class ErrorMonitor;
00086 
00087 public:
00088     CredentialsDB(const QString &metaDataDbName,
00089                   SignOn::AbstractSecretsStorage *secretsStorage);
00090     ~CredentialsDB();
00091 
00092     bool init();
00098     bool openSecretsDB(const QString &secretsDbName);
00099     bool isSecretsDBOpen();
00100     void closeSecretsDB();
00101 
00102     SignOn::CredentialsDBError lastError() const;
00103     bool errorOccurred() const { return lastError().isValid(); };
00104 
00105     QStringList methods(const quint32 id,
00106                         const QString &securityToken = QString());
00107     bool checkPassword(const quint32 id,
00108                        const QString &username, const QString &password);
00109     SignonIdentityInfo credentials(const quint32 id, bool queryPassword = true);
00110     QList<SignonIdentityInfo> credentials(const QMap<QString, QString> &filter);
00111 
00112     quint32 insertCredentials(const SignonIdentityInfo &info);
00113     quint32 updateCredentials(const SignonIdentityInfo &info);
00114     bool removeCredentials(const quint32 id);
00115 
00116     bool clear();
00117 
00118     QStringList accessControlList(const quint32 identityId);
00119     QStringList ownerList(const quint32 identityId);
00120     QString credentialsOwnerSecurityToken(const quint32 identityId);
00121 
00122     QVariantMap loadData(const quint32 id, const QString &method);
00123     bool storeData(const quint32 id,
00124                    const QString &method,
00125                    const QVariantMap &data);
00126     bool removeData(const quint32 id, const QString &method = QString());
00127 
00128     bool addReference(const quint32 id,
00129                       const QString &token,
00130                       const QString &reference);
00131     bool removeReference(const quint32 id,
00132                          const QString &token,
00133                          const QString &reference = QString());
00134     QStringList references(const quint32 id,
00135                            const QString &token = QString());
00136 
00137 Q_SIGNALS:
00138     void credentialsUpdated(quint32 id);
00139 
00140 private:
00141     SignOn::AbstractSecretsStorage *secretsStorage;
00142     SecretsCache *m_secretsCache;
00143     MetaDataDB *metaDataDB;
00144     SignOn::CredentialsDBError _lastError;
00145     SignOn::CredentialsDBError noSecretsDB;
00146 };
00147 
00148 } // namespace SignonDaemonNS
00149 
00150 #endif // CREDENTIALSDB_H