testConnection.js 977 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import LDAP from './ldap';
  2. Meteor.methods({
  3. ldap_test_connection() {
  4. const user = Meteor.user();
  5. if (!user) {
  6. throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'ldap_test_connection' });
  7. }
  8. //TODO: This needs to be fixed - security issue -> alanning:meteor-roles
  9. //if (!RocketChat.authz.hasRole(user._id, 'admin')) {
  10. // throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'ldap_test_connection' });
  11. //}
  12. if (LDAP.settings_get(LDAP_ENABLE) !== true) {
  13. throw new Meteor.Error('LDAP_disabled');
  14. }
  15. let ldap;
  16. try {
  17. ldap = new LDAP();
  18. ldap.connectSync();
  19. } catch (error) {
  20. console.log(error);
  21. throw new Meteor.Error(error.message);
  22. }
  23. try {
  24. ldap.bindIfNecessary();
  25. } catch (error) {
  26. throw new Meteor.Error(error.name || error.message);
  27. }
  28. return {
  29. message: 'Connection_success',
  30. params: [],
  31. };
  32. },
  33. });