Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index db3ea43..365beb7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x62f1=['baseDN','url','domain','Error\x20authenticate\x20%s:\x20%s','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','error','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','adSsoEnabled','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','findOne','password','salt','disabled','blocked','online','admin','user','agent','name','blockedAt','getLicense','message','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','passport','Strategy','moment','activedirectory2','bluebird','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','undefined','activedirectory'];(function(_0x3b1328,_0x24be26){var _0x2d718b=function(_0x451ef3){while(--_0x451ef3){_0x3b1328['push'](_0x3b1328['shift']());}};_0x2d718b(++_0x24be26);}(_0x62f1,0x112));var _0x162f=function(_0x39b2be,_0x56fbee){_0x39b2be=_0x39b2be-0x0;var _0x510508=_0x62f1[_0x39b2be];return _0x510508;};'use strict';var passport=require(_0x162f('0x0'));var LocalStrategy=require('passport-local')[_0x162f('0x1')];var moment=require(_0x162f('0x2'));var ActiveDirectory=require(_0x162f('0x3'));var BPromise=require(_0x162f('0x4'));var util=require(_0x162f('0x5'));var db=require(_0x162f('0x6'))['db'];var authService=require(_0x162f('0x7'));var utils=require(_0x162f('0x8'));var config=require(_0x162f('0x9'));var logger=require(_0x162f('0xa'))('api');function isActiveDirectoryConfigured(_0x3caa89){var _0x2e763a=![];if(typeof _0x3caa89['activedirectory']!==_0x162f('0xb')){_0x2e763a=_0x3caa89[_0x162f('0xc')][_0x162f('0xd')]&&_0x3caa89['activedirectory'][_0x162f('0xe')]&&_0x3caa89[_0x162f('0xc')][_0x162f('0xf')];}return _0x2e763a;}function adAuthenticate(_0x2107d1,_0x54c970,_0x1eeef3){return new BPromise(function(_0x14aaa6,_0x454b6a){try{var _0x4ed5c3=new ActiveDirectory(_0x2107d1);_0x4ed5c3['authenticate'](_0x54c970,_0x1eeef3,function(_0x489525,_0x248b66){if(_0x489525){logger['error'](_0x162f('0x10'),_0x54c970,util[_0x162f('0x11')](_0x489525,{'showHidden':![],'depth':null}));_0x454b6a(_0x162f('0x12'));}else if(!_0x248b66){logger[_0x162f('0x13')]('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x54c970);_0x454b6a(_0x162f('0x12'));}else{_0x14aaa6(_0x248b66);}});}catch(_0x2bf9f0){_0x454b6a(_0x2bf9f0);}});}function ActiveDirectoryAuthenticate(_0x3daa69,_0x130db8,_0x567f37,_0x195085){var _0x4e48e1,_0x250983;if(!isActiveDirectoryConfigured(config)){logger[_0x162f('0x13')](_0x162f('0x14'),_0x130db8);return _0x195085(null,![],{'message':_0x162f('0x12')});}return db['Setting']['findOne']({'where':{'id':0x1},'attributes':[_0x162f('0x15'),_0x162f('0x16')],'raw':!![]})[_0x162f('0x17')](function(_0x1ee433){_0x4e48e1=_0x1ee433;if(!_0x4e48e1[_0x162f('0x15')]){logger[_0x162f('0x13')](_0x162f('0x18'),_0x130db8);throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return _0x3daa69[_0x162f('0x19')]({'attributes':['id','name',_0x162f('0x1a'),_0x162f('0x1b'),'role',_0x162f('0x1c'),_0x162f('0x1d'),'blockedAt',_0x162f('0x1e')],'where':{'name':_0x130db8,'role':{'$or':[_0x162f('0x1f'),_0x162f('0x20'),_0x162f('0x21')]},'adSsoEnabled':!![]}});})['then'](function(_0xdab3e){if(!_0xdab3e||_0xdab3e&&_0xdab3e[_0x162f('0x22')]!==_0x130db8){throw new Error(_0x162f('0x12'));}_0x250983=_0xdab3e;var _0xd9d9e0=_0x250983[_0x162f('0x22')]+'@'+config[_0x162f('0xc')][_0x162f('0xf')];return adAuthenticate(config[_0x162f('0xc')],_0xd9d9e0,_0x567f37);})['then'](function(_0x352547){if(_0x250983[_0x162f('0x1c')]){throw new Error(_0x162f('0x12'));}if(_0x4e48e1[_0x162f('0x16')]>0x0){if(_0x250983['blocked']){if(moment(_0x250983[_0x162f('0x23')])['add'](_0x4e48e1[_0x162f('0x16')],'minutes')>moment()){throw new Error(_0x162f('0x12'));}return utils['clearBlockUser'](_0x250983,0x0,![],null)[_0x162f('0x17')](function(){return utils['getLicense'](_0x250983);})[_0x162f('0x17')](function(){return _0x195085(null,_0x250983);});}else{return utils[_0x162f('0x24')](_0x250983)[_0x162f('0x17')](function(){return _0x195085(null,_0x250983);});}}else{return utils['getLicense'](_0x250983)['then'](function(){return _0x195085(null,_0x250983);});}})['catch'](function(_0x580e13){return _0x195085(null,![],_0x580e13);});}function handleError(_0x3f9247,_0x1b0f5b,_0x4c4049){return _0x3f9247['status'](_0x1b0f5b||0x1f4)['send']({'message':_0x4c4049?_0x4c4049[_0x162f('0x25')]||_0x4c4049:''});}exports['login']=function(_0x43bb9a,_0x1f1c3b,_0x55b224){passport['authenticate'](_0x162f('0x26'),function(_0x3a0241,_0x34de4d,_0x543b55){var _0x313692=_0x3a0241||_0x543b55;if(_0x313692){return handleError(_0x1f1c3b,0x191,_0x313692);}if(!_0x34de4d){return handleError(_0x1f1c3b,0x194,{'message':_0x162f('0x27')});}else{var _0x1dae7c={'payload':{'id':_0x34de4d['id'],'role':_0x34de4d[_0x162f('0x28')]},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x1dae7c)['then'](function(_0x2f5e77){_0x1f1c3b['json']({'id':_0x34de4d['id'],'token':_0x2f5e77,'statusCall':'','isAlreadyLogged':_0x34de4d[_0x162f('0x1e')]});});}})(_0x43bb9a,_0x1f1c3b,_0x55b224);};passport['use']('ad-login',new LocalStrategy({'usernameField':'name','passwordField':'password'},function(_0x3853af,_0x39284d,_0x9d87a1){return ActiveDirectoryAuthenticate(db['User'],_0x3853af,_0x39284d,_0x9d87a1);}));
\ No newline at end of file
+var _0xbb27=['password','salt','role','blockedAt','admin','user','name','blocked','add','clearBlockUser','getLicense','status','send','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','online','use','User','passport','passport-local','moment','activedirectory2','util','../../mysqldb','../../config/utils','../../config/environment','../../config/logger','activedirectory','undefined','baseDN','domain','authenticate','error','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','blockDuration','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xbb27,0x1cd));var _0x7bb2=function(_0x41339a,_0x28fdc4){_0x41339a=_0x41339a-0x0;var _0x3fe50a=_0xbb27[_0x41339a];return _0x3fe50a;};'use strict';var passport=require(_0x7bb2('0x0'));var LocalStrategy=require(_0x7bb2('0x1'))['Strategy'];var moment=require(_0x7bb2('0x2'));var ActiveDirectory=require(_0x7bb2('0x3'));var BPromise=require('bluebird');var util=require(_0x7bb2('0x4'));var db=require(_0x7bb2('0x5'))['db'];var authService=require('../../components/auth/service');var utils=require(_0x7bb2('0x6'));var config=require(_0x7bb2('0x7'));var logger=require(_0x7bb2('0x8'))('api');function isActiveDirectoryConfigured(_0x2a42c7){var _0x35e860=![];if(typeof _0x2a42c7[_0x7bb2('0x9')]!==_0x7bb2('0xa')){_0x35e860=_0x2a42c7[_0x7bb2('0x9')][_0x7bb2('0xb')]&&_0x2a42c7['activedirectory']['url']&&_0x2a42c7[_0x7bb2('0x9')][_0x7bb2('0xc')];}return _0x35e860;}function adAuthenticate(_0x2971a3,_0x4a4e9d,_0x16e33b){return new BPromise(function(_0x4ed512,_0x381ffc){try{var _0x34070f=new ActiveDirectory(_0x2971a3);_0x34070f[_0x7bb2('0xd')](_0x4a4e9d,_0x16e33b,function(_0x1d49e4,_0x349bb5){if(_0x1d49e4){logger[_0x7bb2('0xe')]('Error\x20authenticate\x20%s:\x20%s',_0x4a4e9d,util[_0x7bb2('0xf')](_0x1d49e4,{'showHidden':![],'depth':null}));_0x381ffc('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(!_0x349bb5){logger['error']('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x4a4e9d);_0x381ffc(_0x7bb2('0x10'));}else{_0x4ed512(_0x349bb5);}});}catch(_0x4d467c){_0x381ffc(_0x4d467c);}});}function ActiveDirectoryAuthenticate(_0x3c7c7c,_0x32ebd4,_0x1745ec,_0x5f5c31){var _0x512585,_0x205116;if(!isActiveDirectoryConfigured(config)){logger[_0x7bb2('0xe')](_0x7bb2('0x11'),_0x32ebd4);return _0x5f5c31(null,![],{'message':'Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'});}return db[_0x7bb2('0x12')][_0x7bb2('0x13')]({'where':{'id':0x1},'attributes':['adSsoEnabled',_0x7bb2('0x14')],'raw':!![]})[_0x7bb2('0x15')](function(_0x3dc2e5){_0x512585=_0x3dc2e5;if(!_0x512585['adSsoEnabled']){logger['error'](_0x7bb2('0x16'),_0x32ebd4);throw new Error(_0x7bb2('0x10'));}return _0x3c7c7c[_0x7bb2('0x13')]({'attributes':['id','name',_0x7bb2('0x17'),_0x7bb2('0x18'),_0x7bb2('0x19'),'disabled','blocked',_0x7bb2('0x1a'),'online'],'where':{'name':_0x32ebd4,'role':{'$or':[_0x7bb2('0x1b'),_0x7bb2('0x1c'),'agent']},'adSsoEnabled':!![]}});})[_0x7bb2('0x15')](function(_0x4fcacf){if(!_0x4fcacf||_0x4fcacf&&_0x4fcacf[_0x7bb2('0x1d')]!==_0x32ebd4){throw new Error(_0x7bb2('0x10'));}_0x205116=_0x4fcacf;var _0x27b2fe=_0x205116[_0x7bb2('0x1d')]+'@'+config[_0x7bb2('0x9')][_0x7bb2('0xc')];return adAuthenticate(config[_0x7bb2('0x9')],_0x27b2fe,_0x1745ec);})[_0x7bb2('0x15')](function(_0x1e73db){if(_0x205116['disabled']){throw new Error(_0x7bb2('0x10'));}if(_0x512585[_0x7bb2('0x14')]>0x0){if(_0x205116[_0x7bb2('0x1e')]){if(moment(_0x205116[_0x7bb2('0x1a')])[_0x7bb2('0x1f')](_0x512585[_0x7bb2('0x14')],'minutes')>moment()){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}return utils[_0x7bb2('0x20')](_0x205116,0x0,![],null)[_0x7bb2('0x15')](function(){return utils['getLicense'](_0x205116);})[_0x7bb2('0x15')](function(){return _0x5f5c31(null,_0x205116);});}else{return utils[_0x7bb2('0x21')](_0x205116)[_0x7bb2('0x15')](function(){return _0x5f5c31(null,_0x205116);});}}else{return utils['getLicense'](_0x205116)['then'](function(){return _0x5f5c31(null,_0x205116);});}})['catch'](function(_0x13ec8a){return _0x5f5c31(null,![],_0x13ec8a);});}function handleError(_0x2fa7d2,_0x3c3ac5,_0x5622cb){return _0x2fa7d2[_0x7bb2('0x22')](_0x3c3ac5||0x1f4)[_0x7bb2('0x23')]({'message':_0x5622cb?_0x5622cb['message']||_0x5622cb:''});}exports[_0x7bb2('0x24')]=function(_0x184636,_0x2a1f44,_0x346087){passport[_0x7bb2('0xd')](_0x7bb2('0x25'),function(_0x16756c,_0x2afb7f,_0x19f1e5){var _0x1870c9=_0x16756c||_0x19f1e5;if(_0x1870c9){return handleError(_0x2a1f44,0x191,_0x1870c9);}if(!_0x2afb7f){return handleError(_0x2a1f44,0x194,{'message':_0x7bb2('0x26')});}else{var _0x34cda4={'payload':{'id':_0x2afb7f['id'],'role':_0x2afb7f[_0x7bb2('0x19')]},'options':{'expiresIn':0x15180}};return authService[_0x7bb2('0x27')](_0x34cda4)[_0x7bb2('0x15')](function(_0x62e935){_0x2a1f44[_0x7bb2('0x28')]({'id':_0x2afb7f['id'],'token':_0x62e935,'statusCall':'','isAlreadyLogged':_0x2afb7f[_0x7bb2('0x29')]});});}})(_0x184636,_0x2a1f44,_0x346087);};passport[_0x7bb2('0x2a')](_0x7bb2('0x25'),new LocalStrategy({'usernameField':_0x7bb2('0x1d'),'passwordField':_0x7bb2('0x17')},function(_0x256437,_0x543eaf,_0x10ccde){return ActiveDirectoryAuthenticate(db[_0x7bb2('0x2b')],_0x256437,_0x543eaf,_0x10ccde);}));
\ No newline at end of file