Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index fb42d93..72257f8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3bcf=['activedirectory2','bluebird','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','api','activedirectory','undefined','url','authenticate','error','Error\x20authenticate\x20%s:\x20%s','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','salt','role','disabled','blocked','online','admin','agent','domain','blockedAt','getLicense','catch','send','message','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','use','ad-login','User','passport','passport-local','Strategy','moment'];(function(_0x4e8f87,_0x1542b2){var _0x224194=function(_0xb0c6c8){while(--_0xb0c6c8){_0x4e8f87['push'](_0x4e8f87['shift']());}};_0x224194(++_0x1542b2);}(_0x3bcf,0xdd));var _0xf3bc=function(_0x2ad5b0,_0x6db245){_0x2ad5b0=_0x2ad5b0-0x0;var _0x235edb=_0x3bcf[_0x2ad5b0];return _0x235edb;};'use strict';var passport=require(_0xf3bc('0x0'));var LocalStrategy=require(_0xf3bc('0x1'))[_0xf3bc('0x2')];var moment=require(_0xf3bc('0x3'));var ActiveDirectory=require(_0xf3bc('0x4'));var BPromise=require(_0xf3bc('0x5'));var util=require('util');var db=require(_0xf3bc('0x6'))['db'];var authService=require(_0xf3bc('0x7'));var utils=require(_0xf3bc('0x8'));var config=require(_0xf3bc('0x9'));var logger=require('../../config/logger')(_0xf3bc('0xa'));function isActiveDirectoryConfigured(_0x3456d0){var _0x37bae7=![];if(typeof _0x3456d0[_0xf3bc('0xb')]!==_0xf3bc('0xc')){_0x37bae7=_0x3456d0[_0xf3bc('0xb')]['baseDN']&&_0x3456d0[_0xf3bc('0xb')][_0xf3bc('0xd')]&&_0x3456d0[_0xf3bc('0xb')]['domain'];}return _0x37bae7;}function adAuthenticate(_0x2849f6,_0x180001,_0x33235d){return new BPromise(function(_0x4d74ec,_0x41b436){try{var _0x2a9c12=new ActiveDirectory(_0x2849f6);_0x2a9c12[_0xf3bc('0xe')](_0x180001,_0x33235d,function(_0x2c063f,_0x2916d5){if(_0x2c063f){logger[_0xf3bc('0xf')](_0xf3bc('0x10'),_0x180001,util['inspect'](_0x2c063f,{'showHidden':![],'depth':null}));_0x41b436(_0xf3bc('0x11'));}else if(!_0x2916d5){logger['error']('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x180001);_0x41b436(_0xf3bc('0x11'));}else{_0x4d74ec(_0x2916d5);}});}catch(_0x198604){_0x41b436(_0x198604);}});}function ActiveDirectoryAuthenticate(_0x4cb138,_0x424063,_0x33b2ac,_0x378eed){var _0x4cb6a0,_0x2cc991;if(!isActiveDirectoryConfigured(config)){logger[_0xf3bc('0xf')](_0xf3bc('0x12'),_0x424063);return _0x378eed(null,![],{'message':_0xf3bc('0x11')});}return db[_0xf3bc('0x13')][_0xf3bc('0x14')]({'where':{'id':0x1},'attributes':[_0xf3bc('0x15'),_0xf3bc('0x16')],'raw':!![]})[_0xf3bc('0x17')](function(_0x54e1f0){_0x4cb6a0=_0x54e1f0;if(!_0x4cb6a0[_0xf3bc('0x15')]){logger[_0xf3bc('0xf')](_0xf3bc('0x18'),_0x424063);throw new Error(_0xf3bc('0x11'));}return _0x4cb138[_0xf3bc('0x14')]({'attributes':['id',_0xf3bc('0x19'),'password',_0xf3bc('0x1a'),_0xf3bc('0x1b'),_0xf3bc('0x1c'),_0xf3bc('0x1d'),'blockedAt',_0xf3bc('0x1e')],'where':{'name':_0x424063,'role':{'$or':[_0xf3bc('0x1f'),'user',_0xf3bc('0x20')]},'adSsoEnabled':!![]}});})[_0xf3bc('0x17')](function(_0x30e210){if(!_0x30e210||_0x30e210&&_0x30e210['name']!==_0x424063){throw new Error(_0xf3bc('0x11'));}_0x2cc991=_0x30e210;var _0x1ab9c5=_0x2cc991['name']+'@'+config['activedirectory'][_0xf3bc('0x21')];return adAuthenticate(config[_0xf3bc('0xb')],_0x1ab9c5,_0x33b2ac);})[_0xf3bc('0x17')](function(_0x42ad8e){if(_0x2cc991['disabled']){throw new Error(_0xf3bc('0x11'));}if(_0x4cb6a0[_0xf3bc('0x16')]>0x0){if(_0x2cc991[_0xf3bc('0x1d')]){if(moment(_0x2cc991[_0xf3bc('0x22')])['add'](_0x4cb6a0[_0xf3bc('0x16')],'minutes')>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils['clearBlockUser'](_0x2cc991,0x0,![],null)[_0xf3bc('0x17')](function(){return utils['getLicense'](_0x2cc991);})[_0xf3bc('0x17')](function(){return _0x378eed(null,_0x2cc991);});}else{return utils[_0xf3bc('0x23')](_0x2cc991)[_0xf3bc('0x17')](function(){return _0x378eed(null,_0x2cc991);});}}else{return utils['getLicense'](_0x2cc991)[_0xf3bc('0x17')](function(){return _0x378eed(null,_0x2cc991);});}})[_0xf3bc('0x24')](function(_0x15559f){return _0x378eed(null,![],_0x15559f);});}function handleError(_0x2f3916,_0x4cf46d,_0x333f87){return _0x2f3916['status'](_0x4cf46d||0x1f4)[_0xf3bc('0x25')]({'message':_0x333f87?_0x333f87[_0xf3bc('0x26')]||_0x333f87:''});}exports['login']=function(_0x4f6476,_0x1e0007,_0x5ca363){passport['authenticate']('ad-login',function(_0x5220e3,_0x558f82,_0x3f3d5a){var _0x2e31a4=_0x5220e3||_0x3f3d5a;if(_0x2e31a4){return handleError(_0x1e0007,0x191,_0x2e31a4);}if(!_0x558f82){return handleError(_0x1e0007,0x194,{'message':_0xf3bc('0x27')});}else{var _0x288f18={'payload':{'id':_0x558f82['id'],'role':_0x558f82[_0xf3bc('0x1b')]},'options':{'expiresIn':0x15180}};return authService[_0xf3bc('0x28')](_0x288f18)[_0xf3bc('0x17')](function(_0x6c1033){_0x1e0007[_0xf3bc('0x29')]({'id':_0x558f82['id'],'token':_0x6c1033,'statusCall':'','isAlreadyLogged':_0x558f82['online']});});}})(_0x4f6476,_0x1e0007,_0x5ca363);};passport[_0xf3bc('0x2a')](_0xf3bc('0x2b'),new LocalStrategy({'usernameField':_0xf3bc('0x19'),'passwordField':'password'},function(_0x1a7738,_0x572a9b,_0x1811a4){return ActiveDirectoryAuthenticate(db[_0xf3bc('0x2c')],_0x1a7738,_0x572a9b,_0x1811a4);}));
\ No newline at end of file
+var _0x0bae=['undefined','activedirectory','baseDN','url','domain','authenticate','error','Error\x20authenticate\x20%s:\x20%s','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','blockedAt','agent','then','blockDuration','blocked','add','clearBlockUser','getLicense','catch','status','send','login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','online','use','ad-login','User','passport','passport-local','Strategy','moment','activedirectory2','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api'];(function(_0x28e74e,_0x53fdf1){var _0xb45ac1=function(_0x311a7a){while(--_0x311a7a){_0x28e74e['push'](_0x28e74e['shift']());}};_0xb45ac1(++_0x53fdf1);}(_0x0bae,0x146));var _0xe0ba=function(_0x18e1bf,_0x2fbc81){_0x18e1bf=_0x18e1bf-0x0;var _0x4bd981=_0x0bae[_0x18e1bf];return _0x4bd981;};'use strict';var passport=require(_0xe0ba('0x0'));var LocalStrategy=require(_0xe0ba('0x1'))[_0xe0ba('0x2')];var moment=require(_0xe0ba('0x3'));var ActiveDirectory=require(_0xe0ba('0x4'));var BPromise=require('bluebird');var util=require('util');var db=require('../../mysqldb')['db'];var authService=require(_0xe0ba('0x5'));var utils=require(_0xe0ba('0x6'));var config=require(_0xe0ba('0x7'));var logger=require(_0xe0ba('0x8'))(_0xe0ba('0x9'));function isActiveDirectoryConfigured(_0x21ff6f){var _0x27e0d8=![];if(typeof _0x21ff6f['activedirectory']!==_0xe0ba('0xa')){_0x27e0d8=_0x21ff6f[_0xe0ba('0xb')][_0xe0ba('0xc')]&&_0x21ff6f[_0xe0ba('0xb')][_0xe0ba('0xd')]&&_0x21ff6f['activedirectory'][_0xe0ba('0xe')];}return _0x27e0d8;}function adAuthenticate(_0x2c9d7a,_0x48fb8e,_0x4538fd){return new BPromise(function(_0x8b5354,_0x3d8504){try{var _0x2d801b=new ActiveDirectory(_0x2c9d7a);_0x2d801b[_0xe0ba('0xf')](_0x48fb8e,_0x4538fd,function(_0x303911,_0x29167c){if(_0x303911){logger[_0xe0ba('0x10')](_0xe0ba('0x11'),_0x48fb8e,util['inspect'](_0x303911,{'showHidden':![],'depth':null}));_0x3d8504(_0xe0ba('0x12'));}else if(!_0x29167c){logger['error'](_0xe0ba('0x13'),_0x48fb8e);_0x3d8504(_0xe0ba('0x12'));}else{_0x8b5354(_0x29167c);}});}catch(_0x5c73fc){_0x3d8504(_0x5c73fc);}});}function ActiveDirectoryAuthenticate(_0x42a03c,_0x4f9f91,_0x1e2bf0,_0x1c4fef){var _0x54f21e,_0x3b019a;if(!isActiveDirectoryConfigured(config)){logger[_0xe0ba('0x10')](_0xe0ba('0x14'),_0x4f9f91);return _0x1c4fef(null,![],{'message':_0xe0ba('0x12')});}return db[_0xe0ba('0x15')][_0xe0ba('0x16')]({'where':{'id':0x1},'attributes':[_0xe0ba('0x17'),'blockDuration'],'raw':!![]})['then'](function(_0x26f5c3){_0x54f21e=_0x26f5c3;if(!_0x54f21e[_0xe0ba('0x17')]){logger[_0xe0ba('0x10')](_0xe0ba('0x18'),_0x4f9f91);throw new Error(_0xe0ba('0x12'));}return _0x42a03c[_0xe0ba('0x16')]({'attributes':['id',_0xe0ba('0x19'),_0xe0ba('0x1a'),'salt',_0xe0ba('0x1b'),_0xe0ba('0x1c'),'blocked',_0xe0ba('0x1d'),'online'],'where':{'name':_0x4f9f91,'role':{'$or':['admin','user',_0xe0ba('0x1e')]},'adSsoEnabled':!![]}});})['then'](function(_0x23efac){if(!_0x23efac||_0x23efac&&_0x23efac['name']!==_0x4f9f91){throw new Error(_0xe0ba('0x12'));}_0x3b019a=_0x23efac;var _0x1fe832=_0x3b019a[_0xe0ba('0x19')]+'@'+config[_0xe0ba('0xb')][_0xe0ba('0xe')];return adAuthenticate(config[_0xe0ba('0xb')],_0x1fe832,_0x1e2bf0);})[_0xe0ba('0x1f')](function(_0x152d6c){if(_0x3b019a[_0xe0ba('0x1c')]){throw new Error(_0xe0ba('0x12'));}if(_0x54f21e[_0xe0ba('0x20')]>0x0){if(_0x3b019a[_0xe0ba('0x21')]){if(moment(_0x3b019a[_0xe0ba('0x1d')])[_0xe0ba('0x22')](_0x54f21e['blockDuration'],'minutes')>moment()){throw new Error(_0xe0ba('0x12'));}return utils[_0xe0ba('0x23')](_0x3b019a,0x0,![],null)[_0xe0ba('0x1f')](function(){return utils[_0xe0ba('0x24')](_0x3b019a);})[_0xe0ba('0x1f')](function(){return _0x1c4fef(null,_0x3b019a);});}else{return utils[_0xe0ba('0x24')](_0x3b019a)[_0xe0ba('0x1f')](function(){return _0x1c4fef(null,_0x3b019a);});}}else{return utils[_0xe0ba('0x24')](_0x3b019a)[_0xe0ba('0x1f')](function(){return _0x1c4fef(null,_0x3b019a);});}})[_0xe0ba('0x25')](function(_0x53954f){return _0x1c4fef(null,![],_0x53954f);});}function handleError(_0x6d286a,_0x59fead,_0x5a2d2e){return _0x6d286a[_0xe0ba('0x26')](_0x59fead||0x1f4)[_0xe0ba('0x27')]({'message':_0x5a2d2e?_0x5a2d2e['message']||_0x5a2d2e:''});}exports[_0xe0ba('0x28')]=function(_0x507d57,_0x37d6ba,_0x3d5e62){passport[_0xe0ba('0xf')]('ad-login',function(_0x298fcd,_0x47576a,_0x2a9180){var _0x32cc58=_0x298fcd||_0x2a9180;if(_0x32cc58){return handleError(_0x37d6ba,0x191,_0x32cc58);}if(!_0x47576a){return handleError(_0x37d6ba,0x194,{'message':_0xe0ba('0x29')});}else{var _0x5cf830={'payload':{'id':_0x47576a['id'],'role':_0x47576a[_0xe0ba('0x1b')]},'options':{'expiresIn':0x15180}};return authService[_0xe0ba('0x2a')](_0x5cf830)[_0xe0ba('0x1f')](function(_0x1fb069){_0x37d6ba[_0xe0ba('0x2b')]({'id':_0x47576a['id'],'token':_0x1fb069,'statusCall':'','isAlreadyLogged':_0x47576a[_0xe0ba('0x2c')]});});}})(_0x507d57,_0x37d6ba,_0x3d5e62);};passport[_0xe0ba('0x2d')](_0xe0ba('0x2e'),new LocalStrategy({'usernameField':_0xe0ba('0x19'),'passwordField':_0xe0ba('0x1a')},function(_0x392837,_0x1ee0b1,_0x4ee26d){return ActiveDirectoryAuthenticate(db[_0xe0ba('0x2f')],_0x392837,_0x1ee0b1,_0x4ee26d);}));
\ No newline at end of file