Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index f96b065..baa4631 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1c3d=['Strategy','moment','activedirectory2','bluebird','../../mysqldb','../../config/environment','activedirectory','undefined','baseDN','url','domain','error','inspect','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','findOne','adSsoEnabled','blockDuration','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','password','salt','role','disabled','blocked','online','admin','user','then','name','blockedAt','add','minutes','clearBlockUser','getLicense','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','use','User','passport','passport-local'];(function(_0x1352f0,_0x4cd565){var _0x1c2a82=function(_0x2a9b63){while(--_0x2a9b63){_0x1352f0['push'](_0x1352f0['shift']());}};_0x1c2a82(++_0x4cd565);}(_0x1c3d,0xdf));var _0xd1c3=function(_0x19362a,_0x126dfe){_0x19362a=_0x19362a-0x0;var _0x39c212=_0x1c3d[_0x19362a];return _0x39c212;};'use strict';var passport=require(_0xd1c3('0x0'));var LocalStrategy=require(_0xd1c3('0x1'))[_0xd1c3('0x2')];var moment=require(_0xd1c3('0x3'));var ActiveDirectory=require(_0xd1c3('0x4'));var BPromise=require(_0xd1c3('0x5'));var util=require('util');var db=require(_0xd1c3('0x6'))['db'];var authService=require('../../components/auth/service');var utils=require('../../config/utils');var config=require(_0xd1c3('0x7'));var logger=require('../../config/logger')('api');function isActiveDirectoryConfigured(_0x36b279){var _0x1b1808=![];if(typeof _0x36b279[_0xd1c3('0x8')]!==_0xd1c3('0x9')){_0x1b1808=_0x36b279[_0xd1c3('0x8')][_0xd1c3('0xa')]&&_0x36b279['activedirectory'][_0xd1c3('0xb')]&&_0x36b279[_0xd1c3('0x8')][_0xd1c3('0xc')];}return _0x1b1808;}function adAuthenticate(_0x566dbe,_0x2ffe31,_0x5472f0){return new BPromise(function(_0xbcb6ca,_0x2f9f21){try{var _0x1990a4=new ActiveDirectory(_0x566dbe);_0x1990a4['authenticate'](_0x2ffe31,_0x5472f0,function(_0x1a6dcd,_0x461e38){if(_0x1a6dcd){logger[_0xd1c3('0xd')]('Error\x20authenticate\x20%s:\x20%s',_0x2ffe31,util[_0xd1c3('0xe')](_0x1a6dcd,{'showHidden':![],'depth':null}));_0x2f9f21('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x461e38){logger['error']('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x2ffe31);_0x2f9f21('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{_0xbcb6ca(_0x461e38);}});}catch(_0x442400){_0x2f9f21(_0x442400);}});}function ActiveDirectoryAuthenticate(_0x27b987,_0x4d1f9f,_0x2a1991,_0x1cc142){var _0x2462bf,_0x9c985b;if(!isActiveDirectoryConfigured(config)){logger[_0xd1c3('0xd')](_0xd1c3('0xf'),_0x4d1f9f);return _0x1cc142(null,![],{'message':_0xd1c3('0x10')});}return db['Setting'][_0xd1c3('0x11')]({'where':{'id':0x1},'attributes':[_0xd1c3('0x12'),_0xd1c3('0x13')],'raw':!![]})['then'](function(_0x5105b1){_0x2462bf=_0x5105b1;if(!_0x2462bf['adSsoEnabled']){logger[_0xd1c3('0xd')](_0xd1c3('0x14'),_0x4d1f9f);throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return _0x27b987['findOne']({'attributes':['id','name',_0xd1c3('0x15'),_0xd1c3('0x16'),_0xd1c3('0x17'),_0xd1c3('0x18'),_0xd1c3('0x19'),'blockedAt',_0xd1c3('0x1a')],'where':{'name':_0x4d1f9f,'role':{'$or':[_0xd1c3('0x1b'),_0xd1c3('0x1c'),'agent']},'adSsoEnabled':!![]}});})[_0xd1c3('0x1d')](function(_0x43023e){if(!_0x43023e||_0x43023e&&_0x43023e[_0xd1c3('0x1e')]!==_0x4d1f9f){throw new Error(_0xd1c3('0x10'));}_0x9c985b=_0x43023e;var _0x26a097=_0x9c985b[_0xd1c3('0x1e')]+'@'+config[_0xd1c3('0x8')]['domain'];return adAuthenticate(config[_0xd1c3('0x8')],_0x26a097,_0x2a1991);})[_0xd1c3('0x1d')](function(_0x35abbb){if(_0x9c985b[_0xd1c3('0x18')]){throw new Error(_0xd1c3('0x10'));}if(_0x2462bf[_0xd1c3('0x13')]>0x0){if(_0x9c985b['blocked']){if(moment(_0x9c985b[_0xd1c3('0x1f')])[_0xd1c3('0x20')](_0x2462bf[_0xd1c3('0x13')],_0xd1c3('0x21'))>moment()){throw new Error(_0xd1c3('0x10'));}return utils[_0xd1c3('0x22')](_0x9c985b,0x0,![],null)[_0xd1c3('0x1d')](function(){return utils['getLicense'](_0x9c985b);})[_0xd1c3('0x1d')](function(){return _0x1cc142(null,_0x9c985b);});}else{return utils[_0xd1c3('0x23')](_0x9c985b)[_0xd1c3('0x1d')](function(){return _0x1cc142(null,_0x9c985b);});}}else{return utils['getLicense'](_0x9c985b)[_0xd1c3('0x1d')](function(){return _0x1cc142(null,_0x9c985b);});}})['catch'](function(_0x49ac0f){return _0x1cc142(null,![],_0x49ac0f);});}function handleError(_0x16aaec,_0x47ad3d,_0x44181d){return _0x16aaec['status'](_0x47ad3d||0x1f4)[_0xd1c3('0x24')]({'message':_0x44181d?_0x44181d[_0xd1c3('0x25')]||_0x44181d:''});}exports[_0xd1c3('0x26')]=function(_0x7ae715,_0x592aa0,_0x15be67){passport['authenticate'](_0xd1c3('0x27'),function(_0x35e795,_0x468857,_0x70b52b){var _0x4d3762=_0x35e795||_0x70b52b;if(_0x4d3762){return handleError(_0x592aa0,0x191,_0x4d3762);}if(!_0x468857){return handleError(_0x592aa0,0x194,{'message':_0xd1c3('0x28')});}else{var _0x1f6dbe={'payload':{'id':_0x468857['id'],'role':_0x468857['role']},'options':{'expiresIn':0x15180}};return authService[_0xd1c3('0x29')](_0x1f6dbe)['then'](function(_0x5924e2){_0x592aa0[_0xd1c3('0x2a')]({'id':_0x468857['id'],'token':_0x5924e2,'statusCall':'','isAlreadyLogged':_0x468857['online']});});}})(_0x7ae715,_0x592aa0,_0x15be67);};passport[_0xd1c3('0x2b')](_0xd1c3('0x27'),new LocalStrategy({'usernameField':_0xd1c3('0x1e'),'passwordField':'password'},function(_0x12d4ca,_0x3b8ad9,_0x5bca3c){return ActiveDirectoryAuthenticate(db[_0xd1c3('0x2c')],_0x12d4ca,_0x3b8ad9,_0x5bca3c);}));
\ No newline at end of file
+var _0xac20=['catch','status','send','message','login','ad-login','role','signToken','json','use','passport','passport-local','Strategy','activedirectory2','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','activedirectory','undefined','baseDN','domain','authenticate','error','Error\x20authenticate\x20%s:\x20%s','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','Setting','findOne','adSsoEnabled','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','disabled','blocked','online','user','agent','blockedAt','add','minutes','clearBlockUser','getLicense'];(function(_0x485038,_0x3e26e8){var _0xa87ace=function(_0x1cf247){while(--_0x1cf247){_0x485038['push'](_0x485038['shift']());}};_0xa87ace(++_0x3e26e8);}(_0xac20,0x9a));var _0x0ac2=function(_0x555f67,_0x57ad68){_0x555f67=_0x555f67-0x0;var _0x5bf0ac=_0xac20[_0x555f67];return _0x5bf0ac;};'use strict';var passport=require(_0x0ac2('0x0'));var LocalStrategy=require(_0x0ac2('0x1'))[_0x0ac2('0x2')];var moment=require('moment');var ActiveDirectory=require(_0x0ac2('0x3'));var BPromise=require('bluebird');var util=require(_0x0ac2('0x4'));var db=require(_0x0ac2('0x5'))['db'];var authService=require(_0x0ac2('0x6'));var utils=require(_0x0ac2('0x7'));var config=require(_0x0ac2('0x8'));var logger=require('../../config/logger')('api');function isActiveDirectoryConfigured(_0x3244fc){var _0x84bdac=![];if(typeof _0x3244fc[_0x0ac2('0x9')]!==_0x0ac2('0xa')){_0x84bdac=_0x3244fc[_0x0ac2('0x9')][_0x0ac2('0xb')]&&_0x3244fc[_0x0ac2('0x9')]['url']&&_0x3244fc[_0x0ac2('0x9')][_0x0ac2('0xc')];}return _0x84bdac;}function adAuthenticate(_0x2a4423,_0x5a80b3,_0x8e4c1b){return new BPromise(function(_0x187d1e,_0x31eadb){try{var _0x2c8b0a=new ActiveDirectory(_0x2a4423);_0x2c8b0a[_0x0ac2('0xd')](_0x5a80b3,_0x8e4c1b,function(_0x2b2fcd,_0x5572f5){if(_0x2b2fcd){logger[_0x0ac2('0xe')](_0x0ac2('0xf'),_0x5a80b3,util[_0x0ac2('0x10')](_0x2b2fcd,{'showHidden':![],'depth':null}));_0x31eadb(_0x0ac2('0x11'));}else if(!_0x5572f5){logger[_0x0ac2('0xe')](_0x0ac2('0x12'),_0x5a80b3);_0x31eadb(_0x0ac2('0x11'));}else{_0x187d1e(_0x5572f5);}});}catch(_0x472681){_0x31eadb(_0x472681);}});}function ActiveDirectoryAuthenticate(_0x2c277b,_0x28c0af,_0x287821,_0x11fbda){var _0x50a2ed,_0x149434;if(!isActiveDirectoryConfigured(config)){logger[_0x0ac2('0xe')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x28c0af);return _0x11fbda(null,![],{'message':_0x0ac2('0x11')});}return db[_0x0ac2('0x13')][_0x0ac2('0x14')]({'where':{'id':0x1},'attributes':[_0x0ac2('0x15'),_0x0ac2('0x16')],'raw':!![]})[_0x0ac2('0x17')](function(_0x161378){_0x50a2ed=_0x161378;if(!_0x50a2ed[_0x0ac2('0x15')]){logger[_0x0ac2('0xe')](_0x0ac2('0x18'),_0x28c0af);throw new Error(_0x0ac2('0x11'));}return _0x2c277b['findOne']({'attributes':['id',_0x0ac2('0x19'),_0x0ac2('0x1a'),_0x0ac2('0x1b'),'role',_0x0ac2('0x1c'),_0x0ac2('0x1d'),'blockedAt',_0x0ac2('0x1e')],'where':{'name':_0x28c0af,'role':{'$or':['admin',_0x0ac2('0x1f'),_0x0ac2('0x20')]},'adSsoEnabled':!![]}});})[_0x0ac2('0x17')](function(_0x1f62d3){if(!_0x1f62d3||_0x1f62d3&&_0x1f62d3[_0x0ac2('0x19')]!==_0x28c0af){throw new Error(_0x0ac2('0x11'));}_0x149434=_0x1f62d3;var _0x68e20=_0x149434[_0x0ac2('0x19')]+'@'+config[_0x0ac2('0x9')][_0x0ac2('0xc')];return adAuthenticate(config[_0x0ac2('0x9')],_0x68e20,_0x287821);})['then'](function(_0x3fdcd6){if(_0x149434[_0x0ac2('0x1c')]){throw new Error(_0x0ac2('0x11'));}if(_0x50a2ed['blockDuration']>0x0){if(_0x149434[_0x0ac2('0x1d')]){if(moment(_0x149434[_0x0ac2('0x21')])[_0x0ac2('0x22')](_0x50a2ed[_0x0ac2('0x16')],_0x0ac2('0x23'))>moment()){throw new Error(_0x0ac2('0x11'));}return utils[_0x0ac2('0x24')](_0x149434,0x0,![],null)[_0x0ac2('0x17')](function(){return utils[_0x0ac2('0x25')](_0x149434);})['then'](function(){return _0x11fbda(null,_0x149434);});}else{return utils[_0x0ac2('0x25')](_0x149434)['then'](function(){return _0x11fbda(null,_0x149434);});}}else{return utils['getLicense'](_0x149434)[_0x0ac2('0x17')](function(){return _0x11fbda(null,_0x149434);});}})[_0x0ac2('0x26')](function(_0x5cded3){return _0x11fbda(null,![],_0x5cded3);});}function handleError(_0x486aa7,_0x2c0979,_0x42f8bc){return _0x486aa7[_0x0ac2('0x27')](_0x2c0979||0x1f4)[_0x0ac2('0x28')]({'message':_0x42f8bc?_0x42f8bc[_0x0ac2('0x29')]||_0x42f8bc:''});}exports[_0x0ac2('0x2a')]=function(_0x1236ac,_0x54646b,_0x32f7af){passport[_0x0ac2('0xd')](_0x0ac2('0x2b'),function(_0x44bfae,_0x2ed07d,_0x4743ba){var _0x41f46b=_0x44bfae||_0x4743ba;if(_0x41f46b){return handleError(_0x54646b,0x191,_0x41f46b);}if(!_0x2ed07d){return handleError(_0x54646b,0x194,{'message':'Something\x20went\x20wrong,\x20please\x20try\x20again.'});}else{var _0x128125={'payload':{'id':_0x2ed07d['id'],'role':_0x2ed07d[_0x0ac2('0x2c')]},'options':{'expiresIn':0x15180}};return authService[_0x0ac2('0x2d')](_0x128125)['then'](function(_0xa46175){_0x54646b[_0x0ac2('0x2e')]({'id':_0x2ed07d['id'],'token':_0xa46175,'statusCall':'','isAlreadyLogged':_0x2ed07d[_0x0ac2('0x1e')]});});}})(_0x1236ac,_0x54646b,_0x32f7af);};passport[_0x0ac2('0x2f')]('ad-login',new LocalStrategy({'usernameField':_0x0ac2('0x19'),'passwordField':_0x0ac2('0x1a')},function(_0x5d7cd4,_0x548f50,_0x1e6214){return ActiveDirectoryAuthenticate(db['User'],_0x5d7cd4,_0x548f50,_0x1e6214);}));
\ No newline at end of file