My Project
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  for (auto it = other.m_data.constBegin(), itEnd = other.m_data.constEnd(); it != itEnd; ++it) {
125  m_data[it.key()] = it.value();
126  }
127  return *this;
128  }
129 
134  const QStringList propertyNames() const {
135  return m_data.keys();
136  }
137 
144  const QVariant getProperty(const QString &propertyName) const {
145  return m_data.value(propertyName, QVariant());
146  }
147 
152  QStringList getAccessControlTokens() const {
153  return getProperty(SSO_ACCESS_CONTROL_TOKENS).toStringList();
154  }
155 
161  template <class T> T data() const {
162  T dataImpl;
163  dataImpl.m_data = m_data;
164  return dataImpl;
165  }
166 
171  QVariantMap toMap() const { return m_data; }
172 
178  SIGNON_SESSION_DECLARE_PROPERTY(QString, Secret)
179 
180 
183  SIGNON_SESSION_DECLARE_PROPERTY(QString, UserName)
184 
185 
189  SIGNON_SESSION_DECLARE_PROPERTY(QString, Realm)
190 
191 
195  SIGNON_SESSION_DECLARE_PROPERTY(QString, NetworkProxy)
196 
197 
202  SIGNON_SESSION_DECLARE_PROPERTY(int, UiPolicy)
203 
204 
212  SIGNON_SESSION_DECLARE_PROPERTY(QString, Caption)
213 
214 
220  SIGNON_SESSION_DECLARE_PROPERTY(quint32, NetworkTimeout)
221 
222 
226  SIGNON_SESSION_DECLARE_PROPERTY(quint32, WindowId)
227 
228 
235  SIGNON_SESSION_DECLARE_PROPERTY(bool, RenewToken)
236 
237 protected:
238  QVariantMap m_data;
239 };
240 
241 } //namespace SignOn
242 
243 Q_DECLARE_METATYPE(SignOn::SessionData)
244 #endif // SESSIONDATA_H
Data container to hold values for authentication session.
Definition: sessiondata.h:92
T data() const
Creates an instance of type T, which must be derived from SessionData.
Definition: sessiondata.h:161
SessionData & operator=(const SessionData &other)
Assignment operator.
Definition: sessiondata.h:113
const QVariant getProperty(const QString &propertyName) const
Access the list of runtime existing properties of the SessionData.
Definition: sessiondata.h:144
QStringList getAccessControlTokens() const
Gets the access control tokens that the requesting application has.
Definition: sessiondata.h:152
SessionData(const SessionData &other)
Copy constructor.
Definition: sessiondata.h:106
const QStringList propertyNames() const
Access the list of runtime existing properties of the SessionData.
Definition: sessiondata.h:134
SessionData & operator+=(const SessionData &other)
Addition operator.
Definition: sessiondata.h:123
QVariantMap m_data
Declares the property Secret setter and getter.
Definition: sessiondata.h:238
QVariantMap toMap() const
Gets the QVariantMap of session parameters.
Definition: sessiondata.h:171
SessionData(const QVariantMap &data=QVariantMap())
Constructor.
Definition: sessiondata.h:100
SignonUiPolicy
Policy to define how the plugin interacts with the user.
Definition: sessiondata.h:72
@ NoUserInteractionPolicy
Definition: sessiondata.h:75
@ RequestPasswordPolicy
Definition: sessiondata.h:74
@ ValidationPolicy
Definition: sessiondata.h:76
@ DefaultPolicy
Definition: sessiondata.h:73