Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index acf113d..250afd7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd641=['authenticate','error','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','role','disabled','blockedAt','online','agent','then','blocked','minutes','clearBlockUser','getLicense','status','send','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','json','use','User','passport','passport-local','Strategy','moment','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/logger','api','activedirectory','undefined','domain'];(function(_0x40f721,_0x5cf022){var _0x45bef1=function(_0x135e08){while(--_0x135e08){_0x40f721['push'](_0x40f721['shift']());}};_0x45bef1(++_0x5cf022);}(_0xd641,0xfb));var _0x1d64=function(_0x4803ca,_0x120bea){_0x4803ca=_0x4803ca-0x0;var _0x33317b=_0xd641[_0x4803ca];return _0x33317b;};'use strict';var passport=require(_0x1d64('0x0'));var LocalStrategy=require(_0x1d64('0x1'))[_0x1d64('0x2')];var moment=require(_0x1d64('0x3'));var ActiveDirectory=require('activedirectory2');var BPromise=require('bluebird');var util=require(_0x1d64('0x4'));var db=require(_0x1d64('0x5'))['db'];var authService=require(_0x1d64('0x6'));var utils=require(_0x1d64('0x7'));var config=require('../../config/environment');var logger=require(_0x1d64('0x8'))(_0x1d64('0x9'));function isActiveDirectoryConfigured(_0x5c4afa){var _0x479099=![];if(typeof _0x5c4afa[_0x1d64('0xa')]!==_0x1d64('0xb')){_0x479099=_0x5c4afa['activedirectory']['baseDN']&&_0x5c4afa[_0x1d64('0xa')]['url']&&_0x5c4afa[_0x1d64('0xa')][_0x1d64('0xc')];}return _0x479099;}function adAuthenticate(_0x1fca24,_0x1b48e3,_0x20fb15){return new BPromise(function(_0x4af3b9,_0x4c115e){try{var _0x392f1b=new ActiveDirectory(_0x1fca24);_0x392f1b[_0x1d64('0xd')](_0x1b48e3,_0x20fb15,function(_0x55f07a,_0x3eb1e6){if(_0x55f07a){logger[_0x1d64('0xe')]('Error\x20authenticate\x20%s:\x20%s',_0x1b48e3,util['inspect'](_0x55f07a,{'showHidden':![],'depth':null}));_0x4c115e(_0x1d64('0xf'));}else if(!_0x3eb1e6){logger['error'](_0x1d64('0x10'),_0x1b48e3);_0x4c115e('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{_0x4af3b9(_0x3eb1e6);}});}catch(_0x5a5e10){_0x4c115e(_0x5a5e10);}});}function ActiveDirectoryAuthenticate(_0x4c4c88,_0x2dd4b2,_0x184e5a,_0x321325){var _0x4dfa14,_0x39e68d;if(!isActiveDirectoryConfigured(config)){logger['error'](_0x1d64('0x11'),_0x2dd4b2);return _0x321325(null,![],{'message':_0x1d64('0xf')});}return db[_0x1d64('0x12')][_0x1d64('0x13')]({'where':{'id':0x1},'attributes':[_0x1d64('0x14'),_0x1d64('0x15')],'raw':!![]})['then'](function(_0x50ff70){_0x4dfa14=_0x50ff70;if(!_0x4dfa14[_0x1d64('0x14')]){logger[_0x1d64('0xe')](_0x1d64('0x16'),_0x2dd4b2);throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return _0x4c4c88['findOne']({'logging':!![],'attributes':['id',_0x1d64('0x17'),_0x1d64('0x18'),_0x1d64('0x19'),_0x1d64('0x1a'),_0x1d64('0x1b'),'blocked',_0x1d64('0x1c'),_0x1d64('0x1d')],'where':{'name':_0x2dd4b2,'role':{'$or':['admin','user',_0x1d64('0x1e')]},'adSsoEnabled':!![]}});})[_0x1d64('0x1f')](function(_0x25f627){if(!_0x25f627||_0x25f627&&_0x25f627[_0x1d64('0x17')]!==_0x2dd4b2){throw new Error(_0x1d64('0xf'));}_0x39e68d=_0x25f627;var _0x20e5b0=_0x39e68d[_0x1d64('0x17')]+'@'+config[_0x1d64('0xa')][_0x1d64('0xc')];return adAuthenticate(config[_0x1d64('0xa')],_0x20e5b0,_0x184e5a);})['then'](function(_0x1b65a5){if(_0x39e68d[_0x1d64('0x1b')]){throw new Error(_0x1d64('0xf'));}if(_0x4dfa14[_0x1d64('0x15')]>0x0){if(_0x39e68d[_0x1d64('0x20')]){if(moment(_0x39e68d[_0x1d64('0x1c')])['add'](_0x4dfa14[_0x1d64('0x15')],_0x1d64('0x21'))>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils[_0x1d64('0x22')](_0x39e68d,0x0,![],null)[_0x1d64('0x1f')](function(){return utils[_0x1d64('0x23')](_0x39e68d);})[_0x1d64('0x1f')](function(){return _0x321325(null,_0x39e68d);});}else{return utils['getLicense'](_0x39e68d)[_0x1d64('0x1f')](function(){return _0x321325(null,_0x39e68d);});}}else{return utils['getLicense'](_0x39e68d)['then'](function(){return _0x321325(null,_0x39e68d);});}})['catch'](function(_0x456893){return _0x321325(null,![],_0x456893);});}function handleError(_0x534b3c,_0x231cb8,_0x5014d6){return _0x534b3c[_0x1d64('0x24')](_0x231cb8||0x1f4)[_0x1d64('0x25')]({'message':_0x5014d6?_0x5014d6['message']||_0x5014d6:''});}exports[_0x1d64('0x26')]=function(_0x169191,_0x1d5503,_0x387b5b){passport[_0x1d64('0xd')](_0x1d64('0x27'),function(_0x5ed879,_0xd025a0,_0x5cf5b6){var _0x1e6d08=_0x5ed879||_0x5cf5b6;if(_0x1e6d08){return handleError(_0x1d5503,0x191,_0x1e6d08);}if(!_0xd025a0){return handleError(_0x1d5503,0x194,{'message':_0x1d64('0x28')});}else{var _0x12c83b={'payload':{'id':_0xd025a0['id'],'role':_0xd025a0[_0x1d64('0x1a')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x12c83b)[_0x1d64('0x1f')](function(_0x54588a){_0x1d5503[_0x1d64('0x29')]({'id':_0xd025a0['id'],'token':_0x54588a,'statusCall':'','isAlreadyLogged':_0xd025a0[_0x1d64('0x1d')]});});}})(_0x169191,_0x1d5503,_0x387b5b);};passport[_0x1d64('0x2a')]('ad-login',new LocalStrategy({'usernameField':_0x1d64('0x17'),'passwordField':_0x1d64('0x18')},function(_0x151c35,_0x5f50b3,_0x23929e){return ActiveDirectoryAuthenticate(db[_0x1d64('0x2b')],_0x151c35,_0x5f50b3,_0x23929e);}));
\ No newline at end of file
+var _0xc8ae=['login','ad-login','role','json','User','passport-local','Strategy','moment','activedirectory2','bluebird','util','../../config/utils','../../config/environment','../../config/logger','api','activedirectory','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','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','adSsoEnabled','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','password','salt','disabled','blocked','blockedAt','admin','user','agent','name','add','minutes','getLicense','status','message'];(function(_0x3edece,_0x44e63e){var _0x4caa17=function(_0x330b35){while(--_0x330b35){_0x3edece['push'](_0x3edece['shift']());}};_0x4caa17(++_0x44e63e);}(_0xc8ae,0x1d1));var _0xec8a=function(_0x1f487b,_0x285a74){_0x1f487b=_0x1f487b-0x0;var _0x420c12=_0xc8ae[_0x1f487b];return _0x420c12;};'use strict';var passport=require('passport');var LocalStrategy=require(_0xec8a('0x0'))[_0xec8a('0x1')];var moment=require(_0xec8a('0x2'));var ActiveDirectory=require(_0xec8a('0x3'));var BPromise=require(_0xec8a('0x4'));var util=require(_0xec8a('0x5'));var db=require('../../mysqldb')['db'];var authService=require('../../components/auth/service');var utils=require(_0xec8a('0x6'));var config=require(_0xec8a('0x7'));var logger=require(_0xec8a('0x8'))(_0xec8a('0x9'));function isActiveDirectoryConfigured(_0x1af8c3){var _0x5d610b=![];if(typeof _0x1af8c3['activedirectory']!=='undefined'){_0x5d610b=_0x1af8c3[_0xec8a('0xa')][_0xec8a('0xb')]&&_0x1af8c3[_0xec8a('0xa')][_0xec8a('0xc')]&&_0x1af8c3[_0xec8a('0xa')][_0xec8a('0xd')];}return _0x5d610b;}function adAuthenticate(_0x265b14,_0x1937f5,_0x1f55ba){return new BPromise(function(_0x54fb6b,_0x5f301d){try{var _0x46704c=new ActiveDirectory(_0x265b14);_0x46704c[_0xec8a('0xe')](_0x1937f5,_0x1f55ba,function(_0x41f4b1,_0x2fbd89){if(_0x41f4b1){logger['error'](_0xec8a('0xf'),_0x1937f5,util[_0xec8a('0x10')](_0x41f4b1,{'showHidden':![],'depth':null}));_0x5f301d(_0xec8a('0x11'));}else if(!_0x2fbd89){logger[_0xec8a('0x12')](_0xec8a('0x13'),_0x1937f5);_0x5f301d(_0xec8a('0x11'));}else{_0x54fb6b(_0x2fbd89);}});}catch(_0x3fa0ee){_0x5f301d(_0x3fa0ee);}});}function ActiveDirectoryAuthenticate(_0x1a7792,_0x1c44d4,_0x505646,_0x2d3519){var _0xe57a8d,_0x2bddfc;if(!isActiveDirectoryConfigured(config)){logger[_0xec8a('0x12')](_0xec8a('0x14'),_0x1c44d4);return _0x2d3519(null,![],{'message':_0xec8a('0x11')});}return db[_0xec8a('0x15')][_0xec8a('0x16')]({'where':{'id':0x1},'attributes':[_0xec8a('0x17'),_0xec8a('0x18')],'raw':!![]})[_0xec8a('0x19')](function(_0x5bdfbc){_0xe57a8d=_0x5bdfbc;if(!_0xe57a8d[_0xec8a('0x17')]){logger['error'](_0xec8a('0x1a'),_0x1c44d4);throw new Error(_0xec8a('0x11'));}return _0x1a7792[_0xec8a('0x16')]({'attributes':['id','name',_0xec8a('0x1b'),_0xec8a('0x1c'),'role',_0xec8a('0x1d'),_0xec8a('0x1e'),_0xec8a('0x1f'),'online'],'where':{'name':_0x1c44d4,'role':{'$or':[_0xec8a('0x20'),_0xec8a('0x21'),_0xec8a('0x22')]},'adSsoEnabled':!![]}});})['then'](function(_0x39cd65){if(!_0x39cd65||_0x39cd65&&_0x39cd65[_0xec8a('0x23')]!==_0x1c44d4){throw new Error(_0xec8a('0x11'));}_0x2bddfc=_0x39cd65;var _0x28adaf=_0x2bddfc[_0xec8a('0x23')]+'@'+config[_0xec8a('0xa')][_0xec8a('0xd')];return adAuthenticate(config[_0xec8a('0xa')],_0x28adaf,_0x505646);})[_0xec8a('0x19')](function(_0x2b47d5){if(_0x2bddfc[_0xec8a('0x1d')]){throw new Error(_0xec8a('0x11'));}if(_0xe57a8d[_0xec8a('0x18')]>0x0){if(_0x2bddfc['blocked']){if(moment(_0x2bddfc['blockedAt'])[_0xec8a('0x24')](_0xe57a8d[_0xec8a('0x18')],_0xec8a('0x25'))>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils['clearBlockUser'](_0x2bddfc,0x0,![],null)[_0xec8a('0x19')](function(){return utils[_0xec8a('0x26')](_0x2bddfc);})[_0xec8a('0x19')](function(){return _0x2d3519(null,_0x2bddfc);});}else{return utils[_0xec8a('0x26')](_0x2bddfc)['then'](function(){return _0x2d3519(null,_0x2bddfc);});}}else{return utils[_0xec8a('0x26')](_0x2bddfc)[_0xec8a('0x19')](function(){return _0x2d3519(null,_0x2bddfc);});}})['catch'](function(_0xf96d72){return _0x2d3519(null,![],_0xf96d72);});}function handleError(_0x18e54d,_0xfc3f49,_0x1fdf1c){return _0x18e54d[_0xec8a('0x27')](_0xfc3f49||0x1f4)['send']({'message':_0x1fdf1c?_0x1fdf1c[_0xec8a('0x28')]||_0x1fdf1c:''});}exports[_0xec8a('0x29')]=function(_0x1f15a1,_0x3e8beb,_0x47c059){passport[_0xec8a('0xe')](_0xec8a('0x2a'),function(_0x59eef7,_0x1fd82e,_0x21797e){var _0x562821=_0x59eef7||_0x21797e;if(_0x562821){return handleError(_0x3e8beb,0x191,_0x562821);}if(!_0x1fd82e){return handleError(_0x3e8beb,0x194,{'message':'Something\x20went\x20wrong,\x20please\x20try\x20again.'});}else{var _0x5985c8={'payload':{'id':_0x1fd82e['id'],'role':_0x1fd82e[_0xec8a('0x2b')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x5985c8)[_0xec8a('0x19')](function(_0x37f819){_0x3e8beb[_0xec8a('0x2c')]({'id':_0x1fd82e['id'],'token':_0x37f819,'statusCall':'','isAlreadyLogged':_0x1fd82e['online']});});}})(_0x1f15a1,_0x3e8beb,_0x47c059);};passport['use']('ad-login',new LocalStrategy({'usernameField':'name','passwordField':'password'},function(_0x4e0626,_0x3ee1d2,_0xe34143){return ActiveDirectoryAuthenticate(db[_0xec8a('0x2d')],_0x4e0626,_0x3ee1d2,_0xe34143);}));
\ No newline at end of file