|
@@ -1,7 +1,6 @@
|
|
import ldapjs from 'ldapjs';
|
|
import ldapjs from 'ldapjs';
|
|
import util from 'util';
|
|
import util from 'util';
|
|
-import Bunyan from 'bunyan';
|
|
|
|
-import {log_debug, log_info, log_warn, log_error} from './logger';
|
|
|
|
|
|
+import { Log } from 'meteor/logging'
|
|
|
|
|
|
// copied from https://github.com/ldapjs/node-ldapjs/blob/a113953e0d91211eb945d2a3952c84b7af6de41c/lib/filters/index.js#L167
|
|
// copied from https://github.com/ldapjs/node-ldapjs/blob/a113953e0d91211eb945d2a3952c84b7af6de41c/lib/filters/index.js#L167
|
|
function escapedToHex (str) {
|
|
function escapedToHex (str) {
|
|
@@ -67,7 +66,7 @@ export default class LDAP {
|
|
}
|
|
}
|
|
return value;
|
|
return value;
|
|
} else {
|
|
} else {
|
|
- log_warn(`Lookup for unset variable: ${name}`);
|
|
|
|
|
|
+ Log.warn(`Lookup for unset variable: ${name}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,7 +86,7 @@ export default class LDAP {
|
|
}
|
|
}
|
|
|
|
|
|
connectAsync(callback) {
|
|
connectAsync(callback) {
|
|
- log_info('Init setup');
|
|
|
|
|
|
+ Log.info('Init setup');
|
|
|
|
|
|
let replied = false;
|
|
let replied = false;
|
|
|
|
|
|
@@ -134,15 +133,15 @@ export default class LDAP {
|
|
connectionOptions.url = `ldap://${connectionOptions.url}`;
|
|
connectionOptions.url = `ldap://${connectionOptions.url}`;
|
|
}
|
|
}
|
|
|
|
|
|
- log_info('Connecting', connectionOptions.url);
|
|
|
|
- log_debug(`connectionOptions${util.inspect(connectionOptions)}`);
|
|
|
|
|
|
+ Log.info('Connecting', connectionOptions.url);
|
|
|
|
+ Log.debug(`connectionOptions${util.inspect(connectionOptions)}`);
|
|
|
|
|
|
this.client = ldapjs.createClient(connectionOptions);
|
|
this.client = ldapjs.createClient(connectionOptions);
|
|
|
|
|
|
this.bindSync = Meteor.wrapAsync(this.client.bind, this.client);
|
|
this.bindSync = Meteor.wrapAsync(this.client.bind, this.client);
|
|
|
|
|
|
this.client.on('error', (error) => {
|
|
this.client.on('error', (error) => {
|
|
- log_error('connection', error);
|
|
|
|
|
|
+ Log.error('connection', error);
|
|
if (replied === false) {
|
|
if (replied === false) {
|
|
replied = true;
|
|
replied = true;
|
|
callback(error, null);
|
|
callback(error, null);
|
|
@@ -150,12 +149,12 @@ export default class LDAP {
|
|
});
|
|
});
|
|
|
|
|
|
this.client.on('idle', () => {
|
|
this.client.on('idle', () => {
|
|
- log_info('Idle');
|
|
|
|
|
|
+ Log.info('Idle');
|
|
this.disconnect();
|
|
this.disconnect();
|
|
});
|
|
});
|
|
|
|
|
|
this.client.on('close', () => {
|
|
this.client.on('close', () => {
|
|
- log_info('Closed');
|
|
|
|
|
|
+ Log.info('Closed');
|
|
});
|
|
});
|
|
|
|
|
|
if (this.options.encryption === 'tls') {
|
|
if (this.options.encryption === 'tls') {
|
|
@@ -164,12 +163,12 @@ export default class LDAP {
|
|
// https://github.com/mcavage/node-ldapjs/issues/349
|
|
// https://github.com/mcavage/node-ldapjs/issues/349
|
|
tlsOptions.host = this.options.host;
|
|
tlsOptions.host = this.options.host;
|
|
|
|
|
|
- log_info('Starting TLS');
|
|
|
|
- log_debug('tlsOptions', tlsOptions);
|
|
|
|
|
|
+ Log.info('Starting TLS');
|
|
|
|
+ Log.debug('tlsOptions', tlsOptions);
|
|
|
|
|
|
this.client.starttls(tlsOptions, null, (error, response) => {
|
|
this.client.starttls(tlsOptions, null, (error, response) => {
|
|
if (error) {
|
|
if (error) {
|
|
- log_error('TLS connection', error);
|
|
|
|
|
|
+ Log.error('TLS connection', error);
|
|
if (replied === false) {
|
|
if (replied === false) {
|
|
replied = true;
|
|
replied = true;
|
|
callback(error, null);
|
|
callback(error, null);
|
|
@@ -177,7 +176,7 @@ export default class LDAP {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- log_info('TLS connected');
|
|
|
|
|
|
+ Log.info('TLS connected');
|
|
this.connected = true;
|
|
this.connected = true;
|
|
if (replied === false) {
|
|
if (replied === false) {
|
|
replied = true;
|
|
replied = true;
|
|
@@ -186,7 +185,7 @@ export default class LDAP {
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
this.client.on('connect', (response) => {
|
|
this.client.on('connect', (response) => {
|
|
- log_info('LDAP connected');
|
|
|
|
|
|
+ Log.info('LDAP connected');
|
|
this.connected = true;
|
|
this.connected = true;
|
|
if (replied === false) {
|
|
if (replied === false) {
|
|
replied = true;
|
|
replied = true;
|
|
@@ -197,7 +196,7 @@ export default class LDAP {
|
|
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
if (replied === false) {
|
|
if (replied === false) {
|
|
- log_error('connection time out', connectionOptions.connectTimeout);
|
|
|
|
|
|
+ Log.error('connection time out', connectionOptions.connectTimeout);
|
|
replied = true;
|
|
replied = true;
|
|
callback(new Error('Timeout'));
|
|
callback(new Error('Timeout'));
|
|
}
|
|
}
|
|
@@ -218,7 +217,7 @@ export default class LDAP {
|
|
const usernameFilter = this.options.User_Search_Field.split(',').map((item) => `(${item}=${username})`);
|
|
const usernameFilter = this.options.User_Search_Field.split(',').map((item) => `(${item}=${username})`);
|
|
|
|
|
|
if (usernameFilter.length === 0) {
|
|
if (usernameFilter.length === 0) {
|
|
- log_error('LDAP_LDAP_User_Search_Field not defined');
|
|
|
|
|
|
+ Log.error('LDAP_LDAP_User_Search_Field not defined');
|
|
} else if (usernameFilter.length === 1) {
|
|
} else if (usernameFilter.length === 1) {
|
|
filter.push(`${usernameFilter[0]}`);
|
|
filter.push(`${usernameFilter[0]}`);
|
|
} else {
|
|
} else {
|
|
@@ -248,7 +247,7 @@ export default class LDAP {
|
|
userDn = `${this.options.User_Authentication_Field}=${username},${this.options.BaseDN}`;
|
|
userDn = `${this.options.User_Authentication_Field}=${username},${this.options.BaseDN}`;
|
|
}
|
|
}
|
|
|
|
|
|
- log_info('Binding with User', userDn);
|
|
|
|
|
|
+ Log.info('Binding with User', userDn);
|
|
|
|
|
|
this.bindSync(userDn, password);
|
|
this.bindSync(userDn, password);
|
|
this.domainBinded = true;
|
|
this.domainBinded = true;
|
|
@@ -263,7 +262,7 @@ export default class LDAP {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- log_info('Binding UserDN', this.options.Authentication_UserDN);
|
|
|
|
|
|
+ Log.info('Binding UserDN', this.options.Authentication_UserDN);
|
|
|
|
|
|
this.bindSync(this.options.Authentication_UserDN, this.options.Authentication_Password);
|
|
this.bindSync(this.options.Authentication_UserDN, this.options.Authentication_Password);
|
|
this.domainBinded = true;
|
|
this.domainBinded = true;
|
|
@@ -286,9 +285,9 @@ export default class LDAP {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- log_info('Searching user', username);
|
|
|
|
- log_debug('searchOptions', searchOptions);
|
|
|
|
- log_debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
+ Log.info('Searching user', username);
|
|
|
|
+ Log.debug('searchOptions', searchOptions);
|
|
|
|
+ Log.debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
if (page) {
|
|
if (page) {
|
|
return this.searchAllPaged(this.options.BaseDN, searchOptions, page);
|
|
return this.searchAllPaged(this.options.BaseDN, searchOptions, page);
|
|
@@ -326,9 +325,9 @@ export default class LDAP {
|
|
scope: 'sub',
|
|
scope: 'sub',
|
|
};
|
|
};
|
|
|
|
|
|
- log_info('Searching by id', id);
|
|
|
|
- log_debug('search filter', searchOptions.filter.toString());
|
|
|
|
- log_debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
+ Log.info('Searching by id', id);
|
|
|
|
+ Log.debug('search filter', searchOptions.filter.toString());
|
|
|
|
+ Log.debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
|
|
|
|
@@ -337,7 +336,7 @@ export default class LDAP {
|
|
}
|
|
}
|
|
|
|
|
|
if (result.length > 1) {
|
|
if (result.length > 1) {
|
|
- log_error('Search by id', id, 'returned', result.length, 'records');
|
|
|
|
|
|
+ Log.error('Search by id', id, 'returned', result.length, 'records');
|
|
}
|
|
}
|
|
|
|
|
|
return result[0];
|
|
return result[0];
|
|
@@ -351,9 +350,9 @@ export default class LDAP {
|
|
scope : this.options.User_Search_Scope || 'sub',
|
|
scope : this.options.User_Search_Scope || 'sub',
|
|
};
|
|
};
|
|
|
|
|
|
- log_info('Searching user', username);
|
|
|
|
- log_debug('searchOptions', searchOptions);
|
|
|
|
- log_debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
+ Log.info('Searching user', username);
|
|
|
|
+ Log.debug('searchOptions', searchOptions);
|
|
|
|
+ Log.debug('BaseDN', this.options.BaseDN);
|
|
|
|
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
|
|
|
|
@@ -362,7 +361,7 @@ export default class LDAP {
|
|
}
|
|
}
|
|
|
|
|
|
if (result.length > 1) {
|
|
if (result.length > 1) {
|
|
- log_error('Search by username', username, 'returned', result.length, 'records');
|
|
|
|
|
|
+ Log.error('Search by username', username, 'returned', result.length, 'records');
|
|
}
|
|
}
|
|
|
|
|
|
return result[0];
|
|
return result[0];
|
|
@@ -393,7 +392,7 @@ export default class LDAP {
|
|
scope : 'sub',
|
|
scope : 'sub',
|
|
};
|
|
};
|
|
|
|
|
|
- log_debug('Group list filter LDAP:', searchOptions.filter);
|
|
|
|
|
|
+ Log.debug('Group list filter LDAP:', searchOptions.filter);
|
|
|
|
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
|
|
|
|
@@ -406,7 +405,7 @@ export default class LDAP {
|
|
result.map((item) => {
|
|
result.map((item) => {
|
|
groups.push(item[grp_identifier]);
|
|
groups.push(item[grp_identifier]);
|
|
});
|
|
});
|
|
- log_debug(`Groups: ${groups.join(', ')}`);
|
|
|
|
|
|
+ Log.debug(`Groups: ${groups.join(', ')}`);
|
|
return groups;
|
|
return groups;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -441,7 +440,7 @@ export default class LDAP {
|
|
scope : 'sub',
|
|
scope : 'sub',
|
|
};
|
|
};
|
|
|
|
|
|
- log_debug('Group filter LDAP:', searchOptions.filter);
|
|
|
|
|
|
+ Log.debug('Group filter LDAP:', searchOptions.filter);
|
|
|
|
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
const result = this.searchAllSync(this.options.BaseDN, searchOptions);
|
|
|
|
|
|
@@ -475,7 +474,7 @@ export default class LDAP {
|
|
this.bindIfNecessary();
|
|
this.bindIfNecessary();
|
|
|
|
|
|
const processPage = ({ entries, title, end, next }) => {
|
|
const processPage = ({ entries, title, end, next }) => {
|
|
- log_info(title);
|
|
|
|
|
|
+ Log.info(title);
|
|
// Force LDAP idle to wait the record processing
|
|
// Force LDAP idle to wait the record processing
|
|
this.client._updateIdle(true);
|
|
this.client._updateIdle(true);
|
|
page(null, entries, {
|
|
page(null, entries, {
|
|
@@ -489,13 +488,13 @@ export default class LDAP {
|
|
|
|
|
|
this.client.search(BaseDN, options, (error, res) => {
|
|
this.client.search(BaseDN, options, (error, res) => {
|
|
if (error) {
|
|
if (error) {
|
|
- log_error(error);
|
|
|
|
|
|
+ Log.error(error);
|
|
page(error);
|
|
page(error);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
res.on('error', (error) => {
|
|
res.on('error', (error) => {
|
|
- log_error(error);
|
|
|
|
|
|
+ Log.error(error);
|
|
page(error);
|
|
page(error);
|
|
return;
|
|
return;
|
|
});
|
|
});
|
|
@@ -526,7 +525,7 @@ export default class LDAP {
|
|
end : true,
|
|
end : true,
|
|
});
|
|
});
|
|
} else if (entries.length) {
|
|
} else if (entries.length) {
|
|
- log_info('Page');
|
|
|
|
|
|
+ Log.info('Page');
|
|
processPage({
|
|
processPage({
|
|
entries,
|
|
entries,
|
|
title: 'Page',
|
|
title: 'Page',
|
|
@@ -555,13 +554,13 @@ export default class LDAP {
|
|
|
|
|
|
this.client.search(BaseDN, options, (error, res) => {
|
|
this.client.search(BaseDN, options, (error, res) => {
|
|
if (error) {
|
|
if (error) {
|
|
- log_error(error);
|
|
|
|
|
|
+ Log.error(error);
|
|
callback(error);
|
|
callback(error);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
res.on('error', (error) => {
|
|
res.on('error', (error) => {
|
|
- log_error(error);
|
|
|
|
|
|
+ Log.error(error);
|
|
callback(error);
|
|
callback(error);
|
|
return;
|
|
return;
|
|
});
|
|
});
|
|
@@ -573,25 +572,25 @@ export default class LDAP {
|
|
});
|
|
});
|
|
|
|
|
|
res.on('end', () => {
|
|
res.on('end', () => {
|
|
- log_info('Search result count', entries.length);
|
|
|
|
|
|
+ Log.info('Search result count', entries.length);
|
|
callback(null, entries);
|
|
callback(null, entries);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
authSync(dn, password) {
|
|
authSync(dn, password) {
|
|
- log_info('Authenticating', dn);
|
|
|
|
|
|
+ Log.info('Authenticating', dn);
|
|
|
|
|
|
try {
|
|
try {
|
|
if (password === '') {
|
|
if (password === '') {
|
|
throw new Error('Password is not provided');
|
|
throw new Error('Password is not provided');
|
|
}
|
|
}
|
|
this.bindSync(dn, password);
|
|
this.bindSync(dn, password);
|
|
- log_info('Authenticated', dn);
|
|
|
|
|
|
+ Log.info('Authenticated', dn);
|
|
return true;
|
|
return true;
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- log_info('Not authenticated', dn);
|
|
|
|
- log_debug('error', error);
|
|
|
|
|
|
+ Log.info('Not authenticated', dn);
|
|
|
|
+ Log.debug('error', error);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -599,7 +598,7 @@ export default class LDAP {
|
|
disconnect() {
|
|
disconnect() {
|
|
this.connected = false;
|
|
this.connected = false;
|
|
this.domainBinded = false;
|
|
this.domainBinded = false;
|
|
- log_info('Disconecting');
|
|
|
|
|
|
+ Log.info('Disconecting');
|
|
this.client.unbind();
|
|
this.client.unbind();
|
|
}
|
|
}
|
|
}
|
|
}
|