Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 3f38146..c6c427f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x413b=['error','Setting','findOne','adSsoEnabled','then','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','password','salt','blocked','blockedAt','admin','user','agent','name','disabled','blockDuration','add','clearBlockUser','getLicense','catch','status','send','message','login','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','role','signToken','json','use','User','passport','passport-local','moment','activedirectory2','util','../../components/auth/service','../../config/environment','api','activedirectory','undefined','baseDN','url','authenticate','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(_0x517dca,_0x2227b1){var _0x13bc6c=function(_0x5a5714){while(--_0x5a5714){_0x517dca['push'](_0x517dca['shift']());}};_0x13bc6c(++_0x2227b1);}(_0x413b,0x19f));var _0xb413=function(_0x3896ea,_0x489972){_0x3896ea=_0x3896ea-0x0;var _0x3527bf=_0x413b[_0x3896ea];return _0x3527bf;};'use strict';var passport=require(_0xb413('0x0'));var LocalStrategy=require(_0xb413('0x1'))['Strategy'];var moment=require(_0xb413('0x2'));var ActiveDirectory=require(_0xb413('0x3'));var BPromise=require('bluebird');var util=require(_0xb413('0x4'));var db=require('../../mysqldb')['db'];var authService=require(_0xb413('0x5'));var utils=require('../../config/utils');var config=require(_0xb413('0x6'));var logger=require('../../config/logger')(_0xb413('0x7'));function isActiveDirectoryConfigured(_0x1538b9){var _0x23df68=![];if(typeof _0x1538b9[_0xb413('0x8')]!==_0xb413('0x9')){_0x23df68=_0x1538b9['activedirectory'][_0xb413('0xa')]&&_0x1538b9[_0xb413('0x8')][_0xb413('0xb')]&&_0x1538b9['activedirectory']['domain'];}return _0x23df68;}function adAuthenticate(_0x2a9d3f,_0x3bd17a,_0x1c32d9){return new BPromise(function(_0x4fbae8,_0x332a87){try{var _0x5daa46=new ActiveDirectory(_0x2a9d3f);_0x5daa46[_0xb413('0xc')](_0x3bd17a,_0x1c32d9,function(_0x4d5439,_0x251f1f){if(_0x4d5439){logger['error'](_0xb413('0xd'),_0x3bd17a,util[_0xb413('0xe')](_0x4d5439,{'showHidden':![],'depth':null}));_0x332a87(_0xb413('0xf'));}else if(!_0x251f1f){logger['error'](_0xb413('0x10'),_0x3bd17a);_0x332a87(_0xb413('0xf'));}else{_0x4fbae8(_0x251f1f);}});}catch(_0xf8fbaf){_0x332a87(_0xf8fbaf);}});}function ActiveDirectoryAuthenticate(_0x58ddbd,_0x40e793,_0x44a8d0,_0x369c17){var _0x2f354f,_0xdc6d40;if(!isActiveDirectoryConfigured(config)){logger[_0xb413('0x11')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x40e793);return _0x369c17(null,![],{'message':_0xb413('0xf')});}return db[_0xb413('0x12')][_0xb413('0x13')]({'where':{'id':0x1},'attributes':[_0xb413('0x14'),'blockDuration'],'raw':!![]})[_0xb413('0x15')](function(_0x16f11d){_0x2f354f=_0x16f11d;if(!_0x2f354f[_0xb413('0x14')]){logger['error'](_0xb413('0x16'),_0x40e793);throw new Error(_0xb413('0xf'));}return _0x58ddbd[_0xb413('0x13')]({'logging':!![],'attributes':['id','name',_0xb413('0x17'),_0xb413('0x18'),'role','disabled',_0xb413('0x19'),_0xb413('0x1a'),'online'],'where':{'name':_0x40e793,'role':{'$or':[_0xb413('0x1b'),_0xb413('0x1c'),_0xb413('0x1d')]},'adSsoEnabled':!![]}});})[_0xb413('0x15')](function(_0x40da65){if(!_0x40da65||_0x40da65&&_0x40da65[_0xb413('0x1e')]!==_0x40e793){throw new Error(_0xb413('0xf'));}_0xdc6d40=_0x40da65;var _0x5f1cfd=_0xdc6d40[_0xb413('0x1e')]+'@'+config[_0xb413('0x8')]['domain'];return adAuthenticate(config['activedirectory'],_0x5f1cfd,_0x44a8d0);})[_0xb413('0x15')](function(_0x3275fc){if(_0xdc6d40[_0xb413('0x1f')]){throw new Error(_0xb413('0xf'));}if(_0x2f354f[_0xb413('0x20')]>0x0){if(_0xdc6d40['blocked']){if(moment(_0xdc6d40[_0xb413('0x1a')])[_0xb413('0x21')](_0x2f354f[_0xb413('0x20')],'minutes')>moment()){throw new Error(_0xb413('0xf'));}return utils[_0xb413('0x22')](_0xdc6d40,0x0,![],null)['then'](function(){return utils[_0xb413('0x23')](_0xdc6d40);})[_0xb413('0x15')](function(){return _0x369c17(null,_0xdc6d40);});}else{return utils['getLicense'](_0xdc6d40)[_0xb413('0x15')](function(){return _0x369c17(null,_0xdc6d40);});}}else{return utils['getLicense'](_0xdc6d40)[_0xb413('0x15')](function(){return _0x369c17(null,_0xdc6d40);});}})[_0xb413('0x24')](function(_0x10bda5){return _0x369c17(null,![],_0x10bda5);});}function handleError(_0xc679b0,_0x5c4c75,_0x5602b3){return _0xc679b0[_0xb413('0x25')](_0x5c4c75||0x1f4)[_0xb413('0x26')]({'message':_0x5602b3?_0x5602b3[_0xb413('0x27')]||_0x5602b3:''});}exports[_0xb413('0x28')]=function(_0x3d70cf,_0x4d0195,_0x1dbb67){passport[_0xb413('0xc')](_0xb413('0x29'),function(_0x4b361c,_0xdd0e70,_0x3ec8bc){var _0xf6efcd=_0x4b361c||_0x3ec8bc;if(_0xf6efcd){return handleError(_0x4d0195,0x191,_0xf6efcd);}if(!_0xdd0e70){return handleError(_0x4d0195,0x194,{'message':_0xb413('0x2a')});}else{var _0x28d1fa={'payload':{'id':_0xdd0e70['id'],'role':_0xdd0e70[_0xb413('0x2b')]},'options':{'expiresIn':0x15180}};return authService[_0xb413('0x2c')](_0x28d1fa)[_0xb413('0x15')](function(_0x3aaf10){_0x4d0195[_0xb413('0x2d')]({'id':_0xdd0e70['id'],'token':_0x3aaf10,'statusCall':'','isAlreadyLogged':_0xdd0e70['online']});});}})(_0x3d70cf,_0x4d0195,_0x1dbb67);};passport[_0xb413('0x2e')](_0xb413('0x29'),new LocalStrategy({'usernameField':'name','passwordField':_0xb413('0x17')},function(_0x20e9aa,_0xe740a9,_0x283da1){return ActiveDirectoryAuthenticate(db[_0xb413('0x2f')],_0x20e9aa,_0xe740a9,_0x283da1);}));
\ No newline at end of file
+var _0x0379=['online','admin','user','agent','blockDuration','add','minutes','clearBlockUser','then','getLicense','catch','status','send','message','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken','json','use','User','passport','passport-local','moment','activedirectory2','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','../../config/logger','api','undefined','baseDN','url','activedirectory','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','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured','Setting','findOne','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','password','role','disabled','blocked','blockedAt'];(function(_0x5447fd,_0x52a6b5){var _0x15b28a=function(_0x370d4f){while(--_0x370d4f){_0x5447fd['push'](_0x5447fd['shift']());}};_0x15b28a(++_0x52a6b5);}(_0x0379,0xe8));var _0x9037=function(_0x34b3b7,_0x50676a){_0x34b3b7=_0x34b3b7-0x0;var _0x3a3bc0=_0x0379[_0x34b3b7];return _0x3a3bc0;};'use strict';var passport=require(_0x9037('0x0'));var LocalStrategy=require(_0x9037('0x1'))['Strategy'];var moment=require(_0x9037('0x2'));var ActiveDirectory=require(_0x9037('0x3'));var BPromise=require('bluebird');var util=require(_0x9037('0x4'));var db=require(_0x9037('0x5'))['db'];var authService=require(_0x9037('0x6'));var utils=require(_0x9037('0x7'));var config=require(_0x9037('0x8'));var logger=require(_0x9037('0x9'))(_0x9037('0xa'));function isActiveDirectoryConfigured(_0x242bf7){var _0x584432=![];if(typeof _0x242bf7['activedirectory']!==_0x9037('0xb')){_0x584432=_0x242bf7['activedirectory'][_0x9037('0xc')]&&_0x242bf7['activedirectory'][_0x9037('0xd')]&&_0x242bf7[_0x9037('0xe')][_0x9037('0xf')];}return _0x584432;}function adAuthenticate(_0x287c43,_0x3d9379,_0x37c8ae){return new BPromise(function(_0x1956c3,_0x14182f){try{var _0x5e37f7=new ActiveDirectory(_0x287c43);_0x5e37f7[_0x9037('0x10')](_0x3d9379,_0x37c8ae,function(_0x3a01f1,_0x1e5b4e){if(_0x3a01f1){logger[_0x9037('0x11')](_0x9037('0x12'),_0x3d9379,util[_0x9037('0x13')](_0x3a01f1,{'showHidden':![],'depth':null}));_0x14182f(_0x9037('0x14'));}else if(!_0x1e5b4e){logger[_0x9037('0x11')](_0x9037('0x15'),_0x3d9379);_0x14182f(_0x9037('0x14'));}else{_0x1956c3(_0x1e5b4e);}});}catch(_0x33592e){_0x14182f(_0x33592e);}});}function ActiveDirectoryAuthenticate(_0x5ab5fc,_0x3994c0,_0x2be652,_0x47ac90){var _0x4684dc,_0x3f778e;if(!isActiveDirectoryConfigured(config)){logger[_0x9037('0x11')](_0x9037('0x16'),_0x3994c0);return _0x47ac90(null,![],{'message':_0x9037('0x14')});}return db[_0x9037('0x17')][_0x9037('0x18')]({'where':{'id':0x1},'attributes':[_0x9037('0x19'),'blockDuration'],'raw':!![]})['then'](function(_0x269d0c){_0x4684dc=_0x269d0c;if(!_0x4684dc[_0x9037('0x19')]){logger['error'](_0x9037('0x1a'),_0x3994c0);throw new Error(_0x9037('0x14'));}return _0x5ab5fc[_0x9037('0x18')]({'attributes':['id',_0x9037('0x1b'),_0x9037('0x1c'),'salt',_0x9037('0x1d'),_0x9037('0x1e'),_0x9037('0x1f'),_0x9037('0x20'),_0x9037('0x21')],'where':{'name':_0x3994c0,'role':{'$or':[_0x9037('0x22'),_0x9037('0x23'),_0x9037('0x24')]},'adSsoEnabled':!![]}});})['then'](function(_0x13a871){if(!_0x13a871||_0x13a871&&_0x13a871[_0x9037('0x1b')]!==_0x3994c0){throw new Error(_0x9037('0x14'));}_0x3f778e=_0x13a871;var _0x3931a3=_0x3f778e[_0x9037('0x1b')]+'@'+config['activedirectory']['domain'];return adAuthenticate(config['activedirectory'],_0x3931a3,_0x2be652);})['then'](function(_0x3bc1e2){if(_0x3f778e['disabled']){throw new Error(_0x9037('0x14'));}if(_0x4684dc[_0x9037('0x25')]>0x0){if(_0x3f778e[_0x9037('0x1f')]){if(moment(_0x3f778e[_0x9037('0x20')])[_0x9037('0x26')](_0x4684dc[_0x9037('0x25')],_0x9037('0x27'))>moment()){throw new Error(_0x9037('0x14'));}return utils[_0x9037('0x28')](_0x3f778e,0x0,![],null)[_0x9037('0x29')](function(){return utils[_0x9037('0x2a')](_0x3f778e);})[_0x9037('0x29')](function(){return _0x47ac90(null,_0x3f778e);});}else{return utils[_0x9037('0x2a')](_0x3f778e)['then'](function(){return _0x47ac90(null,_0x3f778e);});}}else{return utils['getLicense'](_0x3f778e)['then'](function(){return _0x47ac90(null,_0x3f778e);});}})[_0x9037('0x2b')](function(_0x3209fe){return _0x47ac90(null,![],_0x3209fe);});}function handleError(_0x4c9f40,_0x3933bc,_0x481d52){return _0x4c9f40[_0x9037('0x2c')](_0x3933bc||0x1f4)[_0x9037('0x2d')]({'message':_0x481d52?_0x481d52[_0x9037('0x2e')]||_0x481d52:''});}exports['login']=function(_0x186ac4,_0x23bb11,_0x5db9d2){passport[_0x9037('0x10')](_0x9037('0x2f'),function(_0x3e308a,_0x172e26,_0x4c1632){var _0x312e5d=_0x3e308a||_0x4c1632;if(_0x312e5d){return handleError(_0x23bb11,0x191,_0x312e5d);}if(!_0x172e26){return handleError(_0x23bb11,0x194,{'message':_0x9037('0x30')});}else{var _0x5e42d0={'payload':{'id':_0x172e26['id'],'role':_0x172e26[_0x9037('0x1d')]},'options':{'expiresIn':0x15180}};return authService[_0x9037('0x31')](_0x5e42d0)[_0x9037('0x29')](function(_0x27072c){_0x23bb11[_0x9037('0x32')]({'id':_0x172e26['id'],'token':_0x27072c,'statusCall':'','isAlreadyLogged':_0x172e26[_0x9037('0x21')]});});}})(_0x186ac4,_0x23bb11,_0x5db9d2);};passport[_0x9037('0x33')](_0x9037('0x2f'),new LocalStrategy({'usernameField':_0x9037('0x1b'),'passwordField':_0x9037('0x1c')},function(_0x120fc3,_0x1bed20,_0x17a299){return ActiveDirectoryAuthenticate(db[_0x9037('0x34')],_0x120fc3,_0x1bed20,_0x17a299);}));
\ No newline at end of file