X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fldapauthenticator.h;h=37550cd07f05b9416107e415c9cfdd9dac2deaf0;hp=c6ee7f1e921addda70e53429996d636f20d0061e;hb=8961f348947fc55cc4bc769563684af3f2ea7ccc;hpb=61aac1868f15babb7086d8bc6bbcff530346f438 diff --git a/src/core/ldapauthenticator.h b/src/core/ldapauthenticator.h index c6ee7f1e..37550cd0 100644 --- a/src/core/ldapauthenticator.h +++ b/src/core/ldapauthenticator.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,43 +18,75 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef LDAPAUTHENTICATOR_H -#define LDAPAUTHENTICATOR_H +/* This file contains an implementation of an LDAP Authenticator, as an example + * of what a custom external auth provider could do. + * + * It's based off of this pull request for quassel by abustany: + * https://github.com/quassel/quassel/pull/4/ + * + */ + +#pragma once #include "authenticator.h" +#include "core.h" + +// Link against LDAP. +/* We should use openldap on windows if at all possible, rather than trying to + * write some kind of compatiblity routine. +#ifdef Q_CC_MSVC +#include +#include +#else*/ +#include +//#endif + +// Default LDAP server port. +constexpr int DEFAULT_LDAP_PORT = 389; class LdapAuthenticator : public Authenticator { Q_OBJECT public: - LdapAuthenticator(QObject *parent = 0); - virtual ~LdapAuthenticator(); + LdapAuthenticator(QObject* parent = nullptr); + ~LdapAuthenticator() override; public slots: /* General */ - virtual bool isAvailable() const; - virtual QString displayName() const; - virtual QString description() const; - virtual QStringList setupKeys() const; - virtual QVariantMap setupDefaults() const; - - /* User handling */ - virtual UserId getUserId(const QString &username); - + bool isAvailable() const override; + QString backendId() const override; + QString displayName() const override; + QString description() const override; + QVariantList setupData() const override; + + bool canChangePassword() const override { return false; } + + bool setup(const QVariantMap& settings, const QProcessEnvironment& environment, bool loadFromEnvironment) override; + State init(const QVariantMap& settings, const QProcessEnvironment& environment, bool loadFromEnvironment) override; + UserId validateUser(const QString& user, const QString& password) override; + protected: - // Protecte methods for retrieving info about the LDAP connection. - inline virtual QString hostName() { return _hostName; } - inline virtual int port() { return _port; } - inline virtual QString bindDN() { return _bindDN; } - inline virtual QString baseDN() { return _baseDN; } - + void setAuthProperties(const QVariantMap& properties, const QProcessEnvironment& environment, bool loadFromEnvironment); + bool ldapConnect(); + void ldapDisconnect(); + bool ldapAuth(const QString& username, const QString& password); + + // Protected methods for retrieving info about the LDAP connection. + QString hostName() const { return _hostName; } + int port() const { return _port; } + QString bindDN() const { return _bindDN; } + QString baseDN() const { return _baseDN; } + private: QString _hostName; int _port; - QString _bindDN; - QString _baseDN; -}; + QString _bindDN; + QString _baseDN; + QString _filter; + QString _bindPassword; + QString _uidAttribute; - -#endif + // The actual connection object. + LDAP* _connection{nullptr}; +};