Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 1441b7c..fc5ad61 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa9f6=['disabled','blocked','blockedAt','online','admin','user','agent','then','blockDuration','minutes','getLicense','catch','status','send','message','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','passport','Strategy','moment','activedirectory2','util','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','activedirectory','undefined','baseDN','url','domain','authenticate','error','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','role'];(function(_0x27c4fe,_0x526312){var _0x3ba97d=function(_0x536243){while(--_0x536243){_0x27c4fe['push'](_0x27c4fe['shift']());}};_0x3ba97d(++_0x526312);}(_0xa9f6,0x14e));var _0x6a9f=function(_0x55a422,_0x1b09fc){_0x55a422=_0x55a422-0x0;var _0xce15c8=_0xa9f6[_0x55a422];return _0xce15c8;};'use strict';var passport=require(_0x6a9f('0x0'));var LocalStrategy=require('passport-local')[_0x6a9f('0x1')];var moment=require(_0x6a9f('0x2'));var ActiveDirectory=require(_0x6a9f('0x3'));var BPromise=require('bluebird');var util=require(_0x6a9f('0x4'));var db=require('../../mysqldb')['db'];var authService=require(_0x6a9f('0x5'));var utils=require(_0x6a9f('0x6'));var config=require(_0x6a9f('0x7'));var logger=require(_0x6a9f('0x8'))('api');function isActiveDirectoryConfigured(_0x26a6ab){var _0x3e52d7=![];if(typeof _0x26a6ab[_0x6a9f('0x9')]!==_0x6a9f('0xa')){_0x3e52d7=_0x26a6ab[_0x6a9f('0x9')][_0x6a9f('0xb')]&&_0x26a6ab['activedirectory'][_0x6a9f('0xc')]&&_0x26a6ab['activedirectory'][_0x6a9f('0xd')];}return _0x3e52d7;}function adAuthenticate(_0x518002,_0x2d48f6,_0x2a9658){return new BPromise(function(_0x20cbf0,_0x3c10c4){try{var _0x556e79=new ActiveDirectory(_0x518002);_0x556e79[_0x6a9f('0xe')](_0x2d48f6,_0x2a9658,function(_0x5fbcf2,_0x2ac853){if(_0x5fbcf2){logger[_0x6a9f('0xf')]('Error\x20authenticate\x20%s:\x20%s',_0x2d48f6,util['inspect'](_0x5fbcf2,{'showHidden':![],'depth':null}));_0x3c10c4(_0x6a9f('0x10'));}else if(!_0x2ac853){logger[_0x6a9f('0xf')]('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x2d48f6);_0x3c10c4(_0x6a9f('0x10'));}else{_0x20cbf0(_0x2ac853);}});}catch(_0x5c0ca1){_0x3c10c4(_0x5c0ca1);}});}function ActiveDirectoryAuthenticate(_0x2c3ebe,_0x1bf75e,_0x4f3eae,_0x4701c7){var _0x5cad6b,_0x3599c9;if(!isActiveDirectoryConfigured(config)){logger['error'](_0x6a9f('0x11'),_0x1bf75e);return _0x4701c7(null,![],{'message':_0x6a9f('0x10')});}return db[_0x6a9f('0x12')][_0x6a9f('0x13')]({'where':{'id':0x1},'attributes':[_0x6a9f('0x14'),'blockDuration'],'raw':!![]})['then'](function(_0x5e4d29){_0x5cad6b=_0x5e4d29;if(!_0x5cad6b['adSsoEnabled']){logger[_0x6a9f('0xf')](_0x6a9f('0x15'),_0x1bf75e);throw new Error(_0x6a9f('0x10'));}return _0x2c3ebe[_0x6a9f('0x13')]({'attributes':['id',_0x6a9f('0x16'),_0x6a9f('0x17'),_0x6a9f('0x18'),_0x6a9f('0x19'),_0x6a9f('0x1a'),_0x6a9f('0x1b'),_0x6a9f('0x1c'),_0x6a9f('0x1d')],'where':{'name':_0x1bf75e,'role':{'$or':[_0x6a9f('0x1e'),_0x6a9f('0x1f'),_0x6a9f('0x20')]},'adSsoEnabled':!![]}});})['then'](function(_0x5b6d34){if(!_0x5b6d34||_0x5b6d34&&_0x5b6d34[_0x6a9f('0x16')]!==_0x1bf75e){throw new Error(_0x6a9f('0x10'));}_0x3599c9=_0x5b6d34;var _0x1812b0=_0x3599c9[_0x6a9f('0x16')]+'@'+config['activedirectory']['domain'];return adAuthenticate(config['activedirectory'],_0x1812b0,_0x4f3eae);})[_0x6a9f('0x21')](function(_0x151322){if(_0x3599c9[_0x6a9f('0x1a')]){throw new Error(_0x6a9f('0x10'));}if(_0x5cad6b['blockDuration']>0x0){if(_0x3599c9[_0x6a9f('0x1b')]){if(moment(_0x3599c9[_0x6a9f('0x1c')])['add'](_0x5cad6b[_0x6a9f('0x22')],_0x6a9f('0x23'))>moment()){throw new Error(_0x6a9f('0x10'));}return utils['clearBlockUser'](_0x3599c9,0x0,![],null)[_0x6a9f('0x21')](function(){return utils[_0x6a9f('0x24')](_0x3599c9);})['then'](function(){return _0x4701c7(null,_0x3599c9);});}else{return utils[_0x6a9f('0x24')](_0x3599c9)[_0x6a9f('0x21')](function(){return _0x4701c7(null,_0x3599c9);});}}else{return utils[_0x6a9f('0x24')](_0x3599c9)['then'](function(){return _0x4701c7(null,_0x3599c9);});}})[_0x6a9f('0x25')](function(_0x2cf7e0){return _0x4701c7(null,![],_0x2cf7e0);});}function handleError(_0x23e6d7,_0x2ec519,_0x54e2be){return _0x23e6d7[_0x6a9f('0x26')](_0x2ec519||0x1f4)[_0x6a9f('0x27')]({'message':_0x54e2be?_0x54e2be[_0x6a9f('0x28')]||_0x54e2be:''});}exports['login']=function(_0x445749,_0x14bf92,_0x669a34){passport['authenticate'](_0x6a9f('0x29'),function(_0x20a7e3,_0x21c558,_0x17d799){var _0x876269=_0x20a7e3||_0x17d799;if(_0x876269){return handleError(_0x14bf92,0x191,_0x876269);}if(!_0x21c558){return handleError(_0x14bf92,0x194,{'message':_0x6a9f('0x2a')});}else{var _0x4b7e11={'payload':{'id':_0x21c558['id'],'role':_0x21c558[_0x6a9f('0x19')]},'options':{'expiresIn':0x15180}};return authService[_0x6a9f('0x2b')](_0x4b7e11)['then'](function(_0x257266){_0x14bf92[_0x6a9f('0x2c')]({'id':_0x21c558['id'],'token':_0x257266,'statusCall':'','isAlreadyLogged':_0x21c558[_0x6a9f('0x1d')]});});}})(_0x445749,_0x14bf92,_0x669a34);};passport['use'](_0x6a9f('0x29'),new LocalStrategy({'usernameField':_0x6a9f('0x16'),'passwordField':_0x6a9f('0x17')},function(_0x23e62b,_0x3b0f5d,_0x204cc9){return ActiveDirectoryAuthenticate(db['User'],_0x23e62b,_0x3b0f5d,_0x204cc9);}));
\ 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