Repository: ambari Updated Branches: refs/heads/branch-2.4 d4c839318 -> b270818fc
AMBARI-17425. [Hive view] hiveserver service check fails for LDAP configured hive view (pallavkul) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b270818f Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b270818f Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b270818f Branch: refs/heads/branch-2.4 Commit: b270818fcf0cab46ce0c20f7aa6febebb1e12112 Parents: d4c8393 Author: Pallav Kulshreshtha <[email protected]> Authored: Thu Jun 30 17:07:12 2016 +0530 Committer: Pallav Kulshreshtha <[email protected]> Committed: Thu Jun 30 17:08:51 2016 +0530 ---------------------------------------------------------------------- .../ui/hive-web/app/controllers/databases.js | 43 +++++-------- .../ui/hive-web/app/controllers/index.js | 63 ++++++++------------ .../ui/hive-web/app/controllers/splash.js | 39 +++++++++++- .../app/services/ldap-authentication.js | 41 +++++++++++++ .../ui/hive-web/app/utils/constants.js | 1 + 5 files changed, 119 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b270818f/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js index 2c3cd5e..fbd726c 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/databases.js @@ -23,6 +23,7 @@ import ENV from '../config/environment'; export default Ember.Controller.extend({ databaseService: Ember.inject.service(constants.namingConventions.database), notifyService: Ember.inject.service(constants.namingConventions.notify), + ldapAuthenticationService: Ember.inject.service(constants.namingConventions.ldapAuthentication), pageCount: 10, @@ -172,7 +173,7 @@ export default Ember.Controller.extend({ self._handleError(error); if(error.status == 401) { - self.send('passwordLDAPDB'); + self.send('openLdapPasswordModal'); } }).finally(function() { self.set('isDatabaseRefreshInProgress', false); @@ -241,9 +242,10 @@ export default Ember.Controller.extend({ } }, - passwordLDAPDB: function(){ + openLdapPasswordModal: function(){ + var self = this, - defer = Ember.RSVP.defer(); + defer = Ember.RSVP.defer(); this.send('openModal', 'modal-save', { heading: "modals.authenticationLDAP.heading", @@ -253,31 +255,18 @@ export default Ember.Controller.extend({ }); defer.promise.then(function (text) { - // make a post call with the given ldap password. - var password = text; - var pathName = window.location.pathname; - var pathNameArray = pathName.split("/"); - var hiveViewVersion = pathNameArray[3]; - var hiveViewName = pathNameArray[4]; - var ldapAuthURL = "/api/v1/views/HIVE/versions/"+ hiveViewVersion + "/instances/" + hiveViewName + "/jobs/auth"; - - $.ajax({ - url: ldapAuthURL, - type: 'post', - headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Requested-By': 'ambari'}, - contentType: 'application/json', - data: JSON.stringify({ "password" : password}), - success: function( data, textStatus, jQxhr ){ - console.log( "LDAP done: " + data ); - self.getDatabases(); - self.syncDatabases(); - }, - error: function( jqXhr, textStatus, errorThrown ){ - console.log( "LDAP fail: " + errorThrown ); - self.get('notifyService').error( "Wrong Credentials." ); - } - }); + var ldapAuthPromise = self.get('ldapAuthenticationService').authenticateLdapPassword(text); + + ldapAuthPromise.then(function (data) { + console.log( "LDAP done: " + data ); + self.getDatabases(); + self.syncDatabases(); + }, function (error) { + console.log( "LDAP fail: " + error ); + self.get('notifyService').error( "Wrong Credentials." ); + }) }); + }, loadSampleData: function (tableName, database) { http://git-wip-us.apache.org/repos/asf/ambari/blob/b270818f/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js index 36faa86..4d35ae7 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/index.js @@ -26,6 +26,7 @@ export default Ember.Controller.extend({ notifyService: Ember.inject.service(constants.namingConventions.notify), session: Ember.inject.service(constants.namingConventions.session), settingsService: Ember.inject.service(constants.namingConventions.settings), + ldapAuthenticationService: Ember.inject.service(constants.namingConventions.ldapAuthentication), openQueries : Ember.inject.controller(constants.namingConventions.openQueries), udfs : Ember.inject.controller(constants.namingConventions.udfs), @@ -499,46 +500,32 @@ export default Ember.Controller.extend({ self = this, defer = Ember.RSVP.defer(); - this.send('openModal', 'modal-save', { - heading: "modals.authenticationLDAP.heading", - text:"", - type: "password", - defer: defer - }); - - defer.promise.then(function (text) { - // make a post call with the given ldap password. - var password = text; - var pathName = window.location.pathname; - var pathNameArray = pathName.split("/"); - var hiveViewVersion = pathNameArray[3]; - var hiveViewName = pathNameArray[4]; - var ldapAuthURL = "/api/v1/views/HIVE/versions/"+ hiveViewVersion + "/instances/" + hiveViewName + "/jobs/auth"; - - $.ajax({ - url: ldapAuthURL, - type: 'post', - headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Requested-By': 'ambari'}, - contentType: 'application/json', - data: JSON.stringify({ "password" : password}), - success: function( data, textStatus, jQxhr ){ - - self.get('databaseService').getDatabases().then(function (databases) { - var selectedDatabase = self.get('databaseService.selectedDatabase.name') || 'default'; - self.get('databaseService').setDatabaseByName( selectedDatabase); - return self.send('executeQuery', 'job', self.get('openQueries.currentQuery.fileContent') ); - }).catch(function (error) { - self.get('notifyService').error( "Error in accessing databases." ); - }); - - }, - error: function( jqXhr, textStatus, errorThrown ){ - console.log( "LDAP fail: " + errorThrown ); - self.get('notifyService').error( "Wrong Credentials." ); - } - }); + this.send('openModal', 'modal-save', { + heading: "modals.authenticationLDAP.heading", + text:"", + type: "password", + defer: defer + }); + defer.promise.then(function (text) { + var ldapAuthPromise = self.get('ldapAuthenticationService').authenticateLdapPassword(text); + + ldapAuthPromise.then(function (data) { + console.log( "LDAP done: " + data ); + self.get('databaseService').getDatabases().then(function (databases) { + var selectedDatabase = self.get('databaseService.selectedDatabase.name') || 'default'; + self.get('databaseService').setDatabaseByName( selectedDatabase); + return self.send('executeQuery', 'job', self.get('openQueries.currentQuery.fileContent') ); + }).catch(function (error) { + self.get('notifyService').error( "Error in accessing databases." ); }); + + }, function (error) { + console.log( "LDAP fail: " + error ); + self.get('notifyService').error( "Wrong Credentials." ); + }) + }); + }, stopCurrentJob: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/b270818f/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/splash.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/splash.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/splash.js index 6f495ed..0e9ee34 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/splash.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/controllers/splash.js @@ -19,9 +19,11 @@ import Ember from 'ember'; import constants from 'hive/utils/constants'; -export default Ember.Controller.extend({ +export default Ember.Controller.extend({ databaseService: Ember.inject.service(constants.namingConventions.database), + ldapAuthenticationService: Ember.inject.service(constants.namingConventions.ldapAuthentication), + notifyService: Ember.inject.service(constants.namingConventions.notify), isExpanded: false, errors: "", stackTrace: "", @@ -32,12 +34,16 @@ export default Ember.Controller.extend({ var self = this; var processResponse = function(name, data) { - if( data != undefined ){ if(data.databases){ data = Ember.Object.create( {trace: null, message: "OK", status: "200"}); } else { - data = data; + + if(data.status === 401 && data.message === 'Hive Password Required'){ + self.send('openLdapPasswordModal'); + } else { + data = data; + } } } else { data = Ember.Object.create( {trace: null, message: "Server Error", status: "500"}); @@ -126,6 +132,33 @@ export default Ember.Controller.extend({ toggleStackTrace:function () { var value = this.get('isExpanded'); this.set('isExpanded', !value); + }, + openLdapPasswordModal: function(){ + + var self = this, + defer = Ember.RSVP.defer(); + + this.send('openModal', 'modal-save', { + heading: "modals.authenticationLDAP.heading", + text:"", + type: "password", + defer: defer + }); + + defer.promise.then(function (text) { + var ldapAuthPromise = self.get('ldapAuthenticationService').authenticateLdapPassword(text); + + ldapAuthPromise.then(function (data) { + self.send('reloadView'); + }, function (error) { + console.log( "LDAP fail: " + error ); + self.get('notifyService').error( "Wrong Credentials." ); + }) + }); + + }, + reloadView: function() { + document.location.reload(true); } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/b270818f/contrib/views/hive/src/main/resources/ui/hive-web/app/services/ldap-authentication.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/services/ldap-authentication.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/services/ldap-authentication.js new file mode 100644 index 0000000..711419c --- /dev/null +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/services/ldap-authentication.js @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; +import constants from 'hive/utils/constants'; +import ENV from '../config/environment'; + +export default Ember.Service.extend({ + + authenticateLdapPassword: function(password){ + var password = password; + var pathName = window.location.pathname; + var pathNameArray = pathName.split("/"); + var hiveViewVersion = pathNameArray[3]; + var hiveViewName = pathNameArray[4]; + var ldapAuthURL = "/api/v1/views/HIVE/versions/"+ hiveViewVersion + "/instances/" + hiveViewName + "/jobs/auth"; + + return Ember.$.ajax({ + url: ldapAuthURL, + type: 'post', + headers: {'X-Requested-With': 'XMLHttpRequest', 'X-Requested-By': 'ambari'}, + contentType: 'application/json', + data: JSON.stringify({ "password" : password}), + }) + } +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/b270818f/contrib/views/hive/src/main/resources/ui/hive-web/app/utils/constants.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/utils/constants.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/utils/constants.js index ec8352b..cf87c9d 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/utils/constants.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/utils/constants.js @@ -81,6 +81,7 @@ export default Ember.Object.create({ databaseSearch: 'databases-search-results', settings: 'settings', jobProgress: 'job-progress', + ldapAuthentication: 'ldap-authentication', queryTabs: 'query-tabs', session: 'session' },
