Built motion from commit 775e2a94.|2.6.3
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 4061a18..a35c4cf 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 _0x72a4=['use','ad-login','User','passport-local','Strategy','moment','bluebird','util','../../mysqldb','../../components/auth/service','../../config/environment','../../config/logger','api','activedirectory','undefined','url','domain','authenticate','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','findOne','adSsoEnabled','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','salt','blocked','online','admin','agent','disabled','blockDuration','blockedAt','clearBlockUser','getLicense','catch','status','send','message','login','signToken','json'];(function(_0x46b46d,_0x3758ff){var _0x49b2d6=function(_0x113f56){while(--_0x113f56){_0x46b46d['push'](_0x46b46d['shift']());}};_0x49b2d6(++_0x3758ff);}(_0x72a4,0x1c5));var _0x472a=function(_0x1c9f8c,_0x39c5e3){_0x1c9f8c=_0x1c9f8c-0x0;var _0x5bcb6e=_0x72a4[_0x1c9f8c];return _0x5bcb6e;};'use strict';var passport=require('passport');var LocalStrategy=require(_0x472a('0x0'))[_0x472a('0x1')];var moment=require(_0x472a('0x2'));var ActiveDirectory=require('activedirectory2');var BPromise=require(_0x472a('0x3'));var util=require(_0x472a('0x4'));var db=require(_0x472a('0x5'))['db'];var authService=require(_0x472a('0x6'));var utils=require('../../config/utils');var config=require(_0x472a('0x7'));var logger=require(_0x472a('0x8'))(_0x472a('0x9'));function isActiveDirectoryConfigured(_0x584734){var _0xfb3ba6=![];if(typeof _0x584734[_0x472a('0xa')]!==_0x472a('0xb')){_0xfb3ba6=_0x584734[_0x472a('0xa')]['baseDN']&&_0x584734['activedirectory'][_0x472a('0xc')]&&_0x584734[_0x472a('0xa')][_0x472a('0xd')];}return _0xfb3ba6;}function adAuthenticate(_0x3f8d81,_0x491a09,_0x59eab8){return new BPromise(function(_0x72a0be,_0x5108f1){try{var _0x42d3bf=new ActiveDirectory(_0x3f8d81);_0x42d3bf[_0x472a('0xe')](_0x491a09,_0x59eab8,function(_0x2471c9,_0x3ec493){if(_0x2471c9){logger['error'](_0x472a('0xf'),_0x491a09,util[_0x472a('0x10')](_0x2471c9,{'showHidden':![],'depth':null}));_0x5108f1(_0x472a('0x11'));}else if(!_0x3ec493){logger[_0x472a('0x12')]('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x491a09);_0x5108f1(_0x472a('0x11'));}else{_0x72a0be(_0x3ec493);}});}catch(_0x383f95){_0x5108f1(_0x383f95);}});}function ActiveDirectoryAuthenticate(_0x3bddc5,_0x54799e,_0x19583a,_0x197e49){var _0x2167b4,_0x529b68;if(!isActiveDirectoryConfigured(config)){logger[_0x472a('0x12')](_0x472a('0x13'),_0x54799e);return _0x197e49(null,![],{'message':_0x472a('0x11')});}return db['Setting'][_0x472a('0x14')]({'where':{'id':0x1},'attributes':[_0x472a('0x15'),'blockDuration'],'raw':!![]})[_0x472a('0x16')](function(_0x51fd08){_0x2167b4=_0x51fd08;if(!_0x2167b4['adSsoEnabled']){logger[_0x472a('0x12')](_0x472a('0x17'),_0x54799e);throw new Error(_0x472a('0x11'));}return _0x3bddc5[_0x472a('0x14')]({'attributes':['id',_0x472a('0x18'),'password',_0x472a('0x19'),'role','disabled',_0x472a('0x1a'),'blockedAt',_0x472a('0x1b')],'where':{'name':_0x54799e,'role':{'$or':[_0x472a('0x1c'),'user',_0x472a('0x1d')]},'adSsoEnabled':!![]}});})[_0x472a('0x16')](function(_0x5866e1){if(!_0x5866e1||_0x5866e1&&_0x5866e1[_0x472a('0x18')]!==_0x54799e){throw new Error(_0x472a('0x11'));}_0x529b68=_0x5866e1;var _0x1bdc0d=_0x529b68['name']+'@'+config[_0x472a('0xa')][_0x472a('0xd')];return adAuthenticate(config[_0x472a('0xa')],_0x1bdc0d,_0x19583a);})[_0x472a('0x16')](function(_0xdf0b73){if(_0x529b68[_0x472a('0x1e')]){throw new Error(_0x472a('0x11'));}if(_0x2167b4[_0x472a('0x1f')]>0x0){if(_0x529b68[_0x472a('0x1a')]){if(moment(_0x529b68[_0x472a('0x20')])['add'](_0x2167b4[_0x472a('0x1f')],'minutes')>moment()){throw new Error(_0x472a('0x11'));}return utils[_0x472a('0x21')](_0x529b68,0x0,![],null)[_0x472a('0x16')](function(){return utils[_0x472a('0x22')](_0x529b68);})[_0x472a('0x16')](function(){return _0x197e49(null,_0x529b68);});}else{return utils[_0x472a('0x22')](_0x529b68)[_0x472a('0x16')](function(){return _0x197e49(null,_0x529b68);});}}else{return utils[_0x472a('0x22')](_0x529b68)[_0x472a('0x16')](function(){return _0x197e49(null,_0x529b68);});}})[_0x472a('0x23')](function(_0x132b8){return _0x197e49(null,![],_0x132b8);});}function handleError(_0x1c2dd4,_0x548327,_0x41ae29){return _0x1c2dd4[_0x472a('0x24')](_0x548327||0x1f4)[_0x472a('0x25')]({'message':_0x41ae29?_0x41ae29[_0x472a('0x26')]||_0x41ae29:''});}exports[_0x472a('0x27')]=function(_0x3905f4,_0x3f64d0,_0x17d5eb){passport[_0x472a('0xe')]('ad-login',function(_0x56bb32,_0x49f16a,_0x591b36){var _0x35e4dc=_0x56bb32||_0x591b36;if(_0x35e4dc){return handleError(_0x3f64d0,0x191,_0x35e4dc);}if(!_0x49f16a){return handleError(_0x3f64d0,0x194,{'message':'Something\x20went\x20wrong,\x20please\x20try\x20again.'});}else{var _0x3783ae={'payload':{'id':_0x49f16a['id'],'role':_0x49f16a['role']},'options':{'expiresIn':0x15180}};return authService[_0x472a('0x28')](_0x3783ae)['then'](function(_0x17b276){_0x3f64d0[_0x472a('0x29')]({'id':_0x49f16a['id'],'token':_0x17b276,'statusCall':'','isAlreadyLogged':_0x49f16a['online']});});}})(_0x3905f4,_0x3f64d0,_0x17d5eb);};passport[_0x472a('0x2a')](_0x472a('0x2b'),new LocalStrategy({'usernameField':_0x472a('0x18'),'passwordField':'password'},function(_0x57a04f,_0x35182f,_0x18c873){return ActiveDirectoryAuthenticate(db[_0x472a('0x2c')],_0x57a04f,_0x35182f,_0x18c873);}));
\ No newline at end of file