mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
66449eedb0
Previously, string "{0}" was replaced by the user dn in the groups_filter attributes of the LDAP configuration. However, if the groups children only have a memberUid attribute, one would like to use the username instead of the user dn. Since the user dn can be built from the username, "{0}" is now replaced by the username instead of the user dn so that an LDAP relying on attribute 'memberUid' can be used.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import BluebirdPromise = require("bluebird");
|
|
import exceptions = require("../Exceptions");
|
|
import ldapjs = require("ldapjs");
|
|
import { IClient } from "./IClient";
|
|
import { IClientFactory } from "./IClientFactory";
|
|
import { GroupsAndEmails } from "./IClient";
|
|
|
|
import { IAuthenticator } from "./IAuthenticator";
|
|
import { LdapConfiguration } from "../configuration/Configuration";
|
|
import { EmailsAndGroupsRetriever } from "./EmailsAndGroupsRetriever";
|
|
|
|
|
|
export class Authenticator implements IAuthenticator {
|
|
private options: LdapConfiguration;
|
|
private clientFactory: IClientFactory;
|
|
|
|
constructor(options: LdapConfiguration, clientFactory: IClientFactory) {
|
|
this.options = options;
|
|
this.clientFactory = clientFactory;
|
|
}
|
|
|
|
authenticate(username: string, password: string): BluebirdPromise<GroupsAndEmails> {
|
|
const that = this;
|
|
let userClient: IClient;
|
|
const adminClient = this.clientFactory.create(this.options.user, this.options.password);
|
|
const emailsAndGroupsRetriever = new EmailsAndGroupsRetriever(this.options, this.clientFactory);
|
|
|
|
return adminClient.open()
|
|
.then(function () {
|
|
return adminClient.searchUserDn(username);
|
|
})
|
|
.then(function (userDN: string) {
|
|
userClient = that.clientFactory.create(userDN, password);
|
|
return userClient.open();
|
|
})
|
|
.then(function () {
|
|
return userClient.close();
|
|
})
|
|
.then(function () {
|
|
return emailsAndGroupsRetriever.retrieve(username);
|
|
})
|
|
.then(function (groupsAndEmails: GroupsAndEmails) {
|
|
return BluebirdPromise.resolve(groupsAndEmails);
|
|
})
|
|
.error(function (err: Error) {
|
|
return BluebirdPromise.reject(new exceptions.LdapError(err.message));
|
|
});
|
|
}
|
|
} |