1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
21 /* This file contains an implementation of an LDAP Authenticator, as an example
22 * of what a custom external auth provider could do.
24 * It's based off of this pull request for quassel by abustany:
25 * https://github.com/quassel/quassel/pull/4/
31 #include "authenticator.h"
36 /* We should use openldap on windows if at all possible, rather than trying to
37 * write some kind of compatiblity routine.
45 // Default LDAP server port.
46 constexpr int DEFAULT_LDAP_PORT = 389;
48 class LdapAuthenticator : public Authenticator
53 LdapAuthenticator(QObject *parent = 0);
54 ~LdapAuthenticator() override;
58 bool isAvailable() const override;
59 QString backendId() const override;
60 QString displayName() const override;
61 QString description() const override;
62 QVariantList setupData() const override;
64 bool canChangePassword() const override { return false; }
66 bool setup(const QVariantMap &settings, const QProcessEnvironment &environment,
67 bool loadFromEnvironment) override;
68 State init(const QVariantMap &settings, const QProcessEnvironment &environment,
69 bool loadFromEnvironment) override;
70 UserId validateUser(const QString &user, const QString &password) override;
73 void setAuthProperties(const QVariantMap &properties, const QProcessEnvironment &environment,
74 bool loadFromEnvironment);
76 void ldapDisconnect();
77 bool ldapAuth(const QString &username, const QString &password);
79 // Protected methods for retrieving info about the LDAP connection.
80 QString hostName() const { return _hostName; }
81 int port() const { return _port; }
82 QString bindDN() const { return _bindDN; }
83 QString baseDN() const { return _baseDN; }
91 QString _bindPassword;
92 QString _uidAttribute;
94 // The actual connection object.
95 LDAP *_connection {nullptr};