| 1 | /* |
| 2 | * This file is part of libOnlineAccounts |
| 3 | * |
| 4 | * Copyright (C) 2015-2016 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "authentication_data_p.h" |
| 22 | |
| 23 | #include <QDBusMetaType> |
| 24 | #include <LomiriOnlineAccountsDaemon/dbus_constants.h> |
| 25 | |
| 26 | using namespace OnlineAccounts; |
| 27 | |
| 28 | AuthenticationDataPrivate::AuthenticationDataPrivate(AuthenticationMethod method): |
| 29 | m_method(method), |
| 30 | m_interactive(true), |
| 31 | m_invalidateCachedReply(false) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | AuthenticationData::AuthenticationData(AuthenticationMethod method): |
| 36 | d(new AuthenticationDataPrivate(method)) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | AuthenticationData::AuthenticationData(AuthenticationDataPrivate *priv): |
| 41 | d(priv) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | AuthenticationData::AuthenticationData(const AuthenticationData &other): |
| 46 | d(other.d) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | AuthenticationData::~AuthenticationData() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | AuthenticationMethod AuthenticationData::method() const |
| 55 | { |
| 56 | return d->m_method; |
| 57 | } |
| 58 | |
| 59 | void AuthenticationData::setInteractive(bool interactive) |
| 60 | { |
| 61 | d->m_interactive = interactive; |
| 62 | } |
| 63 | |
| 64 | bool AuthenticationData::interactive() const |
| 65 | { |
| 66 | return d->m_interactive; |
| 67 | } |
| 68 | |
| 69 | void AuthenticationData::invalidateCachedReply() |
| 70 | { |
| 71 | d->m_invalidateCachedReply = true; |
| 72 | } |
| 73 | |
| 74 | bool AuthenticationData::mustInvalidateCachedReply() const |
| 75 | { |
| 76 | return d->m_invalidateCachedReply; |
| 77 | } |
| 78 | |
| 79 | void AuthenticationData::setParameters(const QVariantMap ¶meters) |
| 80 | { |
| 81 | d->m_parameters = parameters; |
| 82 | } |
| 83 | |
| 84 | QVariantMap AuthenticationData::parameters() const |
| 85 | { |
| 86 | return d->m_parameters; |
| 87 | } |
| 88 | |
| 89 | /* OAuth 2.0 */ |
| 90 | |
| 91 | OAuth2Data::OAuth2Data(): |
| 92 | AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodOAuth2)) |
| 93 | { |
| 94 | qDBusRegisterMetaType<QList<QByteArray>>(); |
| 95 | } |
| 96 | |
| 97 | void OAuth2Data::setClientId(const QByteArray &id) |
| 98 | { |
| 99 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_ID] = id; |
| 100 | } |
| 101 | |
| 102 | QByteArray OAuth2Data::clientId() const |
| 103 | { |
| 104 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_ID].toByteArray(); |
| 105 | } |
| 106 | |
| 107 | void OAuth2Data::setClientSecret(const QByteArray &secret) |
| 108 | { |
| 109 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_SECRET] = secret; |
| 110 | } |
| 111 | |
| 112 | QByteArray OAuth2Data::clientSecret() const |
| 113 | { |
| 114 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CLIENT_SECRET].toByteArray(); |
| 115 | } |
| 116 | |
| 117 | void OAuth2Data::setScopes(const QList<QByteArray> &scopes) |
| 118 | { |
| 119 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SCOPES] = QVariant::fromValue(scopes); |
| 120 | } |
| 121 | |
| 122 | QList<QByteArray> OAuth2Data::scopes() const |
| 123 | { |
| 124 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SCOPES].value<QList<QByteArray> >(); |
| 125 | } |
| 126 | |
| 127 | /* OAuth 1.0a */ |
| 128 | |
| 129 | OAuth1Data::OAuth1Data(): |
| 130 | AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodOAuth1)) |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | void OAuth1Data::setConsumerKey(const QByteArray &key) |
| 135 | { |
| 136 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] = key; |
| 137 | } |
| 138 | |
| 139 | QByteArray OAuth1Data::consumerKey() const |
| 140 | { |
| 141 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY].toByteArray(); |
| 142 | } |
| 143 | |
| 144 | void OAuth1Data::setConsumerSecret(const QByteArray &secret) |
| 145 | { |
| 146 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET] = secret; |
| 147 | } |
| 148 | |
| 149 | QByteArray OAuth1Data::consumerSecret() const |
| 150 | { |
| 151 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET].toByteArray(); |
| 152 | } |
| 153 | |
| 154 | /* SASL */ |
| 155 | |
| 156 | SaslData::SaslData(): |
| 157 | AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodSasl)) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | void SaslData::setService(const QString &service) |
| 162 | { |
| 163 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SERVICE] = service; |
| 164 | } |
| 165 | |
| 166 | QString SaslData::service() const |
| 167 | { |
| 168 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_SERVICE].toString(); |
| 169 | } |
| 170 | |
| 171 | void SaslData::setMechanismList(const QByteArray &mechanisms) |
| 172 | { |
| 173 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_MECHANISMS] = mechanisms; |
| 174 | } |
| 175 | |
| 176 | QByteArray SaslData::mechanismList() const |
| 177 | { |
| 178 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_MECHANISMS].toByteArray(); |
| 179 | } |
| 180 | |
| 181 | void SaslData::setServerFqdn(const QString &fqdn) |
| 182 | { |
| 183 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_FQDN] = fqdn; |
| 184 | } |
| 185 | |
| 186 | QString SaslData::serverFqdn() const |
| 187 | { |
| 188 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_FQDN].toString(); |
| 189 | } |
| 190 | |
| 191 | void SaslData::setLocalIp(const QString &localIp) |
| 192 | { |
| 193 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_LOCAL_IP] = localIp; |
| 194 | } |
| 195 | |
| 196 | QString SaslData::localIp() const |
| 197 | { |
| 198 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_LOCAL_IP].toString(); |
| 199 | } |
| 200 | |
| 201 | void SaslData::setRemoteIp(const QString &remoteIp) |
| 202 | { |
| 203 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_REMOTE_IP] = remoteIp; |
| 204 | } |
| 205 | |
| 206 | QString SaslData::remoteIp() const |
| 207 | { |
| 208 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_REMOTE_IP].toString(); |
| 209 | } |
| 210 | |
| 211 | void SaslData::setChallenge(const QByteArray &challenge) |
| 212 | { |
| 213 | d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CHALLENGE] = challenge; |
| 214 | } |
| 215 | |
| 216 | QByteArray SaslData::challenge() const |
| 217 | { |
| 218 | return d->m_parameters[ONLINE_ACCOUNTS_AUTH_KEY_CHALLENGE].toByteArray(); |
| 219 | } |
| 220 | |
| 221 | /* Password */ |
| 222 | |
| 223 | PasswordData::PasswordData(): |
| 224 | AuthenticationData(new AuthenticationDataPrivate(AuthenticationMethodPassword)) |
| 225 | { |
| 226 | } |