Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 2167b88..f9254ea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc73b=['json','use','ad-login','User','passport','passport-local','Strategy','activedirectory2','util','../../config/environment','../../config/logger','undefined','baseDN','activedirectory','url','domain','error','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Error\x20authenticate\x20%s:\x20Wrong\x20credentials','findOne','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','role','disabled','blocked','online','agent','then','blockDuration','blockedAt','add','getLicense','login','Something\x20went\x20wrong,\x20please\x20try\x20again.'];(function(_0x339d4c,_0x55d105){var _0x17ab6a=function(_0x4163eb){while(--_0x4163eb){_0x339d4c['push'](_0x339d4c['shift']());}};_0x17ab6a(++_0x55d105);}(_0xc73b,0x134));var _0xbc73=function(_0x514b87,_0x289744){_0x514b87=_0x514b87-0x0;var _0x28bf7b=_0xc73b[_0x514b87];return _0x28bf7b;};'use strict';var passport=require(_0xbc73('0x0'));var LocalStrategy=require(_0xbc73('0x1'))[_0xbc73('0x2')];var moment=require('moment');var ActiveDirectory=require(_0xbc73('0x3'));var BPromise=require('bluebird');var util=require(_0xbc73('0x4'));var db=require('../../mysqldb')['db'];var authService=require('../../components/auth/service');var utils=require('../../config/utils');var config=require(_0xbc73('0x5'));var logger=require(_0xbc73('0x6'))('api');function isActiveDirectoryConfigured(_0x19bbcf){var _0x2c6d46=![];if(typeof _0x19bbcf['activedirectory']!==_0xbc73('0x7')){_0x2c6d46=_0x19bbcf['activedirectory'][_0xbc73('0x8')]&&_0x19bbcf[_0xbc73('0x9')][_0xbc73('0xa')]&&_0x19bbcf[_0xbc73('0x9')][_0xbc73('0xb')];}return _0x2c6d46;}function adAuthenticate(_0x2fbf15,_0x3d7e22,_0x5b4b34){return new BPromise(function(_0xc8dbb0,_0xd7bf47){try{var _0x4a79e0=new ActiveDirectory(_0x2fbf15);_0x4a79e0['authenticate'](_0x3d7e22,_0x5b4b34,function(_0x4d6211,_0x1d89a2){if(_0x4d6211){logger[_0xbc73('0xc')]('Error\x20authenticate\x20%s:\x20%s',_0x3d7e22,util[_0xbc73('0xd')](_0x4d6211,{'showHidden':![],'depth':null}));_0xd7bf47(_0xbc73('0xe'));}else if(!_0x1d89a2){logger[_0xbc73('0xc')](_0xbc73('0xf'),_0x3d7e22);_0xd7bf47('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{_0xc8dbb0(_0x1d89a2);}});}catch(_0x228090){_0xd7bf47(_0x228090);}});}function ActiveDirectoryAuthenticate(_0x44cc33,_0x43c536,_0xea7ae,_0x11014c){var _0x327306,_0x61bda2;if(!isActiveDirectoryConfigured(config)){logger[_0xbc73('0xc')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x43c536);return _0x11014c(null,![],{'message':_0xbc73('0xe')});}return db['Setting'][_0xbc73('0x10')]({'where':{'id':0x1},'attributes':[_0xbc73('0x11'),'blockDuration'],'raw':!![]})['then'](function(_0x465ad8){_0x327306=_0x465ad8;if(!_0x327306[_0xbc73('0x11')]){logger[_0xbc73('0xc')](_0xbc73('0x12'),_0x43c536);throw new Error(_0xbc73('0xe'));}return _0x44cc33[_0xbc73('0x10')]({'logging':!![],'attributes':['id',_0xbc73('0x13'),_0xbc73('0x14'),_0xbc73('0x15'),_0xbc73('0x16'),_0xbc73('0x17'),_0xbc73('0x18'),'blockedAt',_0xbc73('0x19')],'where':{'name':_0x43c536,'role':{'$or':['admin','user',_0xbc73('0x1a')]},'adSsoEnabled':!![]}});})[_0xbc73('0x1b')](function(_0x4d1660){if(!_0x4d1660||_0x4d1660&&_0x4d1660['name']!==_0x43c536){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}_0x61bda2=_0x4d1660;var _0x256af5=_0x61bda2[_0xbc73('0x13')]+'@'+config[_0xbc73('0x9')][_0xbc73('0xb')];return adAuthenticate(config[_0xbc73('0x9')],_0x256af5,_0xea7ae);})[_0xbc73('0x1b')](function(_0x13e237){if(_0x61bda2['disabled']){throw new Error(_0xbc73('0xe'));}if(_0x327306[_0xbc73('0x1c')]>0x0){if(_0x61bda2[_0xbc73('0x18')]){if(moment(_0x61bda2[_0xbc73('0x1d')])[_0xbc73('0x1e')](_0x327306[_0xbc73('0x1c')],'minutes')>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils['clearBlockUser'](_0x61bda2,0x0,![],null)[_0xbc73('0x1b')](function(){return utils['getLicense'](_0x61bda2);})[_0xbc73('0x1b')](function(){return _0x11014c(null,_0x61bda2);});}else{return utils[_0xbc73('0x1f')](_0x61bda2)[_0xbc73('0x1b')](function(){return _0x11014c(null,_0x61bda2);});}}else{return utils[_0xbc73('0x1f')](_0x61bda2)[_0xbc73('0x1b')](function(){return _0x11014c(null,_0x61bda2);});}})['catch'](function(_0x4ba22c){return _0x11014c(null,![],_0x4ba22c);});}function handleError(_0x51499f,_0x46fcb1,_0x5ad000){return _0x51499f['status'](_0x46fcb1||0x1f4)['send']({'message':_0x5ad000?_0x5ad000['message']||_0x5ad000:''});}exports[_0xbc73('0x20')]=function(_0x4bf46a,_0x5e6ea0,_0x42b0ea){passport['authenticate']('ad-login',function(_0x46495d,_0x52877f,_0x41395d){var _0x3eaf3c=_0x46495d||_0x41395d;if(_0x3eaf3c){return handleError(_0x5e6ea0,0x191,_0x3eaf3c);}if(!_0x52877f){return handleError(_0x5e6ea0,0x194,{'message':_0xbc73('0x21')});}else{var _0x4419e2={'payload':{'id':_0x52877f['id'],'role':_0x52877f[_0xbc73('0x16')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x4419e2)[_0xbc73('0x1b')](function(_0x55ca35){_0x5e6ea0[_0xbc73('0x22')]({'id':_0x52877f['id'],'token':_0x55ca35,'statusCall':'','isAlreadyLogged':_0x52877f[_0xbc73('0x19')]});});}})(_0x4bf46a,_0x5e6ea0,_0x42b0ea);};passport[_0xbc73('0x23')](_0xbc73('0x24'),new LocalStrategy({'usernameField':'name','passwordField':_0xbc73('0x14')},function(_0x3ac7b9,_0x3da822,_0x5dded3){return ActiveDirectoryAuthenticate(db[_0xbc73('0x25')],_0x3ac7b9,_0x3da822,_0x5dded3);}));
\ No newline at end of file
+var _0x51b7=['Strategy','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','undefined','activedirectory','baseDN','url','domain','authenticate','error','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','blockDuration','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','salt','disabled','blocked','online','user','agent','then','blockedAt','add','minutes','getLicense','catch','status','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','json','use','passport','passport-local'];(function(_0x1f175e,_0x25487c){var _0x4ab74c=function(_0x301e14){while(--_0x301e14){_0x1f175e['push'](_0x1f175e['shift']());}};_0x4ab74c(++_0x25487c);}(_0x51b7,0x19e));var _0x751b=function(_0x197551,_0x2955b0){_0x197551=_0x197551-0x0;var _0x55d8b2=_0x51b7[_0x197551];return _0x55d8b2;};'use strict';var passport=require(_0x751b('0x0'));var LocalStrategy=require(_0x751b('0x1'))[_0x751b('0x2')];var moment=require('moment');var ActiveDirectory=require(_0x751b('0x3'));var BPromise=require(_0x751b('0x4'));var util=require(_0x751b('0x5'));var db=require(_0x751b('0x6'))['db'];var authService=require(_0x751b('0x7'));var utils=require(_0x751b('0x8'));var config=require(_0x751b('0x9'));var logger=require(_0x751b('0xa'))(_0x751b('0xb'));function isActiveDirectoryConfigured(_0x278252){var _0x47dc20=![];if(typeof _0x278252['activedirectory']!==_0x751b('0xc')){_0x47dc20=_0x278252[_0x751b('0xd')][_0x751b('0xe')]&&_0x278252[_0x751b('0xd')][_0x751b('0xf')]&&_0x278252[_0x751b('0xd')][_0x751b('0x10')];}return _0x47dc20;}function adAuthenticate(_0x23f679,_0x64ad5c,_0x33b62d){return new BPromise(function(_0x230e0c,_0x27b8e6){try{var _0x3a0eaf=new ActiveDirectory(_0x23f679);_0x3a0eaf[_0x751b('0x11')](_0x64ad5c,_0x33b62d,function(_0x1d23fa,_0x383401){if(_0x1d23fa){logger[_0x751b('0x12')]('Error\x20authenticate\x20%s:\x20%s',_0x64ad5c,util[_0x751b('0x13')](_0x1d23fa,{'showHidden':![],'depth':null}));_0x27b8e6(_0x751b('0x14'));}else if(!_0x383401){logger[_0x751b('0x12')](_0x751b('0x15'),_0x64ad5c);_0x27b8e6(_0x751b('0x14'));}else{_0x230e0c(_0x383401);}});}catch(_0x2f050e){_0x27b8e6(_0x2f050e);}});}function ActiveDirectoryAuthenticate(_0x3a3a99,_0x540186,_0x5beb43,_0x13b293){var _0x3bda04,_0x2f3b41;if(!isActiveDirectoryConfigured(config)){logger[_0x751b('0x12')](_0x751b('0x16'),_0x540186);return _0x13b293(null,![],{'message':_0x751b('0x14')});}return db[_0x751b('0x17')][_0x751b('0x18')]({'where':{'id':0x1},'attributes':[_0x751b('0x19'),_0x751b('0x1a')],'raw':!![]})['then'](function(_0x4cbe77){_0x3bda04=_0x4cbe77;if(!_0x3bda04[_0x751b('0x19')]){logger[_0x751b('0x12')](_0x751b('0x1b'),_0x540186);throw new Error(_0x751b('0x14'));}return _0x3a3a99[_0x751b('0x18')]({'attributes':['id',_0x751b('0x1c'),_0x751b('0x1d'),_0x751b('0x1e'),'role',_0x751b('0x1f'),_0x751b('0x20'),'blockedAt',_0x751b('0x21')],'where':{'name':_0x540186,'role':{'$or':['admin',_0x751b('0x22'),_0x751b('0x23')]},'adSsoEnabled':!![]}});})['then'](function(_0x56d32e){if(!_0x56d32e||_0x56d32e&&_0x56d32e[_0x751b('0x1c')]!==_0x540186){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}_0x2f3b41=_0x56d32e;var _0x4fe256=_0x2f3b41[_0x751b('0x1c')]+'@'+config['activedirectory'][_0x751b('0x10')];return adAuthenticate(config[_0x751b('0xd')],_0x4fe256,_0x5beb43);})[_0x751b('0x24')](function(_0x131098){if(_0x2f3b41[_0x751b('0x1f')]){throw new Error(_0x751b('0x14'));}if(_0x3bda04[_0x751b('0x1a')]>0x0){if(_0x2f3b41['blocked']){if(moment(_0x2f3b41[_0x751b('0x25')])[_0x751b('0x26')](_0x3bda04['blockDuration'],_0x751b('0x27'))>moment()){throw new Error(_0x751b('0x14'));}return utils['clearBlockUser'](_0x2f3b41,0x0,![],null)['then'](function(){return utils[_0x751b('0x28')](_0x2f3b41);})['then'](function(){return _0x13b293(null,_0x2f3b41);});}else{return utils[_0x751b('0x28')](_0x2f3b41)[_0x751b('0x24')](function(){return _0x13b293(null,_0x2f3b41);});}}else{return utils[_0x751b('0x28')](_0x2f3b41)[_0x751b('0x24')](function(){return _0x13b293(null,_0x2f3b41);});}})[_0x751b('0x29')](function(_0x30ed93){return _0x13b293(null,![],_0x30ed93);});}function handleError(_0xce7a1e,_0x6105e2,_0x1429e1){return _0xce7a1e[_0x751b('0x2a')](_0x6105e2||0x1f4)[_0x751b('0x2b')]({'message':_0x1429e1?_0x1429e1[_0x751b('0x2c')]||_0x1429e1:''});}exports[_0x751b('0x2d')]=function(_0x1ccc83,_0x4640bd,_0x49d1de){passport[_0x751b('0x11')](_0x751b('0x2e'),function(_0x2815dc,_0x2fb851,_0x1e786f){var _0x827599=_0x2815dc||_0x1e786f;if(_0x827599){return handleError(_0x4640bd,0x191,_0x827599);}if(!_0x2fb851){return handleError(_0x4640bd,0x194,{'message':_0x751b('0x2f')});}else{var _0x4dedef={'payload':{'id':_0x2fb851['id'],'role':_0x2fb851[_0x751b('0x30')]},'options':{'expiresIn':0x15180}};return authService[_0x751b('0x31')](_0x4dedef)[_0x751b('0x24')](function(_0x42d7f5){_0x4640bd[_0x751b('0x32')]({'id':_0x2fb851['id'],'token':_0x42d7f5,'statusCall':'','isAlreadyLogged':_0x2fb851[_0x751b('0x21')]});});}})(_0x1ccc83,_0x4640bd,_0x49d1de);};passport[_0x751b('0x33')](_0x751b('0x2e'),new LocalStrategy({'usernameField':_0x751b('0x1c'),'passwordField':_0x751b('0x1d')},function(_0x1133e4,_0x1eba16,_0x1c0236){return ActiveDirectoryAuthenticate(db['User'],_0x1133e4,_0x1eba16,_0x1c0236);}));
\ No newline at end of file