sessiondata.h
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
32 #ifndef SESSIONDATA_H
33 #define SESSIONDATA_H
34 
35 #include <QMap>
36 #include <QString>
37 #include <QStringList>
38 #include <QVariant>
39 
40 #include <SignOn/libsignoncommon.h>
41 
42 namespace SignOn {
43 
52 #define SIGNON_SESSION_DECLARE_PROPERTY(type_, name_) \
53  void set##name_(const type_ &value ) { m_data.insert(QLatin1String(#name_), value); } \
54  type_ name_() const { return m_data.value(QLatin1String(#name_)).value<type_>(); }
55 
61 #define SSO_ACCESS_CONTROL_TOKENS QLatin1String("AccessControlTokens")
62 
78 };
79 
90 class SIGNON_EXPORT SessionData
91 {
92 public:
99  SessionData(const QVariantMap &data = QVariantMap()) { m_data = data; }
100 
105  SessionData(const SessionData &other) { m_data = other.m_data; }
106 
113  m_data = other.m_data;
114  return *this;
115  }
116 
123  m_data.unite(other.m_data);
124  return *this;
125  }
126 
131  const QStringList propertyNames() const {
132  return m_data.keys();
133  }
134 
141  const QVariant getProperty(const QString &propertyName) const {
142  return m_data.value(propertyName, QVariant());
143  }
144 
149  QStringList getAccessControlTokens() const {
150  return getProperty(SSO_ACCESS_CONTROL_TOKENS).toStringList();
151  }
152 
158  template <class T> T data() const {
159  T dataImpl;
160  dataImpl.m_data = m_data;
161  return dataImpl;
162  }
163 
168  QVariantMap toMap() const { return m_data; }
169 
175  SIGNON_SESSION_DECLARE_PROPERTY(QString, Secret)
176 
177 
180  SIGNON_SESSION_DECLARE_PROPERTY(QString, UserName)
181 
186  SIGNON_SESSION_DECLARE_PROPERTY(QString, Realm)
187 
192  SIGNON_SESSION_DECLARE_PROPERTY(QString, NetworkProxy)
193 
199  SIGNON_SESSION_DECLARE_PROPERTY(int, UiPolicy)
200 
209  SIGNON_SESSION_DECLARE_PROPERTY(QString, Caption)
210 
217  SIGNON_SESSION_DECLARE_PROPERTY(quint32, NetworkTimeout)
218 
223  SIGNON_SESSION_DECLARE_PROPERTY(quint32, WindowId)
224 
232  SIGNON_SESSION_DECLARE_PROPERTY(bool, RenewToken)
233 
234 protected:
235  QVariantMap m_data;
236 };
237 
238 } //namespace SignOn
239 
240 Q_DECLARE_METATYPE(SignOn::SessionData)
241 #endif // SESSIONDATA_H
const QStringList propertyNames() const
Access the list of runtime existing properties of the SessionData.
Definition: sessiondata.h:131
SignonUiPolicy
Policy to define how the plugin interacts with the user.
Definition: sessiondata.h:71
Data container to hold values for authentication session.
Definition: sessiondata.h:90
QVariantMap toMap() const
Gets the QVariantMap of session parameters.
Definition: sessiondata.h:168
SessionData & operator+=(const SessionData &other)
Addition operator.
Definition: sessiondata.h:122
QStringList getAccessControlTokens() const
Gets the access control tokens that the requesting application has.
Definition: sessiondata.h:149
SessionData(const SessionData &other)
Copy constructor.
Definition: sessiondata.h:105
SessionData & operator=(const SessionData &other)
Assignment operator.
Definition: sessiondata.h:112
SessionData(const QVariantMap &data=QVariantMap())
Constructor.
Definition: sessiondata.h:99
const QVariant getProperty(const QString &propertyName) const
Access the list of runtime existing properties of the SessionData.
Definition: sessiondata.h:141
QVariantMap m_data
Declares the property Secret setter and getter.
Definition: sessiondata.h:235
T data() const
Creates an instance of type T, which must be derived from SessionData.
Definition: sessiondata.h:158