Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 9c6f3a8..c6c427f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa00e=['blockedAt','online','admin','user','agent','then','minutes','clearBlockUser','getLicense','catch','status','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','json','User','passport','Strategy','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','activedirectory','undefined','baseDN','url','domain','authenticate','Error\x20authenticate\x20%s:\x20%s','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','error','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','Setting','adSsoEnabled','blockDuration','name','password','salt','disabled','blocked'];(function(_0x3b5a5c,_0x1208c6){var _0x5699b5=function(_0x4e64a6){while(--_0x4e64a6){_0x3b5a5c['push'](_0x3b5a5c['shift']());}};_0x5699b5(++_0x1208c6);}(_0xa00e,0xd4));var _0xea00=function(_0x5eb2e1,_0x5a382f){_0x5eb2e1=_0x5eb2e1-0x0;var _0x4efb8d=_0xa00e[_0x5eb2e1];return _0x4efb8d;};'use strict';var passport=require(_0xea00('0x0'));var LocalStrategy=require('passport-local')[_0xea00('0x1')];var moment=require('moment');var ActiveDirectory=require(_0xea00('0x2'));var BPromise=require(_0xea00('0x3'));var util=require(_0xea00('0x4'));var db=require(_0xea00('0x5'))['db'];var authService=require(_0xea00('0x6'));var utils=require(_0xea00('0x7'));var config=require(_0xea00('0x8'));var logger=require('../../config/logger')('api');function isActiveDirectoryConfigured(_0x5027bb){var _0x560ee8=![];if(typeof _0x5027bb[_0xea00('0x9')]!==_0xea00('0xa')){_0x560ee8=_0x5027bb[_0xea00('0x9')][_0xea00('0xb')]&&_0x5027bb[_0xea00('0x9')][_0xea00('0xc')]&&_0x5027bb[_0xea00('0x9')][_0xea00('0xd')];}return _0x560ee8;}function adAuthenticate(_0x36c4e8,_0x1d3e79,_0x2f2d8e){return new BPromise(function(_0x32e2ca,_0xac2689){try{var _0x1177cb=new ActiveDirectory(_0x36c4e8);_0x1177cb[_0xea00('0xe')](_0x1d3e79,_0x2f2d8e,function(_0x1d4d29,_0x20a520){if(_0x1d4d29){logger['error'](_0xea00('0xf'),_0x1d3e79,util[_0xea00('0x10')](_0x1d4d29,{'showHidden':![],'depth':null}));_0xac2689(_0xea00('0x11'));}else if(!_0x20a520){logger[_0xea00('0x12')](_0xea00('0x13'),_0x1d3e79);_0xac2689(_0xea00('0x11'));}else{_0x32e2ca(_0x20a520);}});}catch(_0x52523b){_0xac2689(_0x52523b);}});}function ActiveDirectoryAuthenticate(_0x2ae683,_0x19500a,_0x5cf9d8,_0x1764a6){var _0x53b0e4,_0xf01096;if(!isActiveDirectoryConfigured(config)){logger[_0xea00('0x12')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x19500a);return _0x1764a6(null,![],{'message':_0xea00('0x11')});}return db[_0xea00('0x14')]['findOne']({'where':{'id':0x1},'attributes':[_0xea00('0x15'),_0xea00('0x16')],'raw':!![]})['then'](function(_0x3c6b31){_0x53b0e4=_0x3c6b31;if(!_0x53b0e4[_0xea00('0x15')]){logger['error']('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled',_0x19500a);throw new Error(_0xea00('0x11'));}return _0x2ae683['findOne']({'logging':!![],'attributes':['id',_0xea00('0x17'),_0xea00('0x18'),_0xea00('0x19'),'role',_0xea00('0x1a'),_0xea00('0x1b'),_0xea00('0x1c'),_0xea00('0x1d')],'where':{'name':_0x19500a,'role':{'$or':[_0xea00('0x1e'),_0xea00('0x1f'),_0xea00('0x20')]},'adSsoEnabled':!![]}});})[_0xea00('0x21')](function(_0x1f21fe){if(!_0x1f21fe||_0x1f21fe&&_0x1f21fe[_0xea00('0x17')]!==_0x19500a){throw new Error(_0xea00('0x11'));}_0xf01096=_0x1f21fe;var _0x462f4d=_0xf01096[_0xea00('0x17')]+'@'+config['activedirectory'][_0xea00('0xd')];return adAuthenticate(config[_0xea00('0x9')],_0x462f4d,_0x5cf9d8);})['then'](function(_0x3490ef){if(_0xf01096[_0xea00('0x1a')]){throw new Error(_0xea00('0x11'));}if(_0x53b0e4[_0xea00('0x16')]>0x0){if(_0xf01096['blocked']){if(moment(_0xf01096[_0xea00('0x1c')])['add'](_0x53b0e4[_0xea00('0x16')],_0xea00('0x22'))>moment()){throw new Error(_0xea00('0x11'));}return utils[_0xea00('0x23')](_0xf01096,0x0,![],null)[_0xea00('0x21')](function(){return utils['getLicense'](_0xf01096);})[_0xea00('0x21')](function(){return _0x1764a6(null,_0xf01096);});}else{return utils[_0xea00('0x24')](_0xf01096)[_0xea00('0x21')](function(){return _0x1764a6(null,_0xf01096);});}}else{return utils[_0xea00('0x24')](_0xf01096)['then'](function(){return _0x1764a6(null,_0xf01096);});}})[_0xea00('0x25')](function(_0x5ab650){return _0x1764a6(null,![],_0x5ab650);});}function handleError(_0x681296,_0x31758e,_0x45794b){return _0x681296[_0xea00('0x26')](_0x31758e||0x1f4)[_0xea00('0x27')]({'message':_0x45794b?_0x45794b[_0xea00('0x28')]||_0x45794b:''});}exports[_0xea00('0x29')]=function(_0x51358d,_0x379ef0,_0x3f1f63){passport['authenticate'](_0xea00('0x2a'),function(_0x3b450d,_0x2204a7,_0x15cff3){var _0x190df0=_0x3b450d||_0x15cff3;if(_0x190df0){return handleError(_0x379ef0,0x191,_0x190df0);}if(!_0x2204a7){return handleError(_0x379ef0,0x194,{'message':_0xea00('0x2b')});}else{var _0xbcab08={'payload':{'id':_0x2204a7['id'],'role':_0x2204a7[_0xea00('0x2c')]},'options':{'expiresIn':0x15180}};return authService[_0xea00('0x2d')](_0xbcab08)[_0xea00('0x21')](function(_0x4ced3e){_0x379ef0[_0xea00('0x2e')]({'id':_0x2204a7['id'],'token':_0x4ced3e,'statusCall':'','isAlreadyLogged':_0x2204a7[_0xea00('0x1d')]});});}})(_0x51358d,_0x379ef0,_0x3f1f63);};passport['use'](_0xea00('0x2a'),new LocalStrategy({'usernameField':'name','passwordField':_0xea00('0x18')},function(_0x42d22b,_0x5b4280,_0x4884bc){return ActiveDirectoryAuthenticate(db[_0xea00('0x2f')],_0x42d22b,_0x5b4280,_0x4884bc);}));
\ No newline at end of file
+var _0x0379=['online','admin','user','agent','blockDuration','add','minutes','clearBlockUser','then','getLicense','catch','status','send','message','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','use','User','passport','passport-local','moment','activedirectory2','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','undefined','baseDN','url','activedirectory','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','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','role','disabled','blocked','blockedAt'];(function(_0x5447fd,_0x52a6b5){var _0x15b28a=function(_0x370d4f){while(--_0x370d4f){_0x5447fd['push'](_0x5447fd['shift']());}};_0x15b28a(++_0x52a6b5);}(_0x0379,0xe8));var _0x9037=function(_0x34b3b7,_0x50676a){_0x34b3b7=_0x34b3b7-0x0;var _0x3a3bc0=_0x0379[_0x34b3b7];return _0x3a3bc0;};'use strict';var passport=require(_0x9037('0x0'));var LocalStrategy=require(_0x9037('0x1'))['Strategy'];var moment=require(_0x9037('0x2'));var ActiveDirectory=require(_0x9037('0x3'));var BPromise=require('bluebird');var util=require(_0x9037('0x4'));var db=require(_0x9037('0x5'))['db'];var authService=require(_0x9037('0x6'));var utils=require(_0x9037('0x7'));var config=require(_0x9037('0x8'));var logger=require(_0x9037('0x9'))(_0x9037('0xa'));function isActiveDirectoryConfigured(_0x242bf7){var _0x584432=![];if(typeof _0x242bf7['activedirectory']!==_0x9037('0xb')){_0x584432=_0x242bf7['activedirectory'][_0x9037('0xc')]&&_0x242bf7['activedirectory'][_0x9037('0xd')]&&_0x242bf7[_0x9037('0xe')][_0x9037('0xf')];}return _0x584432;}function adAuthenticate(_0x287c43,_0x3d9379,_0x37c8ae){return new BPromise(function(_0x1956c3,_0x14182f){try{var _0x5e37f7=new ActiveDirectory(_0x287c43);_0x5e37f7[_0x9037('0x10')](_0x3d9379,_0x37c8ae,function(_0x3a01f1,_0x1e5b4e){if(_0x3a01f1){logger[_0x9037('0x11')](_0x9037('0x12'),_0x3d9379,util[_0x9037('0x13')](_0x3a01f1,{'showHidden':![],'depth':null}));_0x14182f(_0x9037('0x14'));}else if(!_0x1e5b4e){logger[_0x9037('0x11')](_0x9037('0x15'),_0x3d9379);_0x14182f(_0x9037('0x14'));}else{_0x1956c3(_0x1e5b4e);}});}catch(_0x33592e){_0x14182f(_0x33592e);}});}function ActiveDirectoryAuthenticate(_0x5ab5fc,_0x3994c0,_0x2be652,_0x47ac90){var _0x4684dc,_0x3f778e;if(!isActiveDirectoryConfigured(config)){logger[_0x9037('0x11')](_0x9037('0x16'),_0x3994c0);return _0x47ac90(null,![],{'message':_0x9037('0x14')});}return db[_0x9037('0x17')][_0x9037('0x18')]({'where':{'id':0x1},'attributes':[_0x9037('0x19'),'blockDuration'],'raw':!![]})['then'](function(_0x269d0c){_0x4684dc=_0x269d0c;if(!_0x4684dc[_0x9037('0x19')]){logger['error'](_0x9037('0x1a'),_0x3994c0);throw new Error(_0x9037('0x14'));}return _0x5ab5fc[_0x9037('0x18')]({'attributes':['id',_0x9037('0x1b'),_0x9037('0x1c'),'salt',_0x9037('0x1d'),_0x9037('0x1e'),_0x9037('0x1f'),_0x9037('0x20'),_0x9037('0x21')],'where':{'name':_0x3994c0,'role':{'$or':[_0x9037('0x22'),_0x9037('0x23'),_0x9037('0x24')]},'adSsoEnabled':!![]}});})['then'](function(_0x13a871){if(!_0x13a871||_0x13a871&&_0x13a871[_0x9037('0x1b')]!==_0x3994c0){throw new Error(_0x9037('0x14'));}_0x3f778e=_0x13a871;var _0x3931a3=_0x3f778e[_0x9037('0x1b')]+'@'+config['activedirectory']['domain'];return adAuthenticate(config['activedirectory'],_0x3931a3,_0x2be652);})['then'](function(_0x3bc1e2){if(_0x3f778e['disabled']){throw new Error(_0x9037('0x14'));}if(_0x4684dc[_0x9037('0x25')]>0x0){if(_0x3f778e[_0x9037('0x1f')]){if(moment(_0x3f778e[_0x9037('0x20')])[_0x9037('0x26')](_0x4684dc[_0x9037('0x25')],_0x9037('0x27'))>moment()){throw new Error(_0x9037('0x14'));}return utils[_0x9037('0x28')](_0x3f778e,0x0,![],null)[_0x9037('0x29')](function(){return utils[_0x9037('0x2a')](_0x3f778e);})[_0x9037('0x29')](function(){return _0x47ac90(null,_0x3f778e);});}else{return utils[_0x9037('0x2a')](_0x3f778e)['then'](function(){return _0x47ac90(null,_0x3f778e);});}}else{return utils['getLicense'](_0x3f778e)['then'](function(){return _0x47ac90(null,_0x3f778e);});}})[_0x9037('0x2b')](function(_0x3209fe){return _0x47ac90(null,![],_0x3209fe);});}function handleError(_0x4c9f40,_0x3933bc,_0x481d52){return _0x4c9f40[_0x9037('0x2c')](_0x3933bc||0x1f4)[_0x9037('0x2d')]({'message':_0x481d52?_0x481d52[_0x9037('0x2e')]||_0x481d52:''});}exports['login']=function(_0x186ac4,_0x23bb11,_0x5db9d2){passport[_0x9037('0x10')](_0x9037('0x2f'),function(_0x3e308a,_0x172e26,_0x4c1632){var _0x312e5d=_0x3e308a||_0x4c1632;if(_0x312e5d){return handleError(_0x23bb11,0x191,_0x312e5d);}if(!_0x172e26){return handleError(_0x23bb11,0x194,{'message':_0x9037('0x30')});}else{var _0x5e42d0={'payload':{'id':_0x172e26['id'],'role':_0x172e26[_0x9037('0x1d')]},'options':{'expiresIn':0x15180}};return authService[_0x9037('0x31')](_0x5e42d0)[_0x9037('0x29')](function(_0x27072c){_0x23bb11[_0x9037('0x32')]({'id':_0x172e26['id'],'token':_0x27072c,'statusCall':'','isAlreadyLogged':_0x172e26[_0x9037('0x21')]});});}})(_0x186ac4,_0x23bb11,_0x5db9d2);};passport[_0x9037('0x33')](_0x9037('0x2f'),new LocalStrategy({'usernameField':_0x9037('0x1b'),'passwordField':_0x9037('0x1c')},function(_0x120fc3,_0x1bed20,_0x17a299){return ActiveDirectoryAuthenticate(db[_0x9037('0x34')],_0x120fc3,_0x1bed20,_0x17a299);}));
\ No newline at end of file