Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index ab324db..f9254ea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2a05=['adSsoEnabled','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','blockedAt','online','admin','user','agent','disabled','blockDuration','add','minutes','clearBlockUser','getLicense','catch','status','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','json','use','passport-local','moment','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/logger','api','undefined','activedirectory','baseDN','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:\x20Active\x20Directory\x20not\x20configured','findOne'];(function(_0x191025,_0x2c9f2f){var _0x4f4295=function(_0xf14ed2){while(--_0xf14ed2){_0x191025['push'](_0x191025['shift']());}};_0x4f4295(++_0x2c9f2f);}(_0x2a05,0x7e));var _0x52a0=function(_0x38634a,_0x5d8b63){_0x38634a=_0x38634a-0x0;var _0x5866ba=_0x2a05[_0x38634a];return _0x5866ba;};'use strict';var passport=require('passport');var LocalStrategy=require(_0x52a0('0x0'))['Strategy'];var moment=require(_0x52a0('0x1'));var ActiveDirectory=require(_0x52a0('0x2'));var BPromise=require(_0x52a0('0x3'));var util=require(_0x52a0('0x4'));var db=require(_0x52a0('0x5'))['db'];var authService=require(_0x52a0('0x6'));var utils=require(_0x52a0('0x7'));var config=require('../../config/environment');var logger=require(_0x52a0('0x8'))(_0x52a0('0x9'));function isActiveDirectoryConfigured(_0x24e7ce){var _0x4acc6e=![];if(typeof _0x24e7ce['activedirectory']!==_0x52a0('0xa')){_0x4acc6e=_0x24e7ce[_0x52a0('0xb')][_0x52a0('0xc')]&&_0x24e7ce[_0x52a0('0xb')]['url']&&_0x24e7ce[_0x52a0('0xb')][_0x52a0('0xd')];}return _0x4acc6e;}function adAuthenticate(_0x50f764,_0x3c87d0,_0x4b6c3e){return new BPromise(function(_0x1fae6d,_0x2a1379){try{var _0x117817=new ActiveDirectory(_0x50f764);_0x117817[_0x52a0('0xe')](_0x3c87d0,_0x4b6c3e,function(_0x51e420,_0x2eebf6){if(_0x51e420){logger['error'](_0x52a0('0xf'),_0x3c87d0,util[_0x52a0('0x10')](_0x51e420,{'showHidden':![],'depth':null}));_0x2a1379(_0x52a0('0x11'));}else if(!_0x2eebf6){logger[_0x52a0('0x12')]('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x3c87d0);_0x2a1379(_0x52a0('0x11'));}else{_0x1fae6d(_0x2eebf6);}});}catch(_0x48827c){_0x2a1379(_0x48827c);}});}function ActiveDirectoryAuthenticate(_0x107675,_0x2b4ec2,_0x1e478d,_0x5e8be2){var _0x4fedc2,_0x5b7938;if(!isActiveDirectoryConfigured(config)){logger[_0x52a0('0x12')](_0x52a0('0x13'),_0x2b4ec2);return _0x5e8be2(null,![],{'message':'Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'});}return db['Setting'][_0x52a0('0x14')]({'where':{'id':0x1},'attributes':[_0x52a0('0x15'),'blockDuration'],'raw':!![]})[_0x52a0('0x16')](function(_0x43ec74){_0x4fedc2=_0x43ec74;if(!_0x4fedc2[_0x52a0('0x15')]){logger[_0x52a0('0x12')](_0x52a0('0x17'),_0x2b4ec2);throw new Error(_0x52a0('0x11'));}return _0x107675[_0x52a0('0x14')]({'logging':!![],'attributes':['id',_0x52a0('0x18'),_0x52a0('0x19'),_0x52a0('0x1a'),'role','disabled','blocked',_0x52a0('0x1b'),_0x52a0('0x1c')],'where':{'name':_0x2b4ec2,'role':{'$or':[_0x52a0('0x1d'),_0x52a0('0x1e'),_0x52a0('0x1f')]},'adSsoEnabled':!![]}});})['then'](function(_0x2c789a){if(!_0x2c789a||_0x2c789a&&_0x2c789a[_0x52a0('0x18')]!==_0x2b4ec2){throw new Error(_0x52a0('0x11'));}_0x5b7938=_0x2c789a;var _0x3da4cb=_0x5b7938[_0x52a0('0x18')]+'@'+config['activedirectory'][_0x52a0('0xd')];return adAuthenticate(config[_0x52a0('0xb')],_0x3da4cb,_0x1e478d);})[_0x52a0('0x16')](function(_0x3cc074){if(_0x5b7938[_0x52a0('0x20')]){throw new Error(_0x52a0('0x11'));}if(_0x4fedc2[_0x52a0('0x21')]>0x0){if(_0x5b7938['blocked']){if(moment(_0x5b7938[_0x52a0('0x1b')])[_0x52a0('0x22')](_0x4fedc2['blockDuration'],_0x52a0('0x23'))>moment()){throw new Error(_0x52a0('0x11'));}return utils[_0x52a0('0x24')](_0x5b7938,0x0,![],null)['then'](function(){return utils['getLicense'](_0x5b7938);})['then'](function(){return _0x5e8be2(null,_0x5b7938);});}else{return utils[_0x52a0('0x25')](_0x5b7938)[_0x52a0('0x16')](function(){return _0x5e8be2(null,_0x5b7938);});}}else{return utils[_0x52a0('0x25')](_0x5b7938)[_0x52a0('0x16')](function(){return _0x5e8be2(null,_0x5b7938);});}})[_0x52a0('0x26')](function(_0x5a2e13){return _0x5e8be2(null,![],_0x5a2e13);});}function handleError(_0x32fab8,_0xeb9ea7,_0xcdeb53){return _0x32fab8[_0x52a0('0x27')](_0xeb9ea7||0x1f4)[_0x52a0('0x28')]({'message':_0xcdeb53?_0xcdeb53[_0x52a0('0x29')]||_0xcdeb53:''});}exports[_0x52a0('0x2a')]=function(_0x1f020b,_0x5869a7,_0x5525f8){passport['authenticate'](_0x52a0('0x2b'),function(_0x159fd4,_0x225cac,_0x1ba677){var _0x465eb2=_0x159fd4||_0x1ba677;if(_0x465eb2){return handleError(_0x5869a7,0x191,_0x465eb2);}if(!_0x225cac){return handleError(_0x5869a7,0x194,{'message':_0x52a0('0x2c')});}else{var _0x3962de={'payload':{'id':_0x225cac['id'],'role':_0x225cac[_0x52a0('0x2d')]},'options':{'expiresIn':0x15180}};return authService[_0x52a0('0x2e')](_0x3962de)[_0x52a0('0x16')](function(_0x15db6d){_0x5869a7[_0x52a0('0x2f')]({'id':_0x225cac['id'],'token':_0x15db6d,'statusCall':'','isAlreadyLogged':_0x225cac[_0x52a0('0x1c')]});});}})(_0x1f020b,_0x5869a7,_0x5525f8);};passport[_0x52a0('0x30')](_0x52a0('0x2b'),new LocalStrategy({'usernameField':_0x52a0('0x18'),'passwordField':_0x52a0('0x19')},function(_0x94ae1,_0x1d0719,_0x412ea4){return ActiveDirectoryAuthenticate(db['User'],_0x94ae1,_0x1d0719,_0x412ea4);}));
\ No newline at end of file
+var _0x51b7=['Strategy','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','undefined','activedirectory','baseDN','url','domain','authenticate','error','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','blockDuration','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','disabled','blocked','online','user','agent','then','blockedAt','add','minutes','getLicense','catch','status','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','json','use','passport','passport-local'];(function(_0x1f175e,_0x25487c){var _0x4ab74c=function(_0x301e14){while(--_0x301e14){_0x1f175e['push'](_0x1f175e['shift']());}};_0x4ab74c(++_0x25487c);}(_0x51b7,0x19e));var _0x751b=function(_0x197551,_0x2955b0){_0x197551=_0x197551-0x0;var _0x55d8b2=_0x51b7[_0x197551];return _0x55d8b2;};'use strict';var passport=require(_0x751b('0x0'));var LocalStrategy=require(_0x751b('0x1'))[_0x751b('0x2')];var moment=require('moment');var ActiveDirectory=require(_0x751b('0x3'));var BPromise=require(_0x751b('0x4'));var util=require(_0x751b('0x5'));var db=require(_0x751b('0x6'))['db'];var authService=require(_0x751b('0x7'));var utils=require(_0x751b('0x8'));var config=require(_0x751b('0x9'));var logger=require(_0x751b('0xa'))(_0x751b('0xb'));function isActiveDirectoryConfigured(_0x278252){var _0x47dc20=![];if(typeof _0x278252['activedirectory']!==_0x751b('0xc')){_0x47dc20=_0x278252[_0x751b('0xd')][_0x751b('0xe')]&&_0x278252[_0x751b('0xd')][_0x751b('0xf')]&&_0x278252[_0x751b('0xd')][_0x751b('0x10')];}return _0x47dc20;}function adAuthenticate(_0x23f679,_0x64ad5c,_0x33b62d){return new BPromise(function(_0x230e0c,_0x27b8e6){try{var _0x3a0eaf=new ActiveDirectory(_0x23f679);_0x3a0eaf[_0x751b('0x11')](_0x64ad5c,_0x33b62d,function(_0x1d23fa,_0x383401){if(_0x1d23fa){logger[_0x751b('0x12')]('Error\x20authenticate\x20%s:\x20%s',_0x64ad5c,util[_0x751b('0x13')](_0x1d23fa,{'showHidden':![],'depth':null}));_0x27b8e6(_0x751b('0x14'));}else if(!_0x383401){logger[_0x751b('0x12')](_0x751b('0x15'),_0x64ad5c);_0x27b8e6(_0x751b('0x14'));}else{_0x230e0c(_0x383401);}});}catch(_0x2f050e){_0x27b8e6(_0x2f050e);}});}function ActiveDirectoryAuthenticate(_0x3a3a99,_0x540186,_0x5beb43,_0x13b293){var _0x3bda04,_0x2f3b41;if(!isActiveDirectoryConfigured(config)){logger[_0x751b('0x12')](_0x751b('0x16'),_0x540186);return _0x13b293(null,![],{'message':_0x751b('0x14')});}return db[_0x751b('0x17')][_0x751b('0x18')]({'where':{'id':0x1},'attributes':[_0x751b('0x19'),_0x751b('0x1a')],'raw':!![]})['then'](function(_0x4cbe77){_0x3bda04=_0x4cbe77;if(!_0x3bda04[_0x751b('0x19')]){logger[_0x751b('0x12')](_0x751b('0x1b'),_0x540186);throw new Error(_0x751b('0x14'));}return _0x3a3a99[_0x751b('0x18')]({'attributes':['id',_0x751b('0x1c'),_0x751b('0x1d'),_0x751b('0x1e'),'role',_0x751b('0x1f'),_0x751b('0x20'),'blockedAt',_0x751b('0x21')],'where':{'name':_0x540186,'role':{'$or':['admin',_0x751b('0x22'),_0x751b('0x23')]},'adSsoEnabled':!![]}});})['then'](function(_0x56d32e){if(!_0x56d32e||_0x56d32e&&_0x56d32e[_0x751b('0x1c')]!==_0x540186){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}_0x2f3b41=_0x56d32e;var _0x4fe256=_0x2f3b41[_0x751b('0x1c')]+'@'+config['activedirectory'][_0x751b('0x10')];return adAuthenticate(config[_0x751b('0xd')],_0x4fe256,_0x5beb43);})[_0x751b('0x24')](function(_0x131098){if(_0x2f3b41[_0x751b('0x1f')]){throw new Error(_0x751b('0x14'));}if(_0x3bda04[_0x751b('0x1a')]>0x0){if(_0x2f3b41['blocked']){if(moment(_0x2f3b41[_0x751b('0x25')])[_0x751b('0x26')](_0x3bda04['blockDuration'],_0x751b('0x27'))>moment()){throw new Error(_0x751b('0x14'));}return utils['clearBlockUser'](_0x2f3b41,0x0,![],null)['then'](function(){return utils[_0x751b('0x28')](_0x2f3b41);})['then'](function(){return _0x13b293(null,_0x2f3b41);});}else{return utils[_0x751b('0x28')](_0x2f3b41)[_0x751b('0x24')](function(){return _0x13b293(null,_0x2f3b41);});}}else{return utils[_0x751b('0x28')](_0x2f3b41)[_0x751b('0x24')](function(){return _0x13b293(null,_0x2f3b41);});}})[_0x751b('0x29')](function(_0x30ed93){return _0x13b293(null,![],_0x30ed93);});}function handleError(_0xce7a1e,_0x6105e2,_0x1429e1){return _0xce7a1e[_0x751b('0x2a')](_0x6105e2||0x1f4)[_0x751b('0x2b')]({'message':_0x1429e1?_0x1429e1[_0x751b('0x2c')]||_0x1429e1:''});}exports[_0x751b('0x2d')]=function(_0x1ccc83,_0x4640bd,_0x49d1de){passport[_0x751b('0x11')](_0x751b('0x2e'),function(_0x2815dc,_0x2fb851,_0x1e786f){var _0x827599=_0x2815dc||_0x1e786f;if(_0x827599){return handleError(_0x4640bd,0x191,_0x827599);}if(!_0x2fb851){return handleError(_0x4640bd,0x194,{'message':_0x751b('0x2f')});}else{var _0x4dedef={'payload':{'id':_0x2fb851['id'],'role':_0x2fb851[_0x751b('0x30')]},'options':{'expiresIn':0x15180}};return authService[_0x751b('0x31')](_0x4dedef)[_0x751b('0x24')](function(_0x42d7f5){_0x4640bd[_0x751b('0x32')]({'id':_0x2fb851['id'],'token':_0x42d7f5,'statusCall':'','isAlreadyLogged':_0x2fb851[_0x751b('0x21')]});});}})(_0x1ccc83,_0x4640bd,_0x49d1de);};passport[_0x751b('0x33')](_0x751b('0x2e'),new LocalStrategy({'usernameField':_0x751b('0x1c'),'passwordField':_0x751b('0x1d')},function(_0x1133e4,_0x1eba16,_0x1c0236){return ActiveDirectoryAuthenticate(db['User'],_0x1133e4,_0x1eba16,_0x1c0236);}));
\ No newline at end of file