Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. var express = require('express');
  2. var router = express.Router();
  3. var tools = require('./authenticateUser');
  4.  
  5. router.post('/authenticateUser', function(req, res) {
  6. // In the below line i am calling the method which
  7. // should return the userDN (a string)
  8. tools.searchUser(req.body.user, req.body.passwd);
  9.  
  10. res.render('home.jade');
  11.  
  12. });
  13.  
  14. module.exports = {
  15. searchUser : function (username, password) {
  16. adminDN = *************;
  17. adminPassword = '*********';
  18. baseDN = '***';
  19.  
  20.  
  21. var ldap = require('ldapjs');
  22. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  23. var adminClient = ldap.createClient({
  24. url: '*******'
  25.  
  26. });
  27. var opts = {
  28. filter: '(&(objectClass=userProxyFull)(sAMAccountName=' + username + '))',
  29. scope: 'sub',
  30. attribute: ['sAMAccountName']
  31.  
  32. };
  33.  
  34.  
  35. console.log('--- going to try to connect user ---');
  36.  
  37. try {
  38. adminClient.bind(adminDN, adminPassword, function (error) {
  39. if (error) {
  40. console.log(error.message);
  41. adminClient.unbind(function (error) {
  42. if (error) {
  43. console.log(error.message);
  44. } else {
  45. console.log('adminClient disconnected');
  46. }
  47. });
  48. } else {
  49.  
  50. // Searching Client ID in LDS
  51.  
  52. adminClient.search(baseDN, opts, function (error, search) {
  53. console.log('Searching.....' + userDN);
  54.  
  55. search.on('searchEntry', function (entry) {
  56. if (entry.object) {
  57. // Here i need to return the object back
  58. //to the router.js from where i call in a synchronous way
  59.  
  60. adminClient.unbind(function (error) {
  61. if (error) {
  62. console.log(error.message);
  63. }
  64. });
  65.  
  66.  
  67. }
  68. });
  69.  
  70. search.on('error', function (error) {
  71. console.error('error: ' + error.message);
  72. });
  73.  
  74.  
  75. });
  76. }
  77. });
  78. } catch (error) {
  79. console.log(error);
  80. adminClient.unbind(function (error) {
  81. if (error) {
  82. console.log(error.message);
  83. } else {
  84. console.log('client disconnected');
  85. }
  86. });
  87. } finally {
  88. adminClient.unbind(function (error) {
  89. if (error) {
  90. console.log(error.message);
  91. } else {
  92. console.log('client disconnected');
  93. }
  94. });
  95. }
  96.  
  97. },
  98.  
  99.  
  100.  
  101.  
  102.  
  103. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement