Built motion from commit ac06311e.|2.6.28
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index c8f0243..3188496 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x989a=['moment','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','activedirectory','undefined','url','domain','authenticate','error','inspect','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Setting','findOne','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','password','salt','disabled','blocked','blockedAt','online','admin','user','then','name','blockDuration','add','clearBlockUser','getLicense','status','send','message','login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','use','ad-login','User','passport','passport-local'];(function(_0x5d6456,_0x58ecc7){var _0x4d66c1=function(_0x4335e3){while(--_0x4335e3){_0x5d6456['push'](_0x5d6456['shift']());}};_0x4d66c1(++_0x58ecc7);}(_0x989a,0x1ae));var _0xa989=function(_0x35031c,_0x400fac){_0x35031c=_0x35031c-0x0;var _0x2a7adf=_0x989a[_0x35031c];return _0x2a7adf;};'use strict';var passport=require(_0xa989('0x0'));var LocalStrategy=require(_0xa989('0x1'))['Strategy'];var moment=require(_0xa989('0x2'));var ActiveDirectory=require(_0xa989('0x3'));var BPromise=require(_0xa989('0x4'));var util=require(_0xa989('0x5'));var db=require(_0xa989('0x6'))['db'];var authService=require(_0xa989('0x7'));var utils=require(_0xa989('0x8'));var config=require(_0xa989('0x9'));var logger=require(_0xa989('0xa'))('api');function isActiveDirectoryConfigured(_0x5735be){var _0x3f39d6=![];if(typeof _0x5735be[_0xa989('0xb')]!==_0xa989('0xc')){_0x3f39d6=_0x5735be[_0xa989('0xb')]['baseDN']&&_0x5735be[_0xa989('0xb')][_0xa989('0xd')]&&_0x5735be['activedirectory'][_0xa989('0xe')];}return _0x3f39d6;}function adAuthenticate(_0xd6ebe,_0x3fa427,_0x333c82){return new BPromise(function(_0x22990b,_0x20c364){try{var _0x3c8569=new ActiveDirectory(_0xd6ebe);_0x3c8569[_0xa989('0xf')](_0x3fa427,_0x333c82,function(_0x1a409c,_0x7d75de){if(_0x1a409c){logger[_0xa989('0x10')]('Error\x20authenticate\x20%s:\x20%s',_0x3fa427,util[_0xa989('0x11')](_0x1a409c,{'showHidden':![],'depth':null}));_0x20c364('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x7d75de){logger['error'](_0xa989('0x12'),_0x3fa427);_0x20c364('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{_0x22990b(_0x7d75de);}});}catch(_0x592cc5){_0x20c364(_0x592cc5);}});}function ActiveDirectoryAuthenticate(_0x44b408,_0x179d53,_0x44844a,_0x50be28){var _0xd3ae18,_0x13529f;if(!isActiveDirectoryConfigured(config)){logger[_0xa989('0x10')](_0xa989('0x13'),_0x179d53);return _0x50be28(null,![],{'message':_0xa989('0x14')});}return db[_0xa989('0x15')][_0xa989('0x16')]({'where':{'id':0x1},'attributes':['adSsoEnabled','blockDuration'],'raw':!![]})['then'](function(_0x304a9c){_0xd3ae18=_0x304a9c;if(!_0xd3ae18['adSsoEnabled']){logger['error'](_0xa989('0x17'),_0x179d53);throw new Error(_0xa989('0x14'));}return _0x44b408[_0xa989('0x16')]({'attributes':['id','name',_0xa989('0x18'),_0xa989('0x19'),'role',_0xa989('0x1a'),_0xa989('0x1b'),_0xa989('0x1c'),_0xa989('0x1d')],'where':{'name':_0x179d53,'role':{'$or':[_0xa989('0x1e'),_0xa989('0x1f'),'agent']},'adSsoEnabled':!![]}});})[_0xa989('0x20')](function(_0x25a025){if(!_0x25a025||_0x25a025&&_0x25a025[_0xa989('0x21')]!==_0x179d53){throw new Error(_0xa989('0x14'));}_0x13529f=_0x25a025;var _0x2aedfc=_0x13529f[_0xa989('0x21')]+'@'+config[_0xa989('0xb')][_0xa989('0xe')];return adAuthenticate(config['activedirectory'],_0x2aedfc,_0x44844a);})['then'](function(_0x4bfaa1){if(_0x13529f[_0xa989('0x1a')]){throw new Error(_0xa989('0x14'));}if(_0xd3ae18[_0xa989('0x22')]>0x0){if(_0x13529f['blocked']){if(moment(_0x13529f[_0xa989('0x1c')])[_0xa989('0x23')](_0xd3ae18['blockDuration'],'minutes')>moment()){throw new Error(_0xa989('0x14'));}return utils[_0xa989('0x24')](_0x13529f,0x0,![],null)['then'](function(){return utils[_0xa989('0x25')](_0x13529f);})['then'](function(){return _0x50be28(null,_0x13529f);});}else{return utils[_0xa989('0x25')](_0x13529f)[_0xa989('0x20')](function(){return _0x50be28(null,_0x13529f);});}}else{return utils[_0xa989('0x25')](_0x13529f)[_0xa989('0x20')](function(){return _0x50be28(null,_0x13529f);});}})['catch'](function(_0x483a5b){return _0x50be28(null,![],_0x483a5b);});}function handleError(_0x21897d,_0x34a73c,_0x33fcf4){return _0x21897d[_0xa989('0x26')](_0x34a73c||0x1f4)[_0xa989('0x27')]({'message':_0x33fcf4?_0x33fcf4[_0xa989('0x28')]||_0x33fcf4:''});}exports[_0xa989('0x29')]=function(_0x1af08c,_0x2118ed,_0x506f77){passport[_0xa989('0xf')]('ad-login',function(_0x33581a,_0x2d86ac,_0x16083c){var _0x11442e=_0x33581a||_0x16083c;if(_0x11442e){return handleError(_0x2118ed,0x191,_0x11442e);}if(!_0x2d86ac){return handleError(_0x2118ed,0x194,{'message':_0xa989('0x2a')});}else{var _0x1c1b98={'payload':{'id':_0x2d86ac['id'],'role':_0x2d86ac[_0xa989('0x2b')]},'options':{'expiresIn':0x15180}};return authService[_0xa989('0x2c')](_0x1c1b98)['then'](function(_0x3b0df3){_0x2118ed['json']({'id':_0x2d86ac['id'],'token':_0x3b0df3,'statusCall':'','isAlreadyLogged':_0x2d86ac[_0xa989('0x1d')]});});}})(_0x1af08c,_0x2118ed,_0x506f77);};passport[_0xa989('0x2d')](_0xa989('0x2e'),new LocalStrategy({'usernameField':_0xa989('0x21'),'passwordField':'password'},function(_0x17bd3a,_0x2c8435,_0x1cf0b9){return ActiveDirectoryAuthenticate(db[_0xa989('0x2f')],_0x17bd3a,_0x2c8435,_0x1cf0b9);}));
\ No newline at end of file
+var _0xecc6=['login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','ad-login','User','passport-local','Strategy','moment','activedirectory2','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','undefined','activedirectory','url','authenticate','error','Error\x20authenticate\x20%s:\x20%s','inspect','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Setting','adSsoEnabled','blockDuration','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','findOne','name','password','salt','role','blocked','blockedAt','online','user','agent','then','disabled','getLicense','catch','status','send','message'];(function(_0xd89ad8,_0x347fda){var _0x1be90f=function(_0xa8f0ef){while(--_0xa8f0ef){_0xd89ad8['push'](_0xd89ad8['shift']());}};_0x1be90f(++_0x347fda);}(_0xecc6,0x148));var _0x6ecc=function(_0x519d9d,_0x5cc5d0){_0x519d9d=_0x519d9d-0x0;var _0x2c0d4c=_0xecc6[_0x519d9d];return _0x2c0d4c;};'use strict';var passport=require('passport');var LocalStrategy=require(_0x6ecc('0x0'))[_0x6ecc('0x1')];var moment=require(_0x6ecc('0x2'));var ActiveDirectory=require(_0x6ecc('0x3'));var BPromise=require('bluebird');var util=require('util');var db=require(_0x6ecc('0x4'))['db'];var authService=require(_0x6ecc('0x5'));var utils=require(_0x6ecc('0x6'));var config=require(_0x6ecc('0x7'));var logger=require(_0x6ecc('0x8'))(_0x6ecc('0x9'));function isActiveDirectoryConfigured(_0x56a5b5){var _0x450edb=![];if(typeof _0x56a5b5['activedirectory']!==_0x6ecc('0xa')){_0x450edb=_0x56a5b5[_0x6ecc('0xb')]['baseDN']&&_0x56a5b5[_0x6ecc('0xb')][_0x6ecc('0xc')]&&_0x56a5b5[_0x6ecc('0xb')]['domain'];}return _0x450edb;}function adAuthenticate(_0x378c34,_0x59f2db,_0xcedc8f){return new BPromise(function(_0x18c8b1,_0x3082ec){try{var _0x2cb8b3=new ActiveDirectory(_0x378c34);_0x2cb8b3[_0x6ecc('0xd')](_0x59f2db,_0xcedc8f,function(_0x16a124,_0x142ea9){if(_0x16a124){logger[_0x6ecc('0xe')](_0x6ecc('0xf'),_0x59f2db,util[_0x6ecc('0x10')](_0x16a124,{'showHidden':![],'depth':null}));_0x3082ec('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x142ea9){logger[_0x6ecc('0xe')](_0x6ecc('0x11'),_0x59f2db);_0x3082ec(_0x6ecc('0x12'));}else{_0x18c8b1(_0x142ea9);}});}catch(_0xf8d071){_0x3082ec(_0xf8d071);}});}function ActiveDirectoryAuthenticate(_0x4af7d9,_0x16e519,_0x4e106c,_0x332753){var _0x5cd5ab,_0x50590a;if(!isActiveDirectoryConfigured(config)){logger[_0x6ecc('0xe')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x16e519);return _0x332753(null,![],{'message':_0x6ecc('0x12')});}return db[_0x6ecc('0x13')]['findOne']({'where':{'id':0x1},'attributes':[_0x6ecc('0x14'),_0x6ecc('0x15')],'raw':!![]})['then'](function(_0x1cbdba){_0x5cd5ab=_0x1cbdba;if(!_0x5cd5ab['adSsoEnabled']){logger[_0x6ecc('0xe')](_0x6ecc('0x16'),_0x16e519);throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return _0x4af7d9[_0x6ecc('0x17')]({'attributes':['id',_0x6ecc('0x18'),_0x6ecc('0x19'),_0x6ecc('0x1a'),_0x6ecc('0x1b'),'disabled',_0x6ecc('0x1c'),_0x6ecc('0x1d'),_0x6ecc('0x1e')],'where':{'name':_0x16e519,'role':{'$or':['admin',_0x6ecc('0x1f'),_0x6ecc('0x20')]},'adSsoEnabled':!![]}});})['then'](function(_0x5d86c1){if(!_0x5d86c1||_0x5d86c1&&_0x5d86c1[_0x6ecc('0x18')]!==_0x16e519){throw new Error(_0x6ecc('0x12'));}_0x50590a=_0x5d86c1;var _0x4fa737=_0x50590a[_0x6ecc('0x18')]+'@'+config[_0x6ecc('0xb')]['domain'];return adAuthenticate(config[_0x6ecc('0xb')],_0x4fa737,_0x4e106c);})[_0x6ecc('0x21')](function(_0x49c31a){if(_0x50590a[_0x6ecc('0x22')]){throw new Error(_0x6ecc('0x12'));}if(_0x5cd5ab['blockDuration']>0x0){if(_0x50590a['blocked']){if(moment(_0x50590a[_0x6ecc('0x1d')])['add'](_0x5cd5ab[_0x6ecc('0x15')],'minutes')>moment()){throw new Error(_0x6ecc('0x12'));}return utils['clearBlockUser'](_0x50590a,0x0,![],null)['then'](function(){return utils[_0x6ecc('0x23')](_0x50590a);})[_0x6ecc('0x21')](function(){return _0x332753(null,_0x50590a);});}else{return utils[_0x6ecc('0x23')](_0x50590a)[_0x6ecc('0x21')](function(){return _0x332753(null,_0x50590a);});}}else{return utils[_0x6ecc('0x23')](_0x50590a)[_0x6ecc('0x21')](function(){return _0x332753(null,_0x50590a);});}})[_0x6ecc('0x24')](function(_0x1042f9){return _0x332753(null,![],_0x1042f9);});}function handleError(_0x199a66,_0x151c2c,_0x1ec429){return _0x199a66[_0x6ecc('0x25')](_0x151c2c||0x1f4)[_0x6ecc('0x26')]({'message':_0x1ec429?_0x1ec429[_0x6ecc('0x27')]||_0x1ec429:''});}exports[_0x6ecc('0x28')]=function(_0x234689,_0x2d4be4,_0x4104e5){passport[_0x6ecc('0xd')]('ad-login',function(_0x4a86dc,_0x5da8e0,_0x299609){var _0x3a4fa7=_0x4a86dc||_0x299609;if(_0x3a4fa7){return handleError(_0x2d4be4,0x191,_0x3a4fa7);}if(!_0x5da8e0){return handleError(_0x2d4be4,0x194,{'message':_0x6ecc('0x29')});}else{var _0x4b0d15={'payload':{'id':_0x5da8e0['id'],'role':_0x5da8e0[_0x6ecc('0x1b')]},'options':{'expiresIn':0x15180}};return authService[_0x6ecc('0x2a')](_0x4b0d15)[_0x6ecc('0x21')](function(_0x47fd22){_0x2d4be4[_0x6ecc('0x2b')]({'id':_0x5da8e0['id'],'token':_0x47fd22,'statusCall':'','isAlreadyLogged':_0x5da8e0[_0x6ecc('0x1e')]});});}})(_0x234689,_0x2d4be4,_0x4104e5);};passport['use'](_0x6ecc('0x2c'),new LocalStrategy({'usernameField':_0x6ecc('0x18'),'passwordField':'password'},function(_0x309afe,_0x304d1b,_0x3ce0cf){return ActiveDirectoryAuthenticate(db[_0x6ecc('0x2d')],_0x309afe,_0x304d1b,_0x3ce0cf);}));
\ No newline at end of file