1 /***************************************************************************
2 * Copyright (C) 2005-2016 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 #include <QStringList>
30 class Authenticator : public QObject {
35 using QObject::QObject;
36 ~Authenticator() override = default;
39 IsReady, // ready to go
40 NeedsSetup, // need basic setup (ask the user for input)
41 NotAvailable // remove the authenticator backend from the list of avaliable authenticators.
48 //! Check if the authenticator type is available.
49 /** An authenticator subclass should return true if it can be successfully used, i.e. if all
50 * prerequisites are in place.
51 * \return True if and only if the authenticator class can be successfully used.
53 virtual bool isAvailable() const = 0;
55 //! Returns the identifier of the authenticator backend
56 /** \return A string that can be used by the client to identify the authenticator backend */
57 virtual QString backendId() const = 0;
59 //! Returns the display name of the authenticator backend
60 /** \return A string that can be used by the client to name the authenticator backend */
61 virtual QString displayName() const = 0;
63 //! Returns a description of this authenticator backend
64 /** \return A string that can be displayed by the client to describe the authenticator */
65 virtual QString description() const = 0;
67 //! Returns data required to configure the authenticator backend
69 * A list of flattened triples for each field: {key, translated field name, default value}
70 * The default value's type determines the kind of input widget to be shown
71 * (int -> QSpinBox; QString -> QLineEdit)
72 * \return A list of triples defining the data to be shown in the configuration dialog
74 virtual QVariantList setupData() const = 0;
76 //! Checks if the authenticator allows manual password changes from inside quassel.
77 virtual bool canChangePassword() const = 0;
79 //! Setup the authenticator provider.
80 /** This prepares the authenticator provider (e.g. create tables, etc.) for use within Quassel.
81 * \param settings Hostname, port, username, password, ...
82 * \return True if and only if the authenticator provider was initialized successfully.
84 virtual bool setup(const QVariantMap &settings = QVariantMap()) = 0;
86 //! Initialize the authenticator provider
87 /** \param settings Hostname, port, username, password, ...
88 * \return the State the authenticator backend is now in (see authenticator::State)
90 virtual State init(const QVariantMap &settings = QVariantMap()) = 0;
92 //! Validate a username with a given password.
93 /** \param user The username to validate
94 * \param password The user's alleged password
95 * \return A valid UserId if the password matches the username; 0 else
97 virtual UserId validateUser(const QString &user, const QString &password) = 0;