2017-07-16 22:37:13 +07:00
|
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import exceptions = require("../Exceptions");
|
|
|
|
import ldapjs = require("ldapjs");
|
|
|
|
import { Client } from "./Client";
|
|
|
|
|
2017-09-03 03:38:26 +07:00
|
|
|
import { IPasswordUpdater } from "./IPasswordUpdater";
|
2017-07-20 02:06:12 +07:00
|
|
|
import { LdapConfiguration } from "../configuration/Configuration";
|
2017-09-03 03:38:26 +07:00
|
|
|
import { IClientFactory } from "./IClientFactory";
|
2017-07-16 22:37:13 +07:00
|
|
|
|
|
|
|
|
2017-09-03 03:38:26 +07:00
|
|
|
export class PasswordUpdater implements IPasswordUpdater {
|
2017-07-16 22:37:13 +07:00
|
|
|
private options: LdapConfiguration;
|
2017-09-03 03:38:26 +07:00
|
|
|
private clientFactory: IClientFactory;
|
2017-07-16 22:37:13 +07:00
|
|
|
|
2017-09-03 03:38:26 +07:00
|
|
|
constructor(options: LdapConfiguration, clientFactory: IClientFactory) {
|
2017-07-16 22:37:13 +07:00
|
|
|
this.options = options;
|
2017-09-03 03:38:26 +07:00
|
|
|
this.clientFactory = clientFactory;
|
2017-07-16 22:37:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
updatePassword(username: string, newPassword: string): BluebirdPromise<void> {
|
2017-09-03 03:38:26 +07:00
|
|
|
const adminClient = this.clientFactory.create(this.options.user, this.options.password);
|
2017-07-16 22:37:13 +07:00
|
|
|
|
|
|
|
return adminClient.open()
|
|
|
|
.then(function () {
|
|
|
|
return adminClient.modifyPassword(username, newPassword);
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return adminClient.close();
|
|
|
|
})
|
|
|
|
.error(function (err: Error) {
|
|
|
|
return BluebirdPromise.reject(new exceptions.LdapError("Failed during password update: " + err.message));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|