sessiondata.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2012-2016 Canonical Ltd.
00006  *
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00033 #ifndef SESSIONDATA_H
00034 #define SESSIONDATA_H
00035 
00036 #include <QMap>
00037 #include <QString>
00038 #include <QStringList>
00039 #include <QVariant>
00040 
00041 #include <SignOn/libsignoncommon.h>
00042 
00043 namespace SignOn {
00044 
00053 #define SIGNON_SESSION_DECLARE_PROPERTY(type_, name_) \
00054           void set##name_(const type_ &value ) { m_data.insert(QLatin1String(#name_), value); } \
00055           type_ name_() const { return m_data.value(QLatin1String(#name_)).value<type_>(); }
00056 
00062 #define SSO_ACCESS_CONTROL_TOKENS QLatin1String("AccessControlTokens")
00063 
00072 enum SignonUiPolicy {
00073     DefaultPolicy = 0,          
00074     RequestPasswordPolicy,      
00075     NoUserInteractionPolicy,    
00076     ValidationPolicy,           
00079 };
00080 
00091 class SIGNON_EXPORT SessionData
00092 {
00093 public:
00100     SessionData(const QVariantMap &data = QVariantMap()) { m_data = data; }
00101 
00106     SessionData(const SessionData &other) { m_data = other.m_data; }
00107 
00113     SessionData &operator=(const SessionData &other) {
00114         m_data = other.m_data;
00115         return *this;
00116     }
00117 
00123     SessionData &operator+=(const SessionData &other) {
00124         m_data.unite(other.m_data);
00125         return *this;
00126     }
00127 
00132     const QStringList propertyNames() const {
00133         return m_data.keys();
00134     }
00135 
00142     const QVariant getProperty(const QString &propertyName) const {
00143         return m_data.value(propertyName, QVariant());
00144     }
00145 
00150     QStringList getAccessControlTokens() const {
00151         return getProperty(SSO_ACCESS_CONTROL_TOKENS).toStringList();
00152     }
00153 
00159     template <class T> T data() const {
00160         T dataImpl;
00161         dataImpl.m_data = m_data;
00162         return dataImpl;
00163     }
00164 
00169     QVariantMap toMap() const { return m_data; }
00170 
00176     SIGNON_SESSION_DECLARE_PROPERTY(QString, Secret)
00177 
00178     
00181     SIGNON_SESSION_DECLARE_PROPERTY(QString, UserName)
00182 
00187     SIGNON_SESSION_DECLARE_PROPERTY(QString, Realm)
00188 
00193     SIGNON_SESSION_DECLARE_PROPERTY(QString, NetworkProxy)
00194 
00200     SIGNON_SESSION_DECLARE_PROPERTY(int, UiPolicy)
00201 
00210     SIGNON_SESSION_DECLARE_PROPERTY(QString, Caption)
00211 
00218     SIGNON_SESSION_DECLARE_PROPERTY(quint32, NetworkTimeout)
00219 
00224     SIGNON_SESSION_DECLARE_PROPERTY(quint32, WindowId)
00225 
00233     SIGNON_SESSION_DECLARE_PROPERTY(bool, RenewToken)
00234 
00235 protected:
00236     QVariantMap m_data;
00237 };
00238 
00239 } //namespace SignOn
00240 
00241 Q_DECLARE_METATYPE(SignOn::SessionData)
00242 #endif // SESSIONDATA_H