My Project
identity.cpp
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  * Copyright (C) 2011-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  */
23 
24 #include <QDBusMetaType>
25 
26 #include "debug.h"
27 #include "identityimpl.h"
28 #include "identity.h"
29 #include "securitycontext.h"
30 #include "securitycontextpriv.h"
31 
32 namespace SignOn {
33 
34 Identity::Identity(const quint32 id, QObject *parent):
35  QObject(parent)
36 {
37  initDebug();
38 
39  qRegisterMetaType<Error>("SignOn::Error");
40  qRegisterMetaType<Error>("Error");
41  qDBusRegisterMetaType<SecurityContext>();
42 
43  if (qMetaTypeId<Error>() < QMetaType::User)
44  BLAME() << "Identity::Identity() - "
45  "SignOn::Error meta type not registered.";
46 
47  impl = new IdentityImpl(this, id);
48 }
49 
50 Identity *Identity::newIdentity(const IdentityInfo &info, QObject *parent)
51 {
52  Identity *identity = new Identity(SSO_NEW_IDENTITY, parent);
53  identity->impl->copyInfo(info);
54  return identity;
55 }
56 
57 Identity *Identity::existingIdentity(const quint32 id, QObject *parent)
58 {
59  if (id == 0)
60  return NULL;
61  return new Identity(id, parent);
62 }
63 
65 {
66 }
67 
68 quint32 Identity::id() const
69 {
70  return impl->id();
71 }
72 
74 {
75  impl->queryAvailableMethods();
76 }
77 
78 AuthSessionP Identity::createSession(const QString &methodName)
79 {
80  if (methodName.isEmpty())
81  return NULL;
82 
83  return AuthSessionP(impl->createSession(methodName, this));
84 }
85 
86 void Identity::destroySession(const AuthSessionP &session)
87 {
88  if (session.isNull())
89  return;
90 
91  impl->destroySession(session.data());
92 }
93 
94 void Identity::requestCredentialsUpdate(const QString &message)
95 {
96  impl->requestCredentialsUpdate(message);
97 }
98 
100 {
101  impl->storeCredentials(info);
102 }
103 
105 {
106  impl->remove();
107 }
108 
109 void Identity::addReference(const QString &reference)
110 {
111  impl->addReference(reference);
112 }
113 
114 void Identity::removeReference(const QString &reference)
115 {
116  impl->removeReference(reference);
117 }
118 
120 {
121  impl->queryInfo();
122 }
123 
124 void Identity::verifyUser(const QString &message)
125 {
126  impl->verifyUser(message);
127 }
128 
129 void Identity::verifyUser(const QVariantMap &params)
130 {
131  impl->verifyUser(params);
132 }
133 
134 void Identity::verifySecret(const QString &secret)
135 {
136  impl->verifySecret(secret);
137 }
138 
140 {
141  impl->signOut();
142 }
143 
144 } //namespace SignOn
Contains identity information.
Definition: identityinfo.h:65
Represents a database entry for a single identity.
Definition: identity.h:58
void destroySession(const AuthSessionP &session)
Destroys an authentication session.
Definition: identity.cpp:86
static Identity * newIdentity(const IdentityInfo &info=IdentityInfo(), QObject *parent=0)
Constructs a new identity object.
Definition: identity.cpp:50
void addReference(const QString &reference=QString())
Adds the named reference to identity into the database.
Definition: identity.cpp:109
void removeReference(const QString &reference=QString())
Removes a named reference to identity from the database.
Definition: identity.cpp:114
void queryInfo()
Query stored credential parameters for this authentication identity.
Definition: identity.cpp:119
void requestCredentialsUpdate(const QString &message=QString())
Requests the user to give a new secret into database.
Definition: identity.cpp:94
AuthSessionP createSession(const QString &methodName)
Creates a new session for authentication.
Definition: identity.cpp:78
void verifySecret(const QString &secret)
Verifies if the given secret match the stored secret.
Definition: identity.cpp:134
void verifyUser(const QString &message=QString())
Gets a secret verification from the user and compares it to the stored secret.
Definition: identity.cpp:124
quint32 id() const
Unique id of given identity.
Definition: identity.cpp:68
void info(const SignOn::IdentityInfo &info)
Emitted when credentials passed by queryInfo() method.
void signOut()
Signs out Identity from all services.
Definition: identity.cpp:139
virtual ~Identity()
Destructor.
Definition: identity.cpp:64
void remove()
Removes this identity from database.
Definition: identity.cpp:104
void storeCredentials(const IdentityInfo &info=IdentityInfo())
Stores credential parameters for this authentication identity.
Definition: identity.cpp:99
static Identity * existingIdentity(const quint32 id, QObject *parent=0)
Constructs an identity object associated with an existing identity record.
Definition: identity.cpp:57
void queryAvailableMethods()
Query list of available authentication methods for given identity.
Definition: identity.cpp:73
Identity(const quint32 id=SSO_NEW_IDENTITY, QObject *parent=0)
Definition: identity.cpp:34