Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index baa4631..fc5ad61 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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
+var _0x2aa0=['add','minutes','clearBlockUser','status','send','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','json','use','User','passport','passport-local','moment','activedirectory2','util','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','activedirectory','undefined','baseDN','url','authenticate','error','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','adSsoEnabled','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','disabled','blockedAt','online','admin','user','agent','domain','blocked'];(function(_0x531cb8,_0x8ef36f){var _0x5cf297=function(_0x45acb4){while(--_0x45acb4){_0x531cb8['push'](_0x531cb8['shift']());}};_0x5cf297(++_0x8ef36f);}(_0x2aa0,0x6c));var _0x02aa=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0x2aa0[_0x57b54c];return _0x59cc19;};'use strict';var passport=require(_0x02aa('0x0'));var LocalStrategy=require(_0x02aa('0x1'))['Strategy'];var moment=require(_0x02aa('0x2'));var ActiveDirectory=require(_0x02aa('0x3'));var BPromise=require('bluebird');var util=require(_0x02aa('0x4'));var db=require('../../mysqldb')['db'];var authService=require(_0x02aa('0x5'));var utils=require(_0x02aa('0x6'));var config=require(_0x02aa('0x7'));var logger=require(_0x02aa('0x8'))(_0x02aa('0x9'));function isActiveDirectoryConfigured(_0x386694){var _0x17e58f=![];if(typeof _0x386694[_0x02aa('0xa')]!==_0x02aa('0xb')){_0x17e58f=_0x386694[_0x02aa('0xa')][_0x02aa('0xc')]&&_0x386694['activedirectory'][_0x02aa('0xd')]&&_0x386694[_0x02aa('0xa')]['domain'];}return _0x17e58f;}function adAuthenticate(_0x6b4d7f,_0x1590b1,_0x410540){return new BPromise(function(_0x4a9912,_0x5da83a){try{var _0x26d443=new ActiveDirectory(_0x6b4d7f);_0x26d443[_0x02aa('0xe')](_0x1590b1,_0x410540,function(_0x2bc880,_0x1e6be1){if(_0x2bc880){logger[_0x02aa('0xf')]('Error\x20authenticate\x20%s:\x20%s',_0x1590b1,util['inspect'](_0x2bc880,{'showHidden':![],'depth':null}));_0x5da83a('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x1e6be1){logger[_0x02aa('0xf')](_0x02aa('0x10'),_0x1590b1);_0x5da83a(_0x02aa('0x11'));}else{_0x4a9912(_0x1e6be1);}});}catch(_0x24c2ce){_0x5da83a(_0x24c2ce);}});}function ActiveDirectoryAuthenticate(_0x2a00da,_0x191bd3,_0x119662,_0x32787){var _0x14988e,_0x3a0f8c;if(!isActiveDirectoryConfigured(config)){logger[_0x02aa('0xf')](_0x02aa('0x12'),_0x191bd3);return _0x32787(null,![],{'message':_0x02aa('0x11')});}return db[_0x02aa('0x13')][_0x02aa('0x14')]({'where':{'id':0x1},'attributes':[_0x02aa('0x15'),_0x02aa('0x16')],'raw':!![]})[_0x02aa('0x17')](function(_0xb0bc12){_0x14988e=_0xb0bc12;if(!_0x14988e[_0x02aa('0x15')]){logger['error'](_0x02aa('0x18'),_0x191bd3);throw new Error(_0x02aa('0x11'));}return _0x2a00da['findOne']({'attributes':['id',_0x02aa('0x19'),_0x02aa('0x1a'),_0x02aa('0x1b'),'role',_0x02aa('0x1c'),'blocked',_0x02aa('0x1d'),_0x02aa('0x1e')],'where':{'name':_0x191bd3,'role':{'$or':[_0x02aa('0x1f'),_0x02aa('0x20'),_0x02aa('0x21')]},'adSsoEnabled':!![]}});})['then'](function(_0xf74047){if(!_0xf74047||_0xf74047&&_0xf74047[_0x02aa('0x19')]!==_0x191bd3){throw new Error(_0x02aa('0x11'));}_0x3a0f8c=_0xf74047;var _0x1dcc4e=_0x3a0f8c[_0x02aa('0x19')]+'@'+config[_0x02aa('0xa')][_0x02aa('0x22')];return adAuthenticate(config[_0x02aa('0xa')],_0x1dcc4e,_0x119662);})[_0x02aa('0x17')](function(_0x3a4cf5){if(_0x3a0f8c[_0x02aa('0x1c')]){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}if(_0x14988e[_0x02aa('0x16')]>0x0){if(_0x3a0f8c[_0x02aa('0x23')]){if(moment(_0x3a0f8c[_0x02aa('0x1d')])[_0x02aa('0x24')](_0x14988e[_0x02aa('0x16')],_0x02aa('0x25'))>moment()){throw new Error(_0x02aa('0x11'));}return utils[_0x02aa('0x26')](_0x3a0f8c,0x0,![],null)[_0x02aa('0x17')](function(){return utils['getLicense'](_0x3a0f8c);})[_0x02aa('0x17')](function(){return _0x32787(null,_0x3a0f8c);});}else{return utils['getLicense'](_0x3a0f8c)[_0x02aa('0x17')](function(){return _0x32787(null,_0x3a0f8c);});}}else{return utils['getLicense'](_0x3a0f8c)['then'](function(){return _0x32787(null,_0x3a0f8c);});}})['catch'](function(_0x57b1fc){return _0x32787(null,![],_0x57b1fc);});}function handleError(_0x20cf72,_0x1ccf22,_0xf93497){return _0x20cf72[_0x02aa('0x27')](_0x1ccf22||0x1f4)[_0x02aa('0x28')]({'message':_0xf93497?_0xf93497['message']||_0xf93497:''});}exports[_0x02aa('0x29')]=function(_0x2d4883,_0x444b79,_0x3a7508){passport[_0x02aa('0xe')](_0x02aa('0x2a'),function(_0x1fc70b,_0x22aac4,_0x125bee){var _0x5ecf18=_0x1fc70b||_0x125bee;if(_0x5ecf18){return handleError(_0x444b79,0x191,_0x5ecf18);}if(!_0x22aac4){return handleError(_0x444b79,0x194,{'message':_0x02aa('0x2b')});}else{var _0x560bf2={'payload':{'id':_0x22aac4['id'],'role':_0x22aac4[_0x02aa('0x2c')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x560bf2)[_0x02aa('0x17')](function(_0x592f60){_0x444b79[_0x02aa('0x2d')]({'id':_0x22aac4['id'],'token':_0x592f60,'statusCall':'','isAlreadyLogged':_0x22aac4[_0x02aa('0x1e')]});});}})(_0x2d4883,_0x444b79,_0x3a7508);};passport[_0x02aa('0x2e')]('ad-login',new LocalStrategy({'usernameField':'name','passwordField':'password'},function(_0x18f6e5,_0x4ee46c,_0x236418){return ActiveDirectoryAuthenticate(db[_0x02aa('0x2f')],_0x18f6e5,_0x4ee46c,_0x236418);}));
\ No newline at end of file