<commit_before>import { LDAP } from 'meteor/babrahams:accounts-ldap';
import { Meteor } from 'meteor/meteor';

let allowSelfSignedTLS = Meteor.settings.ldap.allowSelfSignedTLS;
if (allowSelfSignedTLS) {
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
}

LDAP.searchField = Meteor.settings.ldap.searchDn;
LDAP.searchValueType = 'username';

function ldapEnabled() {
    return !!Meteor.settings &&
        !!Meteor.settings.ldap &&
        Meteor.settings.ldap.enabled;
}

Meteor.startup(() => {
    // propagate the ldap enabled flag to the clients
    Meteor.settings.public.ldapEnabled = ldapEnabled();
});

LDAP.bindValue = function (usernameOrEmail, isEmailAddress) {
    if (!ldapEnabled()) {
        return '';
    }

    const serverDn = Meteor.settings.ldap.serverDn;
    const searchDn = Meteor.settings.ldap.searchDn;

    if (!serverDn || !searchDn) {
        return '';
    }

    const username = (isEmailAddress) ? usernameOrEmail.split('@')[0] : usernameOrEmail;

    return [searchDn, '=', username, ',', serverDn].join('');
};

LDAP.filter = function (isEmailAddress, usernameOrEmail) {
    if (!ldapEnabled()) {
        return '';
    }

    const searchField = Meteor.settings.ldap.searchDn;

    if (!searchField) {
        return '';
    }

    const searchValue = (isEmailAddress) ? usernameOrEmail.split('@')[0] : usernameOrEmail;
    const filter = Meteor.settings.ldap.searchFilter || "";

    return ['(&(', searchField, '=', searchValue, ')', filter ,')'].join('');
};

LDAP.log = function (message) {
    // The ldap plugin prints the user password in clear text in the log
    // The log leaking the password always starts with 'Creating user'
    // so we filter it here
    if (message.indexOf('Creating user') === 0) {<commit_msg>Fix issue with ldap logins<commit_after>import { LDAP } from 'meteor/babrahams:accounts-ldap';
import { Meteor } from 'meteor/meteor';

let allowSelfSignedTLS = Meteor.settings.ldap.allowSelfSignedTLS;
if (allowSelfSignedTLS) {
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
}

LDAP.searchField = Meteor.settings.ldap.searchDn;
LDAP.searchValueType = 'username';

function ldapEnabled() {
    return !!Meteor.settings &&
        !!Meteor.settings.ldap &&
        Meteor.settings.ldap.enabled;
}

Meteor.startup(() => {
    // propagate the ldap enabled flag to the clients
    Meteor.settings.public.ldapEnabled = ldapEnabled();
});

LDAP.bindValue = function (usernameOrEmail, isEmailAddress) {
    if (!ldapEnabled()) {
        return '';
    }

    const serverDn = Meteor.settings.ldap.serverDn;
    const searchDn = Meteor.settings.ldap.searchDn;

    if (!serverDn || !searchDn) {
        return '';
    }

    const username = (isEmailAddress) ? usernameOrEmail.split('@')[0] : usernameOrEmail;

    return [searchDn, '=', username, ',', serverDn].join('');
};

LDAP.filter = function (isEmailAddress, usernameOrEmail) {
    if (!ldapEnabled()) {
        return '';
    }

    const searchField = Meteor.settings.ldap.searchDn;

    if (!searchField) {
        return '';
    }

    const searchValue = (isEmailAddress) ? usernameOrEmail.split('@')[0] : usernameOrEmail;
    const filter = Meteor.settings.ldap.searchFilter || "";

    return ['(&(', searchField, '=', searchValue, ')', filter ,')'].join('');
};

LDAP.addFields = function (/*person - the ldap entry for that user*/) {
    // this = ldap request object

    return {
        // overwrite the password to prevent local logins
        password: ''
    };
};

LDAP.log = function (message) {
    // The ldap plugin prints the user password in clear text in the log
    // The log leaking the password always starts with 'Creating user'
    // so we filter it here
    if (message.indexOf('Creating user') === 0) {
{'fraction_non_alphanumeric': 0.14262863236470275, 'fraction_numerical': 0.0021327645961077045, 'mean_word_length': 3.3476245654692933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6763844', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1191, 'n_words': 272}