97091efabd2e655f315506081763d5e9290e20b3
[quassel.git] / src / core / authenticator.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #pragma once
22
23 #include <QObject>
24 #include <QString>
25 #include <QStringList>
26 #include <QVariant>
27
28 #include "types.h"
29
30 class Authenticator : public QObject {
31
32     Q_OBJECT
33
34 public:
35     Authenticator(QObject *parent = 0);
36     virtual ~Authenticator() {};
37
38     enum State {
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.
42     };
43
44
45 public slots:
46     // General
47
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.
52      */
53     virtual bool isAvailable() const = 0;
54
55     //! Returns the display name of the authenticator backend
56     /** \return A string that can be used by the client to name the authenticator backend */
57     virtual QString backendId() const = 0;
58
59     //! Returns a description of this authenticator backend
60     /** \return A string that can be displayed by the client to describe the authenticator */
61     virtual QString description() const = 0;
62
63     //! Returns a list of properties required to use the authenticator backend
64     virtual QStringList setupKeys() const = 0;
65
66     //! Checks if the authenticator allows manual password changes from inside quassel.
67     virtual bool canChangePassword() const = 0;
68
69     //! Returns a map where the keys are are properties to use the authenticator backend
70     /*  the values are QVariants with default values */
71     virtual QVariantMap setupDefaults() const = 0;
72
73     //! Setup the authenticator provider.
74     /** This prepares the authenticator provider (e.g. create tables, etc.) for use within Quassel.
75      *  \param settings   Hostname, port, username, password, ...
76      *  \return True if and only if the authenticator provider was initialized successfully.
77      */
78     virtual bool setup(const QVariantMap &settings = QVariantMap()) = 0;
79
80     //! Initialize the authenticator provider
81     /** \param settings   Hostname, port, username, password, ...
82      *  \return the State the authenticator backend is now in (see authenticator::State)
83      */
84     virtual State init(const QVariantMap &settings = QVariantMap()) = 0;
85
86     //! Validate a username with a given password.
87     /** \param user     The username to validate
88      *  \param password The user's alleged password
89      *  \return A valid UserId if the password matches the username; 0 else
90      */
91     virtual UserId validateUser(const QString &user, const QString &password) = 0;
92
93 private:
94
95 };