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