Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / authActiveDirectory / authActiveDirectory.controller.js
index 2364c5f..6f26e5a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1e5c=['use','ad-login','password','User','passport-local','Strategy','moment','activedirectory2','util','../../mysqldb','../../components/auth/service','../../config/environment','../../config/logger','api','activedirectory','undefined','url','domain','error','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','Setting','findOne','then','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','name','role','disabled','blocked','blockedAt','online','admin','user','agent','blockDuration','add','minutes','getLicense','catch','status','send','message','login','authenticate','Something\x20went\x20wrong,\x20please\x20try\x20again.','signToken'];(function(_0x3f082b,_0x30f37a){var _0x163d64=function(_0x41ba13){while(--_0x41ba13){_0x3f082b['push'](_0x3f082b['shift']());}};_0x163d64(++_0x30f37a);}(_0x1e5c,0x1da));var _0xc1e5=function(_0x9699f0,_0x354c17){_0x9699f0=_0x9699f0-0x0;var _0x17e53a=_0x1e5c[_0x9699f0];return _0x17e53a;};'use strict';var passport=require('passport');var LocalStrategy=require(_0xc1e5('0x0'))[_0xc1e5('0x1')];var moment=require(_0xc1e5('0x2'));var ActiveDirectory=require(_0xc1e5('0x3'));var BPromise=require('bluebird');var util=require(_0xc1e5('0x4'));var db=require(_0xc1e5('0x5'))['db'];var authService=require(_0xc1e5('0x6'));var utils=require('../../config/utils');var config=require(_0xc1e5('0x7'));var logger=require(_0xc1e5('0x8'))(_0xc1e5('0x9'));function isActiveDirectoryConfigured(_0x41c824){var _0x2e9dcd=![];if(typeof _0x41c824[_0xc1e5('0xa')]!==_0xc1e5('0xb')){_0x2e9dcd=_0x41c824[_0xc1e5('0xa')]['baseDN']&&_0x41c824['activedirectory'][_0xc1e5('0xc')]&&_0x41c824[_0xc1e5('0xa')][_0xc1e5('0xd')];}return _0x2e9dcd;}function adAuthenticate(_0x19c5e9,_0x4c0cb0,_0x2a56e4){return new BPromise(function(_0x482c28,_0x354c41){try{var _0x5593b9=new ActiveDirectory(_0x19c5e9);_0x5593b9['authenticate'](_0x4c0cb0,_0x2a56e4,function(_0x58c9b3,_0x56e3f9){if(_0x58c9b3){logger[_0xc1e5('0xe')]('Error\x20authenticate\x20%s:\x20%s',_0x4c0cb0,util[_0xc1e5('0xf')](_0x58c9b3,{'showHidden':![],'depth':null}));_0x354c41(_0xc1e5('0x10'));}else if(!_0x56e3f9){logger[_0xc1e5('0xe')]('Error\x20authenticate\x20%s:\x20Wrong\x20credentials',_0x4c0cb0);_0x354c41(_0xc1e5('0x10'));}else{_0x482c28(_0x56e3f9);}});}catch(_0x1e091a){_0x354c41(_0x1e091a);}});}function ActiveDirectoryAuthenticate(_0x43d9a1,_0x2d6042,_0x29f471,_0x335320){var _0xfb9dc5,_0x5a6a1f;if(!isActiveDirectoryConfigured(config)){logger[_0xc1e5('0xe')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0x2d6042);return _0x335320(null,![],{'message':'Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'});}return db[_0xc1e5('0x11')][_0xc1e5('0x12')]({'where':{'id':0x1},'attributes':['adSsoEnabled','blockDuration'],'raw':!![]})[_0xc1e5('0x13')](function(_0x6b420a){_0xfb9dc5=_0x6b420a;if(!_0xfb9dc5[_0xc1e5('0x14')]){logger['error'](_0xc1e5('0x15'),_0x2d6042);throw new Error(_0xc1e5('0x10'));}return _0x43d9a1[_0xc1e5('0x12')]({'logging':!![],'attributes':['id',_0xc1e5('0x16'),'password','salt',_0xc1e5('0x17'),_0xc1e5('0x18'),_0xc1e5('0x19'),_0xc1e5('0x1a'),_0xc1e5('0x1b')],'where':{'name':_0x2d6042,'role':{'$or':[_0xc1e5('0x1c'),_0xc1e5('0x1d'),_0xc1e5('0x1e')]},'adSsoEnabled':!![]}});})[_0xc1e5('0x13')](function(_0x2450e6){if(!_0x2450e6||_0x2450e6&&_0x2450e6['name']!==_0x2d6042){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}_0x5a6a1f=_0x2450e6;var _0x5782c6=_0x5a6a1f[_0xc1e5('0x16')]+'@'+config[_0xc1e5('0xa')]['domain'];return adAuthenticate(config[_0xc1e5('0xa')],_0x5782c6,_0x29f471);})[_0xc1e5('0x13')](function(_0x3541ce){if(_0x5a6a1f[_0xc1e5('0x18')]){throw new Error(_0xc1e5('0x10'));}if(_0xfb9dc5[_0xc1e5('0x1f')]>0x0){if(_0x5a6a1f[_0xc1e5('0x19')]){if(moment(_0x5a6a1f['blockedAt'])[_0xc1e5('0x20')](_0xfb9dc5['blockDuration'],_0xc1e5('0x21'))>moment()){throw new Error(_0xc1e5('0x10'));}return utils['clearBlockUser'](_0x5a6a1f,0x0,![],null)[_0xc1e5('0x13')](function(){return utils[_0xc1e5('0x22')](_0x5a6a1f);})[_0xc1e5('0x13')](function(){return _0x335320(null,_0x5a6a1f);});}else{return utils[_0xc1e5('0x22')](_0x5a6a1f)['then'](function(){return _0x335320(null,_0x5a6a1f);});}}else{return utils['getLicense'](_0x5a6a1f)[_0xc1e5('0x13')](function(){return _0x335320(null,_0x5a6a1f);});}})[_0xc1e5('0x23')](function(_0x225f7e){return _0x335320(null,![],_0x225f7e);});}function handleError(_0x4263cf,_0x1f955c,_0x2da45f){return _0x4263cf[_0xc1e5('0x24')](_0x1f955c||0x1f4)[_0xc1e5('0x25')]({'message':_0x2da45f?_0x2da45f[_0xc1e5('0x26')]||_0x2da45f:''});}exports[_0xc1e5('0x27')]=function(_0x692244,_0x1152c4,_0x2cacce){passport[_0xc1e5('0x28')]('ad-login',function(_0x4cf4b0,_0x230800,_0x4bf266){var _0x380e75=_0x4cf4b0||_0x4bf266;if(_0x380e75){return handleError(_0x1152c4,0x191,_0x380e75);}if(!_0x230800){return handleError(_0x1152c4,0x194,{'message':_0xc1e5('0x29')});}else{var _0x327317={'payload':{'id':_0x230800['id'],'role':_0x230800[_0xc1e5('0x17')]},'options':{'expiresIn':0x15180}};return authService[_0xc1e5('0x2a')](_0x327317)['then'](function(_0x41e48b){_0x1152c4['json']({'id':_0x230800['id'],'token':_0x41e48b,'statusCall':'','isAlreadyLogged':_0x230800[_0xc1e5('0x1b')]});});}})(_0x692244,_0x1152c4,_0x2cacce);};passport[_0xc1e5('0x2b')](_0xc1e5('0x2c'),new LocalStrategy({'usernameField':'name','passwordField':_0xc1e5('0x2d')},function(_0x20f3d6,_0x1793d3,_0x5ce911){return ActiveDirectoryAuthenticate(db[_0xc1e5('0x2e')],_0x20f3d6,_0x1793d3,_0x5ce911);}));
\ No newline at end of file
+var _0x85bf=['Error\x20authenticate\x20%s:\x20Wrong\x20credentials','findOne','blockDuration','then','adSsoEnabled','Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20enabled','password','salt','blocked','blockedAt','online','admin','user','agent','name','disabled','add','clearBlockUser','getLicense','catch','status','send','ad-login','Something\x20went\x20wrong,\x20please\x20try\x20again.','json','use','User','passport','passport-local','Strategy','util','../../mysqldb','../../components/auth/service','../../config/utils','../../config/environment','api','activedirectory','undefined','baseDN','domain','authenticate','error','Error\x20authenticate\x20%s:\x20%s','inspect','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'];(function(_0x38a47d,_0x3ef533){var _0x42c7b1=function(_0x11844d){while(--_0x11844d){_0x38a47d['push'](_0x38a47d['shift']());}};_0x42c7b1(++_0x3ef533);}(_0x85bf,0x183));var _0xf85b=function(_0x358c56,_0x42b5c1){_0x358c56=_0x358c56-0x0;var _0x1eda1f=_0x85bf[_0x358c56];return _0x1eda1f;};'use strict';var passport=require(_0xf85b('0x0'));var LocalStrategy=require(_0xf85b('0x1'))[_0xf85b('0x2')];var moment=require('moment');var ActiveDirectory=require('activedirectory2');var BPromise=require('bluebird');var util=require(_0xf85b('0x3'));var db=require(_0xf85b('0x4'))['db'];var authService=require(_0xf85b('0x5'));var utils=require(_0xf85b('0x6'));var config=require(_0xf85b('0x7'));var logger=require('../../config/logger')(_0xf85b('0x8'));function isActiveDirectoryConfigured(_0x4fe13c){var _0x3402cc=![];if(typeof _0x4fe13c[_0xf85b('0x9')]!==_0xf85b('0xa')){_0x3402cc=_0x4fe13c[_0xf85b('0x9')][_0xf85b('0xb')]&&_0x4fe13c[_0xf85b('0x9')]['url']&&_0x4fe13c[_0xf85b('0x9')][_0xf85b('0xc')];}return _0x3402cc;}function adAuthenticate(_0x383124,_0x1d87ea,_0x4023b8){return new BPromise(function(_0x86296a,_0x4161da){try{var _0x143fb2=new ActiveDirectory(_0x383124);_0x143fb2[_0xf85b('0xd')](_0x1d87ea,_0x4023b8,function(_0x14b270,_0x56fff2){if(_0x14b270){logger[_0xf85b('0xe')](_0xf85b('0xf'),_0x1d87ea,util[_0xf85b('0x10')](_0x14b270,{'showHidden':![],'depth':null}));_0x4161da(_0xf85b('0x11'));}else if(!_0x56fff2){logger[_0xf85b('0xe')](_0xf85b('0x12'),_0x1d87ea);_0x4161da(_0xf85b('0x11'));}else{_0x86296a(_0x56fff2);}});}catch(_0x4933a8){_0x4161da(_0x4933a8);}});}function ActiveDirectoryAuthenticate(_0x4a03c0,_0xb7d6fd,_0x1e0c84,_0x4c3b8a){var _0x520753,_0x39c187;if(!isActiveDirectoryConfigured(config)){logger[_0xf85b('0xe')]('Error\x20authenticate\x20%s:\x20Active\x20Directory\x20not\x20configured',_0xb7d6fd);return _0x4c3b8a(null,![],{'message':_0xf85b('0x11')});}return db['Setting'][_0xf85b('0x13')]({'where':{'id':0x1},'attributes':['adSsoEnabled',_0xf85b('0x14')],'raw':!![]})[_0xf85b('0x15')](function(_0xeca01a){_0x520753=_0xeca01a;if(!_0x520753[_0xf85b('0x16')]){logger[_0xf85b('0xe')](_0xf85b('0x17'),_0xb7d6fd);throw new Error(_0xf85b('0x11'));}return _0x4a03c0['findOne']({'logging':!![],'attributes':['id','name',_0xf85b('0x18'),_0xf85b('0x19'),'role','disabled',_0xf85b('0x1a'),_0xf85b('0x1b'),_0xf85b('0x1c')],'where':{'name':_0xb7d6fd,'role':{'$or':[_0xf85b('0x1d'),_0xf85b('0x1e'),_0xf85b('0x1f')]},'adSsoEnabled':!![]}});})['then'](function(_0x4da7a4){if(!_0x4da7a4||_0x4da7a4&&_0x4da7a4[_0xf85b('0x20')]!==_0xb7d6fd){throw new Error(_0xf85b('0x11'));}_0x39c187=_0x4da7a4;var _0x51b477=_0x39c187[_0xf85b('0x20')]+'@'+config[_0xf85b('0x9')]['domain'];return adAuthenticate(config[_0xf85b('0x9')],_0x51b477,_0x1e0c84);})[_0xf85b('0x15')](function(_0x425751){if(_0x39c187[_0xf85b('0x21')]){throw new Error('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}if(_0x520753[_0xf85b('0x14')]>0x0){if(_0x39c187[_0xf85b('0x1a')]){if(moment(_0x39c187['blockedAt'])[_0xf85b('0x22')](_0x520753['blockDuration'],'minutes')>moment()){throw new Error(_0xf85b('0x11'));}return utils[_0xf85b('0x23')](_0x39c187,0x0,![],null)['then'](function(){return utils['getLicense'](_0x39c187);})['then'](function(){return _0x4c3b8a(null,_0x39c187);});}else{return utils[_0xf85b('0x24')](_0x39c187)[_0xf85b('0x15')](function(){return _0x4c3b8a(null,_0x39c187);});}}else{return utils[_0xf85b('0x24')](_0x39c187)['then'](function(){return _0x4c3b8a(null,_0x39c187);});}})[_0xf85b('0x25')](function(_0x598dc7){return _0x4c3b8a(null,![],_0x598dc7);});}function handleError(_0x4fc610,_0x27e2e8,_0x51368d){return _0x4fc610[_0xf85b('0x26')](_0x27e2e8||0x1f4)[_0xf85b('0x27')]({'message':_0x51368d?_0x51368d['message']||_0x51368d:''});}exports['login']=function(_0xf643cc,_0x276bd2,_0x5eb5bd){passport[_0xf85b('0xd')](_0xf85b('0x28'),function(_0x3082ce,_0x3a6b25,_0x5592a3){var _0x5962d3=_0x3082ce||_0x5592a3;if(_0x5962d3){return handleError(_0x276bd2,0x191,_0x5962d3);}if(!_0x3a6b25){return handleError(_0x276bd2,0x194,{'message':_0xf85b('0x29')});}else{var _0x124de1={'payload':{'id':_0x3a6b25['id'],'role':_0x3a6b25['role']},'options':{'expiresIn':0x15180}};return authService['signToken'](_0x124de1)['then'](function(_0x16f13b){_0x276bd2[_0xf85b('0x2a')]({'id':_0x3a6b25['id'],'token':_0x16f13b,'statusCall':'','isAlreadyLogged':_0x3a6b25[_0xf85b('0x1c')]});});}})(_0xf643cc,_0x276bd2,_0x5eb5bd);};passport[_0xf85b('0x2b')](_0xf85b('0x28'),new LocalStrategy({'usernameField':_0xf85b('0x20'),'passwordField':'password'},function(_0x42ae6c,_0x356c9c,_0xbdccef){return ActiveDirectoryAuthenticate(db[_0xf85b('0x2c')],_0x42ae6c,_0x356c9c,_0xbdccef);}));
\ No newline at end of file