a0c8720dfd880f4632404ca051dada544f26dfe6
[quassel.git] / src / core / ldapauthenticator.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 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 /* This file contains an implementation of an LDAP Authenticator, as an example
22  * of what a custom external auth provider could do.
23  *
24  * It's based off of this pull request for quassel by abustany:
25  * https://github.com/quassel/quassel/pull/4/
26  *
27  */
28
29 #ifndef LDAPAUTHENTICATOR_H
30 #define LDAPAUTHENTICATOR_H
31
32 #include "authenticator.h"
33
34 #include "core.h"
35
36 // Link against LDAP.
37 #include <ldap.h>
38
39 // Default LDAP server port.
40 #define DEFAULT_LDAP_PORT 389
41
42 class LdapAuthenticator : public Authenticator
43 {
44     Q_OBJECT
45
46 public:
47     LdapAuthenticator(QObject *parent = 0);
48     virtual ~LdapAuthenticator();
49
50 public slots:
51     /* General */
52     bool isAvailable() const;
53     QString displayName() const;
54     QString description() const;
55     virtual QStringList setupKeys() const;
56     virtual QVariantMap setupDefaults() const;
57
58     virtual inline bool canChangePassword() const { return false; }
59
60     bool setup(const QVariantMap &settings = QVariantMap());
61     State init(const QVariantMap &settings = QVariantMap());
62     UserId validateUser(const QString &user, const QString &password);
63
64 protected:
65     virtual void setConnectionProperties(const QVariantMap &properties);
66     bool ldapConnect();
67     void ldapDisconnect();
68     bool ldapAuth(const QString &username, const QString &password);
69
70     // Protected methods for retrieving info about the LDAP connection.
71     inline virtual QString hostName() { return _hostName; }
72     inline virtual int port() { return _port; }
73     inline virtual QString bindDN() { return _bindDN; }
74     inline virtual QString baseDN() { return _baseDN; }
75
76 private:
77     QString _hostName;
78     int _port;
79     QString _bindDN;
80     QString _baseDN;
81     QString _filter;
82     QString _bindPassword;
83     QString _uidAttribute;
84
85     // The actual connection object.
86     LDAP *_connection;
87
88 };
89
90
91 #endif