signon  8.58
signonsessioncore.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 #ifndef SIGNONSESSIONCORE_H_
00024 #define SIGNONSESSIONCORE_H_
00025 
00026 #include <QtCore>
00027 #include <QtDBus>
00028 
00029 /*
00030  * TODO: remove invocation of plugin operations into the main signond process
00031  */
00032 
00033 #include "pluginproxy.h"
00034 #include "signondisposable.h"
00035 #include "signonsessioncoretools.h"
00036 
00037 using namespace SignOn;
00038 
00039 class SignonUiAdaptor;
00040 
00041 namespace SignonDaemonNS {
00042 
00043 class SignonDaemon;
00044 
00050 class SignonSessionCore: public SignonDisposable
00051 {
00052     Q_OBJECT
00053 
00054 public:
00055     static SignonSessionCore *sessionCore(const quint32 id,
00056                                           const QString &method,
00057                                           SignonDaemon *parent);
00058     virtual ~SignonSessionCore();
00059     quint32 id() const;
00060     QString method() const;
00061     bool setupPlugin();
00062     /*
00063      * just for any case
00064      * */
00065     static void stopAllAuthSessions();
00066     static QStringList loadedPluginMethods(const QString &method);
00067 
00068     void destroy();
00069 
00070 public Q_SLOTS:
00071     QStringList queryAvailableMechanisms(const QStringList &wantedMechanisms);
00072 
00073     void process(const QDBusConnection &connection,
00074                  const QDBusMessage &message,
00075                  const QVariantMap &sessionDataVa,
00076                  const QString &mechanism,
00077                  const QString &cancelKey);
00078 
00079     void cancel(const QString &cancelKey);
00080     void setId(quint32 id);
00081 
00082     /* When the credentials system is ready, session processing will begin.
00083      * This mechanism helps avoiding the display of eroneous secure storage
00084      * related messages on query credentials dialogs (e.g. The `No key present`
00085      * scenario - keys might actually be present but the querying of them is
00086      * not complete at the time of the auth. session processing).
00087      */
00088     void credentialsSystemReady();
00089 
00090 Q_SIGNALS:
00091     void stateChanged(const QString &requestId,
00092                       int state,
00093                       const QString &message);
00094 
00095 private Q_SLOTS:
00096     void startNewRequest();
00097 
00098     void processResultReply(const QVariantMap &data);
00099     void processStore(const QVariantMap &data);
00100     void processUiRequest(const QVariantMap &data);
00101     void processRefreshRequest(const QVariantMap &data);
00102     void processError(int err, const QString &message);
00103     void stateChangedSlot(int state,
00104                           const QString &message);
00105 
00106     void queryUiSlot(QDBusPendingCallWatcher *call);
00107 
00108 protected:
00109     SignonSessionCore(quint32 id,
00110                       const QString &method,
00111                       int timeout,
00112                       QObject *parent);
00113 
00114     void childEvent(QChildEvent *ce);
00115     void customEvent(QEvent *event);
00116 
00117 private:
00118     void startProcess();
00119     void replyError(const QDBusConnection &conn,
00120                     const QDBusMessage &msg,
00121                     int err,
00122                     const QString &message);
00123     void processStoreOperation(const StoreOperation &operation);
00124     void requestDone();
00125 
00126 private:
00127     PluginProxy *m_plugin;
00128     QQueue<RequestData> m_listOfRequests;
00129     SignonUiAdaptor *m_signonui;
00130 
00131     QDBusPendingCallWatcher *m_watcher;
00132 
00133     bool m_requestIsActive;
00134     bool m_canceled;
00135 
00136     uint m_id;
00137     QString m_method;
00138     /* the original request parameters, for the request currently being
00139      * processed */
00140     QVariantMap m_clientData;
00141 
00142     //Temporary caching
00143     QString m_tmpUsername;
00144     QString m_tmpPassword;
00145 
00146     /* Flag used for handling post ui querying results' processing.
00147      * Secure storage not available events won't be posted if the current
00148      * session processing was not preceded by a signon UI query credentials
00149      * interaction, when this flag is set to true. */
00150     bool m_queryCredsUiDisplayed;
00151 
00152     Q_DISABLE_COPY(SignonSessionCore)
00153 }; //class SignonDaemon
00154 
00155 } //namespace SignonDaemonNS
00156 
00157 #endif //SIGNONSESSIONQUEUE_H_