summaryrefslogtreecommitdiffstats
path: root/packages/wekan-ldap/server/testConnection.js
blob: 02866ce54ac13209166b67bdbe9d608b9625e8f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import LDAP from './ldap';

Meteor.methods({
  ldap_test_connection() {
    const user = Meteor.user();
    if (!user) {
      throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'ldap_test_connection' });
    }

    //TODO: This needs to be fixed - security issue -> alanning:meteor-roles
    //if (!RocketChat.authz.hasRole(user._id, 'admin')) {
    //	throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'ldap_test_connection' });
    //}

    if (LDAP.settings_get(LDAP_ENABLE) !== true) {
      throw new Meteor.Error('LDAP_disabled');
    }

    let ldap;
    try {
      ldap = new LDAP();
      ldap.connectSync();
    } catch (error) {
      console.log(error);
      throw new Meteor.Error(error.message);
    }

    try {
      ldap.bindIfNecessary();
    } catch (error) {
      throw new Meteor.Error(error.name || error.message);
    }

    return {
      message: 'Connection_success',
      params: [],
    };
  },
});