Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 9861225..31c5820 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x84c7=['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','then','name','password','disabled','blocked','blockedAt','admin','user','agent','add','blockDuration','clearBlockUser','getLicense','catch','status','send','authenticate','role','signToken','online','use','ad-login','User','passport-local','Strategy','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','activedirectory','undefined','baseDN','url','domain','error','Error\x20authenticate\x20%s:\x20%s'];(function(_0x1a046d,_0x3c2120){var _0x1dabe7=function(_0x123dec){while(--_0x123dec){_0x1a046d['push'](_0x1a046d['shift']());}};_0x1dabe7(++_0x3c2120);}(_0x84c7,0x10e));var _0x784c=function(_0x15f1d9,_0x48654d){_0x15f1d9=_0x15f1d9-0x0;var _0x1d00e4=_0x84c7[_0x15f1d9];return _0x1d00e4;};'use strict';var passport=require('passport');var LocalStrategy=require(_0x784c('0x0'))[_0x784c('0x1')];var moment=require('moment');var ActiveDirectory=require(_0x784c('0x2'));var BPromise=require(_0x784c('0x3'));var util=require(_0x784c('0x4'));var db=require(_0x784c('0x5'))['db'];var authService=require(_0x784c('0x6'));var utils=require(_0x784c('0x7'));var config=require(_0x784c('0x8'));var logger=require(_0x784c('0x9'))(_0x784c('0xa'));function isActiveDirectoryConfigured(_0x13c349){var _0x16b92b=![];if(typeof _0x13c349[_0x784c('0xb')]!==_0x784c('0xc')){_0x16b92b=_0x13c349[_0x784c('0xb')][_0x784c('0xd')]&&_0x13c349['activedirectory'][_0x784c('0xe')]&&_0x13c349[_0x784c('0xb')][_0x784c('0xf')];}return _0x16b92b;}function adAuthenticate(_0x29522a,_0x55e50d,_0x3750df){return new BPromise(function(_0xadc711,_0x4796fc){try{var _0x32fa73=new ActiveDirectory(_0x29522a);_0x32fa73['authenticate'](_0x55e50d,_0x3750df,function(_0x5a5ba7,_0x15c069){if(_0x5a5ba7){logger[_0x784c('0x10')](_0x784c('0x11'),_0x55e50d,util[_0x784c('0x12')](_0x5a5ba7,{'showHidden':![],'depth':null}));_0x4796fc(_0x784c('0x13'));}else if(!_0x15c069){logger['error'](_0x784c('0x14'),_0x55e50d);_0x4796fc(_0x784c('0x13'));}else{_0xadc711(_0x15c069);}});}catch(_0x12f4b0){_0x4796fc(_0x12f4b0);}});}function ActiveDirectoryAuthenticate(_0x29f9f2,_0x179f32,_0x489010,_0x29dbae){var _0x422a51,_0x31cc00;if(!isActiveDirectoryConfigured(config)){logger[_0x784c('0x10')](_0x784c('0x15'),_0x179f32);return _0x29dbae(null,![],{'message':_0x784c('0x13')});}return db[_0x784c('0x16')][_0x784c('0x17')]({'where':{'id':0x1},'attributes':[_0x784c('0x18'),'blockDuration'],'raw':!![]})[_0x784c('0x19')](function(_0x3e2717){_0x422a51=_0x3e2717;if(!_0x422a51[_0x784c('0x18')]){logger[_0x784c('0x10')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled',_0x179f32);throw new Error(_0x784c('0x13'));}return _0x29f9f2[_0x784c('0x17')]({'attributes':['id',_0x784c('0x1a'),_0x784c('0x1b'),'salt','role',_0x784c('0x1c'),_0x784c('0x1d'),_0x784c('0x1e'),'online'],'where':{'name':_0x179f32,'role':{'$or':[_0x784c('0x1f'),_0x784c('0x20'),_0x784c('0x21')]},'adSsoEnabled':!![]}});})[_0x784c('0x19')](function(_0x2c293d){if(!_0x2c293d||_0x2c293d&&_0x2c293d[_0x784c('0x1a')]!==_0x179f32){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}_0x31cc00=_0x2c293d;var _0x115918=_0x31cc00['name']+'@'+config[_0x784c('0xb')]['domain'];return adAuthenticate(config['activedirectory'],_0x115918,_0x489010);})[_0x784c('0x19')](function(_0x41d515){if(_0x31cc00[_0x784c('0x1c')]){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}if(_0x422a51['blockDuration']>0x0){if(_0x31cc00[_0x784c('0x1d')]){if(moment(_0x31cc00[_0x784c('0x1e')])[_0x784c('0x22')](_0x422a51[_0x784c('0x23')],'minutes')>moment()){throw new Error(_0x784c('0x13'));}return utils[_0x784c('0x24')](_0x31cc00,0x0,![],null)['then'](function(){return utils[_0x784c('0x25')](_0x31cc00);})[_0x784c('0x19')](function(){return _0x29dbae(null,_0x31cc00);});}else{return utils['getLicense'](_0x31cc00)['then'](function(){return _0x29dbae(null,_0x31cc00);});}}else{return utils[_0x784c('0x25')](_0x31cc00)[_0x784c('0x19')](function(){return _0x29dbae(null,_0x31cc00);});}})[_0x784c('0x26')](function(_0x1bc8da){return _0x29dbae(null,![],_0x1bc8da);});}function handleError(_0x5852fc,_0x5d832a,_0x136b6d){return _0x5852fc[_0x784c('0x27')](_0x5d832a||0x1f4)[_0x784c('0x28')]({'message':_0x136b6d?_0x136b6d['message']||_0x136b6d:''});}exports['login']=function(_0x110b7b,_0x4364f4,_0x249937){passport[_0x784c('0x29')]('ad-login',function(_0x270c34,_0x5793af,_0x27517e){var _0x4c43c4=_0x270c34||_0x27517e;if(_0x4c43c4){return handleError(_0x4364f4,0x191,_0x4c43c4);}if(!_0x5793af){return handleError(_0x4364f4,0x194,{'message':'Something\x20went\x20wrong,\x20please\x20try\x20again.'});}else{var _0x4db964={'payload':{'id':_0x5793af['id'],'role':_0x5793af[_0x784c('0x2a')]},'options':{'expiresIn':0x15180}};return authService[_0x784c('0x2b')](_0x4db964)[_0x784c('0x19')](function(_0x4777d8){_0x4364f4['json']({'id':_0x5793af['id'],'token':_0x4777d8,'statusCall':'','isAlreadyLogged':_0x5793af[_0x784c('0x2c')]});});}})(_0x110b7b,_0x4364f4,_0x249937);};passport[_0x784c('0x2d')](_0x784c('0x2e'),new LocalStrategy({'usernameField':_0x784c('0x1a'),'passwordField':_0x784c('0x1b')},function(_0x1c66eb,_0x1ba0b1,_0x202f3f){return ActiveDirectoryAuthenticate(db[_0x784c('0x2f')],_0x1c66eb,_0x1ba0b1,_0x202f3f);}));
\ No newline at end of file
+var _0x0289=['name','role','disabled','blocked','blockedAt','online','admin','user','then','add','minutes','getLicense','catch','send','login','ad-login','signToken','json','password','User','passport','passport-local','activedirectory2','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','api','undefined','baseDN','activedirectory','url','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','adSsoEnabled','blockDuration','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','findOne'];(function(_0x1f307f,_0x3a3ef4){var _0x5c9a90=function(_0x2698a5){while(--_0x2698a5){_0x1f307f['push'](_0x1f307f['shift']());}};_0x5c9a90(++_0x3a3ef4);}(_0x0289,0x70));var _0x9028=function(_0x627b1b,_0x462114){_0x627b1b=_0x627b1b-0x0;var _0x2fd022=_0x0289[_0x627b1b];return _0x2fd022;};'use strict';var passport=require(_0x9028('0x0'));var LocalStrategy=require(_0x9028('0x1'))['Strategy'];var moment=require('moment');var ActiveDirectory=require(_0x9028('0x2'));var BPromise=require('bluebird');var util=require(_0x9028('0x3'));var db=require(_0x9028('0x4'))['db'];var authService=require(_0x9028('0x5'));var utils=require(_0x9028('0x6'));var config=require(_0x9028('0x7'));var logger=require('../../config/logger')(_0x9028('0x8'));function isActiveDirectoryConfigured(_0x23d0a3){var _0x429d84=![];if(typeof _0x23d0a3['activedirectory']!==_0x9028('0x9')){_0x429d84=_0x23d0a3['activedirectory'][_0x9028('0xa')]&&_0x23d0a3[_0x9028('0xb')][_0x9028('0xc')]&&_0x23d0a3[_0x9028('0xb')][_0x9028('0xd')];}return _0x429d84;}function adAuthenticate(_0x297bd2,_0x3f4dfa,_0x5d1b37){return new BPromise(function(_0x267e49,_0x1edc50){try{var _0x1bdfbf=new ActiveDirectory(_0x297bd2);_0x1bdfbf[_0x9028('0xe')](_0x3f4dfa,_0x5d1b37,function(_0x4f2fd9,_0x5ec9a8){if(_0x4f2fd9){logger[_0x9028('0xf')](_0x9028('0x10'),_0x3f4dfa,util[_0x9028('0x11')](_0x4f2fd9,{'showHidden':![],'depth':null}));_0x1edc50(_0x9028('0x12'));}else if(!_0x5ec9a8){logger['error'](_0x9028('0x13'),_0x3f4dfa);_0x1edc50(_0x9028('0x12'));}else{_0x267e49(_0x5ec9a8);}});}catch(_0x1e2b28){_0x1edc50(_0x1e2b28);}});}function ActiveDirectoryAuthenticate(_0x4b14c6,_0x595829,_0x519ec8,_0x168dfb){var _0x2c52fb,_0x3ea3be;if(!isActiveDirectoryConfigured(config)){logger[_0x9028('0xf')](_0x9028('0x14'),_0x595829);return _0x168dfb(null,![],{'message':'Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'});}return db[_0x9028('0x15')]['findOne']({'where':{'id':0x1},'attributes':[_0x9028('0x16'),_0x9028('0x17')],'raw':!![]})['then'](function(_0x3143ea){_0x2c52fb=_0x3143ea;if(!_0x2c52fb[_0x9028('0x16')]){logger[_0x9028('0xf')](_0x9028('0x18'),_0x595829);throw new Error(_0x9028('0x12'));}return _0x4b14c6[_0x9028('0x19')]({'attributes':['id',_0x9028('0x1a'),'password','salt',_0x9028('0x1b'),_0x9028('0x1c'),_0x9028('0x1d'),_0x9028('0x1e'),_0x9028('0x1f')],'where':{'name':_0x595829,'role':{'$or':[_0x9028('0x20'),_0x9028('0x21'),'agent']},'adSsoEnabled':!![]}});})[_0x9028('0x22')](function(_0xd2fcf1){if(!_0xd2fcf1||_0xd2fcf1&&_0xd2fcf1[_0x9028('0x1a')]!==_0x595829){throw new Error(_0x9028('0x12'));}_0x3ea3be=_0xd2fcf1;var _0x1c1e01=_0x3ea3be[_0x9028('0x1a')]+'@'+config[_0x9028('0xb')]['domain'];return adAuthenticate(config[_0x9028('0xb')],_0x1c1e01,_0x519ec8);})['then'](function(_0x1dd627){if(_0x3ea3be['disabled']){throw new Error(_0x9028('0x12'));}if(_0x2c52fb[_0x9028('0x17')]>0x0){if(_0x3ea3be[_0x9028('0x1d')]){if(moment(_0x3ea3be[_0x9028('0x1e')])[_0x9028('0x23')](_0x2c52fb[_0x9028('0x17')],_0x9028('0x24'))>moment()){throw new Error(_0x9028('0x12'));}return utils['clearBlockUser'](_0x3ea3be,0x0,![],null)[_0x9028('0x22')](function(){return utils['getLicense'](_0x3ea3be);})[_0x9028('0x22')](function(){return _0x168dfb(null,_0x3ea3be);});}else{return utils[_0x9028('0x25')](_0x3ea3be)['then'](function(){return _0x168dfb(null,_0x3ea3be);});}}else{return utils[_0x9028('0x25')](_0x3ea3be)['then'](function(){return _0x168dfb(null,_0x3ea3be);});}})[_0x9028('0x26')](function(_0x4ed78f){return _0x168dfb(null,![],_0x4ed78f);});}function handleError(_0x5571cd,_0x5ed476,_0xd160cb){return _0x5571cd['status'](_0x5ed476||0x1f4)[_0x9028('0x27')]({'message':_0xd160cb?_0xd160cb['message']||_0xd160cb:''});}exports[_0x9028('0x28')]=function(_0x2cc558,_0x4c1913,_0x90fc26){passport['authenticate'](_0x9028('0x29'),function(_0x4eba52,_0x37996d,_0x12cfdf){var _0x4141a3=_0x4eba52||_0x12cfdf;if(_0x4141a3){return handleError(_0x4c1913,0x191,_0x4141a3);}if(!_0x37996d){return handleError(_0x4c1913,0x194,{'message':'Something\x20went\x20wrong,\x20please\x20try\x20again.'});}else{var _0x491071={'payload':{'id':_0x37996d['id'],'role':_0x37996d['role']},'options':{'expiresIn':0x15180}};return authService[_0x9028('0x2a')](_0x491071)[_0x9028('0x22')](function(_0x49cccc){_0x4c1913[_0x9028('0x2b')]({'id':_0x37996d['id'],'token':_0x49cccc,'statusCall':'','isAlreadyLogged':_0x37996d['online']});});}})(_0x2cc558,_0x4c1913,_0x90fc26);};passport['use']('ad-login',new LocalStrategy({'usernameField':'name','passwordField':_0x9028('0x2c')},function(_0x1573c8,_0x41d925,_0x58ac2b){return ActiveDirectoryAuthenticate(db[_0x9028('0x2d')],_0x1573c8,_0x41d925,_0x58ac2b);}));
\ No newline at end of file