Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 4061a18..fc5ad61 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x194c=['Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','findOne','adSsoEnabled','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','role','disabled','blocked','blockedAt','online','user','agent','minutes','getLicense','catch','status','send','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','json','use','User','passport','passport-local','Strategy','moment','activedirectory2','bluebird','util','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','activedirectory','undefined','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'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x194c,0x19b));var _0xc194=function(_0x4e8452,_0xf5645a){_0x4e8452=_0x4e8452-0x0;var _0x2b97f4=_0x194c[_0x4e8452];return _0x2b97f4;};'use strict';var passport=require(_0xc194('0x0'));var LocalStrategy=require(_0xc194('0x1'))[_0xc194('0x2')];var moment=require(_0xc194('0x3'));var ActiveDirectory=require(_0xc194('0x4'));var BPromise=require(_0xc194('0x5'));var util=require(_0xc194('0x6'));var db=require('../../mysqldb')['db'];var authService=require(_0xc194('0x7'));var utils=require(_0xc194('0x8'));var config=require(_0xc194('0x9'));var logger=require(_0xc194('0xa'))(_0xc194('0xb'));function isActiveDirectoryConfigured(_0x330147){var _0x17462b=![];if(typeof _0x330147[_0xc194('0xc')]!==_0xc194('0xd')){_0x17462b=_0x330147[_0xc194('0xc')]['baseDN']&&_0x330147[_0xc194('0xc')]['url']&&_0x330147[_0xc194('0xc')][_0xc194('0xe')];}return _0x17462b;}function adAuthenticate(_0x7a75b9,_0x5bdc73,_0x3f547c){return new BPromise(function(_0x5608d8,_0x52124e){try{var _0x35c2c2=new ActiveDirectory(_0x7a75b9);_0x35c2c2[_0xc194('0xf')](_0x5bdc73,_0x3f547c,function(_0xb8bcd2,_0x585768){if(_0xb8bcd2){logger[_0xc194('0x10')](_0xc194('0x11'),_0x5bdc73,util[_0xc194('0x12')](_0xb8bcd2,{'showHidden':![],'depth':null}));_0x52124e(_0xc194('0x13'));}else if(!_0x585768){logger['error'](_0xc194('0x14'),_0x5bdc73);_0x52124e('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{_0x5608d8(_0x585768);}});}catch(_0x14920a){_0x52124e(_0x14920a);}});}function ActiveDirectoryAuthenticate(_0x3b832d,_0x4222bd,_0x4ad6c2,_0x46a877){var _0x34a170,_0x4abcc7;if(!isActiveDirectoryConfigured(config)){logger[_0xc194('0x10')](_0xc194('0x15'),_0x4222bd);return _0x46a877(null,![],{'message':_0xc194('0x13')});}return db['Setting'][_0xc194('0x16')]({'where':{'id':0x1},'attributes':[_0xc194('0x17'),_0xc194('0x18')],'raw':!![]})[_0xc194('0x19')](function(_0x16789f){_0x34a170=_0x16789f;if(!_0x34a170[_0xc194('0x17')]){logger['error'](_0xc194('0x1a'),_0x4222bd);throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return _0x3b832d[_0xc194('0x16')]({'logging':!![],'attributes':['id',_0xc194('0x1b'),_0xc194('0x1c'),_0xc194('0x1d'),_0xc194('0x1e'),_0xc194('0x1f'),_0xc194('0x20'),_0xc194('0x21'),_0xc194('0x22')],'where':{'name':_0x4222bd,'role':{'$or':['admin',_0xc194('0x23'),_0xc194('0x24')]},'adSsoEnabled':!![]}});})['then'](function(_0xdeb133){if(!_0xdeb133||_0xdeb133&&_0xdeb133[_0xc194('0x1b')]!==_0x4222bd){throw new Error(_0xc194('0x13'));}_0x4abcc7=_0xdeb133;var _0x13e98a=_0x4abcc7['name']+'@'+config[_0xc194('0xc')][_0xc194('0xe')];return adAuthenticate(config[_0xc194('0xc')],_0x13e98a,_0x4ad6c2);})[_0xc194('0x19')](function(_0x279adb){if(_0x4abcc7['disabled']){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}if(_0x34a170[_0xc194('0x18')]>0x0){if(_0x4abcc7[_0xc194('0x20')]){if(moment(_0x4abcc7[_0xc194('0x21')])['add'](_0x34a170[_0xc194('0x18')],_0xc194('0x25'))>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils['clearBlockUser'](_0x4abcc7,0x0,![],null)[_0xc194('0x19')](function(){return utils[_0xc194('0x26')](_0x4abcc7);})['then'](function(){return _0x46a877(null,_0x4abcc7);});}else{return utils[_0xc194('0x26')](_0x4abcc7)['then'](function(){return _0x46a877(null,_0x4abcc7);});}}else{return utils[_0xc194('0x26')](_0x4abcc7)[_0xc194('0x19')](function(){return _0x46a877(null,_0x4abcc7);});}})[_0xc194('0x27')](function(_0x370f90){return _0x46a877(null,![],_0x370f90);});}function handleError(_0x1e30a9,_0x284d89,_0x567d7f){return _0x1e30a9[_0xc194('0x28')](_0x284d89||0x1f4)[_0xc194('0x29')]({'message':_0x567d7f?_0x567d7f['message']||_0x567d7f:''});}exports[_0xc194('0x2a')]=function(_0x364641,_0x9e77a1,_0x2bbb47){passport['authenticate'](_0xc194('0x2b'),function(_0x88598c,_0x54b6e9,_0x19cbbb){var _0x6ebb26=_0x88598c||_0x19cbbb;if(_0x6ebb26){return handleError(_0x9e77a1,0x191,_0x6ebb26);}if(!_0x54b6e9){return handleError(_0x9e77a1,0x194,{'message':_0xc194('0x2c')});}else{var _0x4f335a={'payload':{'id':_0x54b6e9['id'],'role':_0x54b6e9[_0xc194('0x1e')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x4f335a)[_0xc194('0x19')](function(_0x45b007){_0x9e77a1[_0xc194('0x2d')]({'id':_0x54b6e9['id'],'token':_0x45b007,'statusCall':'','isAlreadyLogged':_0x54b6e9[_0xc194('0x22')]});});}})(_0x364641,_0x9e77a1,_0x2bbb47);};passport[_0xc194('0x2e')]('ad-login',new LocalStrategy({'usernameField':_0xc194('0x1b'),'passwordField':_0xc194('0x1c')},function(_0x19b599,_0x4a003b,_0xc2cb8e){return ActiveDirectoryAuthenticate(db[_0xc194('0x2f')],_0x19b599,_0x4a003b,_0xc2cb8e);}));
\ No newline at end of file
+var _0x2aa0=['add','minutes','clearBlockUser','status','send','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','json','use','User','passport','passport-local','moment','activedirectory2','util','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','activedirectory','undefined','baseDN','url','authenticate','error','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','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','password','salt','disabled','blockedAt','online','admin','user','agent','domain','blocked'];(function(_0x531cb8,_0x8ef36f){var _0x5cf297=function(_0x45acb4){while(--_0x45acb4){_0x531cb8['push'](_0x531cb8['shift']());}};_0x5cf297(++_0x8ef36f);}(_0x2aa0,0x6c));var _0x02aa=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0x2aa0[_0x57b54c];return _0x59cc19;};'use strict';var passport=require(_0x02aa('0x0'));var LocalStrategy=require(_0x02aa('0x1'))['Strategy'];var moment=require(_0x02aa('0x2'));var ActiveDirectory=require(_0x02aa('0x3'));var BPromise=require('bluebird');var util=require(_0x02aa('0x4'));var db=require('../../mysqldb')['db'];var authService=require(_0x02aa('0x5'));var utils=require(_0x02aa('0x6'));var config=require(_0x02aa('0x7'));var logger=require(_0x02aa('0x8'))(_0x02aa('0x9'));function isActiveDirectoryConfigured(_0x386694){var _0x17e58f=![];if(typeof _0x386694[_0x02aa('0xa')]!==_0x02aa('0xb')){_0x17e58f=_0x386694[_0x02aa('0xa')][_0x02aa('0xc')]&&_0x386694['activedirectory'][_0x02aa('0xd')]&&_0x386694[_0x02aa('0xa')]['domain'];}return _0x17e58f;}function adAuthenticate(_0x6b4d7f,_0x1590b1,_0x410540){return new BPromise(function(_0x4a9912,_0x5da83a){try{var _0x26d443=new ActiveDirectory(_0x6b4d7f);_0x26d443[_0x02aa('0xe')](_0x1590b1,_0x410540,function(_0x2bc880,_0x1e6be1){if(_0x2bc880){logger[_0x02aa('0xf')]('Error\x20authenticate\x20%s:\x20%s',_0x1590b1,util['inspect'](_0x2bc880,{'showHidden':![],'depth':null}));_0x5da83a('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x1e6be1){logger[_0x02aa('0xf')](_0x02aa('0x10'),_0x1590b1);_0x5da83a(_0x02aa('0x11'));}else{_0x4a9912(_0x1e6be1);}});}catch(_0x24c2ce){_0x5da83a(_0x24c2ce);}});}function ActiveDirectoryAuthenticate(_0x2a00da,_0x191bd3,_0x119662,_0x32787){var _0x14988e,_0x3a0f8c;if(!isActiveDirectoryConfigured(config)){logger[_0x02aa('0xf')](_0x02aa('0x12'),_0x191bd3);return _0x32787(null,![],{'message':_0x02aa('0x11')});}return db[_0x02aa('0x13')][_0x02aa('0x14')]({'where':{'id':0x1},'attributes':[_0x02aa('0x15'),_0x02aa('0x16')],'raw':!![]})[_0x02aa('0x17')](function(_0xb0bc12){_0x14988e=_0xb0bc12;if(!_0x14988e[_0x02aa('0x15')]){logger['error'](_0x02aa('0x18'),_0x191bd3);throw new Error(_0x02aa('0x11'));}return _0x2a00da['findOne']({'attributes':['id',_0x02aa('0x19'),_0x02aa('0x1a'),_0x02aa('0x1b'),'role',_0x02aa('0x1c'),'blocked',_0x02aa('0x1d'),_0x02aa('0x1e')],'where':{'name':_0x191bd3,'role':{'$or':[_0x02aa('0x1f'),_0x02aa('0x20'),_0x02aa('0x21')]},'adSsoEnabled':!![]}});})['then'](function(_0xf74047){if(!_0xf74047||_0xf74047&&_0xf74047[_0x02aa('0x19')]!==_0x191bd3){throw new Error(_0x02aa('0x11'));}_0x3a0f8c=_0xf74047;var _0x1dcc4e=_0x3a0f8c[_0x02aa('0x19')]+'@'+config[_0x02aa('0xa')][_0x02aa('0x22')];return adAuthenticate(config[_0x02aa('0xa')],_0x1dcc4e,_0x119662);})[_0x02aa('0x17')](function(_0x3a4cf5){if(_0x3a0f8c[_0x02aa('0x1c')]){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}if(_0x14988e[_0x02aa('0x16')]>0x0){if(_0x3a0f8c[_0x02aa('0x23')]){if(moment(_0x3a0f8c[_0x02aa('0x1d')])[_0x02aa('0x24')](_0x14988e[_0x02aa('0x16')],_0x02aa('0x25'))>moment()){throw new Error(_0x02aa('0x11'));}return utils[_0x02aa('0x26')](_0x3a0f8c,0x0,![],null)[_0x02aa('0x17')](function(){return utils['getLicense'](_0x3a0f8c);})[_0x02aa('0x17')](function(){return _0x32787(null,_0x3a0f8c);});}else{return utils['getLicense'](_0x3a0f8c)[_0x02aa('0x17')](function(){return _0x32787(null,_0x3a0f8c);});}}else{return utils['getLicense'](_0x3a0f8c)['then'](function(){return _0x32787(null,_0x3a0f8c);});}})['catch'](function(_0x57b1fc){return _0x32787(null,![],_0x57b1fc);});}function handleError(_0x20cf72,_0x1ccf22,_0xf93497){return _0x20cf72[_0x02aa('0x27')](_0x1ccf22||0x1f4)[_0x02aa('0x28')]({'message':_0xf93497?_0xf93497['message']||_0xf93497:''});}exports[_0x02aa('0x29')]=function(_0x2d4883,_0x444b79,_0x3a7508){passport[_0x02aa('0xe')](_0x02aa('0x2a'),function(_0x1fc70b,_0x22aac4,_0x125bee){var _0x5ecf18=_0x1fc70b||_0x125bee;if(_0x5ecf18){return handleError(_0x444b79,0x191,_0x5ecf18);}if(!_0x22aac4){return handleError(_0x444b79,0x194,{'message':_0x02aa('0x2b')});}else{var _0x560bf2={'payload':{'id':_0x22aac4['id'],'role':_0x22aac4[_0x02aa('0x2c')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x560bf2)[_0x02aa('0x17')](function(_0x592f60){_0x444b79[_0x02aa('0x2d')]({'id':_0x22aac4['id'],'token':_0x592f60,'statusCall':'','isAlreadyLogged':_0x22aac4[_0x02aa('0x1e')]});});}})(_0x2d4883,_0x444b79,_0x3a7508);};passport[_0x02aa('0x2e')]('ad-login',new LocalStrategy({'usernameField':'name','passwordField':'password'},function(_0x18f6e5,_0x4ee46c,_0x236418){return ActiveDirectoryAuthenticate(db[_0x02aa('0x2f')],_0x18f6e5,_0x4ee46c,_0x236418);}));
\ No newline at end of file