1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | 1 1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 1 1 2 1 1 1 7 7 7 7 7 31 7 7 19 19 19 6 13 19 19 19 1 1 1 7 7 20 20 4 4 2 2 16 7 4 2 2 2 2 3 3 6 6 6 | 'use strict'; ;require.register("controllers/main/admin/kerberos", function (exports, require, module) { /** * 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. */ var App = require('app'); require('controllers/main/admin/kerberos/step4_controller'); App.MainAdminKerberosController = App.KerberosWizardStep4Controller.extend({ name: 'mainAdminKerberosController', /** * @type {boolean} * @deafult false */ securityEnabled: false, /** * @type {boolean} * @default false */ defaultKerberosLoaded: false, /** * @type {boolean} * @default false */ dataIsLoaded: false, /** * @type {boolean} * @default true */ isRecommendedLoaded: true, /** * @type {boolean} * @default false */ isEditMode: false, /** * @type {string} */ kdc_type: '', kdcTypesValues: { 'mit-kdc': Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'), 'active-directory': Em.I18n.t('admin.kerberos.wizard.step1.option.ad'), 'ipa': Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'), 'none': Em.I18n.t('admin.kerberos.wizard.step1.option.manual') }, getAddSecurityWizardStatus: function getAddSecurityWizardStatus() { return App.db.getSecurityWizardStatus(); }, setAddSecurityWizardStatus: function setAddSecurityWizardStatus(status) { App.db.setSecurityWizardStatus(status); }, setDisableSecurityStatus: function setDisableSecurityStatus(status) { App.db.setDisableSecurityStatus(status); }, getDisableSecurityStatus: function getDisableSecurityStatus(status) { return App.db.getDisableSecurityStatus(); }, notifySecurityOff: false, notifySecurityAdd: false, notifySecurityOffPopup: function notifySecurityOffPopup() { var self = this; this.checkServiceWarnings().then(function () { App.ModalPopup.show({ header: Em.I18n.t('popup.confirmation.commonHeader'), primary: Em.I18n.t('ok'), onPrimary: function onPrimary() { App.db.setSecurityDeployCommands(undefined); self.setDisableSecurityStatus("RUNNING"); App.router.transitionTo('disableSecurity'); this.hide(); }, bodyClass: Ember.View.extend({ templateName: require('templates/main/admin/kerberos/notify_security_off_popup') }) }); }); }, /** * Show confirmation popup for regenerate keytabs * @method regenerateKeytabs * @param callback function (optional) * @return {App.ModalPopup} */ regenerateKeytabs: function regenerateKeytabs(callback) { var self = this; return App.ModalPopup.show({ /** * True - regenerate keytabs only for missing hosts and components, false - regenerate for all hosts and components * @type {boolean} */ regenerateKeytabsOnlyForMissing: false, header: Em.I18n.t('admin.kerberos.button.regenerateKeytabs'), bodyClass: Em.View.extend({ templateName: require('templates/main/admin/kerberos/regenerate_keytabs_popup_body') }), onPrimary: function onPrimary() { this._super(); return self.restartServicesAfterRegenerate(this.get('regenerateKeytabsOnlyForMissing'), callback); } }); }, /** * Show confirmation popup for restarting all services and after confirmation regenerate keytabs * * @param regenerateKeytabsOnlyForMissing {Boolean} * @param callback (optional) * @returns {*} */ restartServicesAfterRegenerate: function restartServicesAfterRegenerate(regenerateKeytabsOnlyForMissing, callback) { var self = this; return App.ModalPopup.show({ /** * True - automatically restart services, false - user will have to restart required services manually * @type {boolean} */ restartComponents: false, header: Em.I18n.t('admin.kerberos.button.regenerateKeytabs'), bodyClass: Em.View.extend({ templateName: require('templates/main/admin/kerberos/restart_services_after_regenerate_body') }), onPrimary: function onPrimary() { this._super(); var popupContext = this; // Keytabs can either be regenerated directly or after updating kerberos descriptor in the callback function Iif (Em.typeOf(callback) === 'function') { callback().done(function () { self.regenerateKeytabsRequest(regenerateKeytabsOnlyForMissing, popupContext.get('restartComponents')); }); } else { self.regenerateKeytabsRequest(regenerateKeytabsOnlyForMissing, popupContext.get('restartComponents')); } } }); }, /** * Send request to regenerate keytabs * @param {boolean} missingOnly determines type of regeneration - missing|all * @param {boolean} withAutoRestart determines if the system should automatically restart all services or not after regeneration * @returns {$.ajax} */ regenerateKeytabsRequest: function regenerateKeytabsRequest(missingOnly, withAutoRestart) { missingOnly = missingOnly || false; return App.ajax.send({ name: "admin.kerberos_security.regenerate_keytabs", sender: this, data: { type: missingOnly ? 'missing' : 'all', withAutoRestart: withAutoRestart || false }, success: "regenerateKeytabsSuccess" }); }, /** * Success callback of <code>regenerateKeytabs</code> * show background operations popup if appropriate option is set * * @param data * @param opt * @param params * @param request */ regenerateKeytabsSuccess: function regenerateKeytabsSuccess(data, opt, params, request) { var self = this; App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) { if (initValue) { App.router.get('backgroundOperationsController').showPopup(); } self.set('needsRestartAfterRegenerate', params.withAutoRestart); }); }, /** * Do request to server for restarting all services * @method restartAllServices * @return {$.ajax} */ restartAllServices: function () { Eif (!App.router.get('backgroundOperationsController.runningOperationsCount')) { Iif (this.get('needsRestartAfterRegenerate')) { this.set('needsRestartAfterRegenerate', false); App.router.get('mainServiceController').restartAllServices(); } } }.observes('controllers.backgroundOperationsController.runningOperationsCount'), /** * performs cluster check before kerbefos security * wizard starts if <code>preKerberizeCheck<code> supports is true * otherwise runs <code>startKerberosWizard<code> * @method checkAndStartKerberosWizard */ checkAndStartKerberosWizard: function checkAndStartKerberosWizard() { if (App.get('supports.preKerberizeCheck')) { App.ajax.send({ name: "admin.kerberos_security.checks", sender: this, success: "runSecurityCheckSuccess" }); } else { this.startKerberosWizard(); } }, /** * success callback of <code>checkAndStartKerberosWizard()</code> * if there are some fails - it shows popup else open security wizard * @param data {object} * @param opt {object} * @param params {object} */ runSecurityCheckSuccess: function runSecurityCheckSuccess(data, opt, params) { //TODO correct check if (data.items.someProperty('UpgradeChecks.status', "FAIL")) { var hasFails = data.items.someProperty('UpgradeChecks.status', 'FAIL'), header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label), title = Em.I18n.t('popup.clusterCheck.Security.title'), alert = Em.I18n.t('popup.clusterCheck.Security.alert'); App.showClusterCheckPopup(data, { header: header, failTitle: title, failAlert: alert, noCallbackCondition: hasFails }); } else { this.startKerberosWizard(); } }, startKerberosWizard: function startKerberosWizard() { var self = this; this.checkServiceWarnings().then(function () { self.setAddSecurityWizardStatus('RUNNING'); App.router.get('kerberosWizardController').setDBProperty('onClosePath', 'main.admin.adminKerberos.index'); App.router.transitionTo('adminKerberos.adminAddKerberos'); }); }, /** * Loads the security status from server (security_enabled property in cluster-env configuration) */ loadSecurityStatusFromServer: function loadSecurityStatusFromServer() { if (App.get('testMode')) { this.set('securityEnabled', !App.get('testEnableSecurity')); this.set('dataIsLoaded', true); } else { //get Security Status From Server this.getSecurityType(); return this.getSecurityStatus(); } }, /** * Load security status from server. * @returns {$.Deferred} */ getSecurityStatus: function getSecurityStatus() { var self = this; var dfd = $.Deferred(); if (App.get('testMode')) { this.set('securityEnabled', !App.get('testEnableSecurity')); this.set('dataIsLoaded', true); dfd.resolve(); } else { //get Security Status From Server App.ajax.send({ name: 'admin.security_status', sender: this, success: 'getSecurityStatusSuccessCallback', error: 'errorCallback' }).always(function () { self.getSecurityType(function () { dfd.resolve(); }); }); } return dfd.promise(); }, getSecurityStatusSuccessCallback: function getSecurityStatusSuccessCallback(data) { this.set('dataIsLoaded', true); var securityType = data.Clusters.security_type; this.set('securityEnabled', securityType === 'KERBEROS'); }, errorCallback: function errorCallback(jqXHR) { this.set('dataIsLoaded', true); // Show the error popup if the API call received a response from the server. // jqXHR.status will be empty when browser cancels the request. Refer to AMBARI-5921 for more info if (!!jqXHR.status) { this.showSecurityErrorPopup(); } }, showSecurityErrorPopup: function showSecurityErrorPopup() { App.ModalPopup.show({ header: Em.I18n.t('common.error'), secondary: false, bodyClass: Ember.View.extend({ template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>') }) }); }, /** * Override <code>App.KerberosWizardStep4Controller</code> */ clearStep: function clearStep() { this.set('isEditMode', false); this._super(); }, /** * Override <code>App.KerberosWizardStep4Controller</code> * * @param {App.ServiceConfigProperty[]} properties */ setStepConfigs: function setStepConfigs(properties) { this.get('stepConfigs').clear(); this._super(properties); this.set('selectedService', this.get('stepConfigs')[0]); this.get('stepConfigs').forEach(function (serviceConfig) { serviceConfig.set('initConfigsLength', serviceConfig.get('configs.length')); }); }, /** * Override <code>App.KerberosWizardStep4Controller</code> * * @param {App.ServiceConfigProperty[]} configs * @returns {App.ServiceConfigProperty[]} */ prepareConfigProperties: function prepareConfigProperties(configs) { var self = this; var configProperties = configs.slice(0); var siteProperties = App.configsCollection.getAll(); var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName')); configProperties = configProperties.filter(function (item) { return installedServiceNames.contains(item.get('serviceName')); }); configProperties.setEach('isSecureConfig', false); configProperties.forEach(function (property, item, allConfigs) { Iif (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) { property.addObserver('value', self, 'spnegoPropertiesObserver'); } Iif (property.get('observesValueFrom')) { var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value'); property.set('value', observedValue); property.set('recommendedValue', observedValue); } if (property.get('serviceName') == 'Cluster') { property.set('category', 'Global'); } else { property.set('category', property.get('serviceName')); } // All user identity should be grouped under "Ambari Principals" category Iif (property.get('identityType') == 'user') property.set('category', 'Ambari Principals'); var siteProperty = siteProperties.findProperty('name', property.get('name')); if (siteProperty) { Iif (siteProperty.category === property.get('category')) { property.set('displayName', siteProperty.displayName); if (siteProperty.index) { property.set('index', siteProperty.index); } } Eif (siteProperty.displayType) { property.set('displayType', siteProperty.displayType); } } }); configProperties.setEach('isEditable', false); return configProperties; }, getKDCSessionState: function getKDCSessionState(callback, kdcCancelHandler) { var self = this; if (this.get('securityEnabled') || App.get('isKerberosEnabled')) { this.getSecurityType(function () { if (!self.get('isManualKerberos')) { App.ajax.send({ name: 'kerberos.session.state', sender: self, data: { callback: callback }, success: 'checkState', kdcCancelHandler: kdcCancelHandler }); } else { callback(); } }); } else { callback(); } }, /** * Determines security type. * * @param {function} [callback] callback function to execute * @returns {$.Deferred|null} */ getSecurityType: function getSecurityType(callback) { if (this.get('securityEnabled') || App.get('isKerberosEnabled')) { if (!this.get('kdc_type')) { return App.ajax.send({ name: 'admin.security.cluster_configs.kerberos', sender: this, data: { clusterName: App.get('clusterName'), additionalCallback: callback }, success: 'getSecurityTypeSuccess' }); } else { Eif (Em.typeOf(callback) === 'function') { callback(); } return $.Deferred().resolve().promise; } } else Eif (Em.typeOf(callback) === 'function') { callback(); } else { return $.Deferred().resolve().promise; } }, getSecurityTypeSuccess: function getSecurityTypeSuccess(data, opt, params) { var kdcType = data.items && data.items[0] && Em.getWithDefault(Em.getWithDefault(data.items[0], 'configurations', []).findProperty('type', 'kerberos-env') || {}, 'properties.kdc_type', 'none') || 'none'; this.set('kdc_type', kdcType); Iif (Em.typeOf(params.additionalCallback) === 'function') { params.additionalCallback(); } }, isManualKerberos: Em.computed.equal('kdc_type', 'none'), checkState: function checkState(data, opt, params) { var res = Em.get(data, 'Services.attributes.kdc_validation_result'); var message = Em.get(data, 'Services.attributes.kdc_validation_failure_details'); if (res.toUpperCase() === "OK") { params.callback(); } else { App.showInvalidKDCPopup(opt, App.format.kdcErrorMsg(message, false)); } }, /** * Determines if some config value is changed * @type {boolean} */ isPropertiesChanged: Em.computed.someBy('stepConfigs', 'isPropertiesChanged', true), /** * Determines if the save button is disabled */ isSaveButtonDisabled: Em.computed.or('isSubmitDisabled', '!isPropertiesChanged'), /** * Determines if the `Disbale Kerberos` and `Regenerate Keytabs` button are disabled */ isKerberosButtonsDisabled: Em.computed.not('isSaveButtonDisabled'), makeConfigsEditable: function makeConfigsEditable() { if (this.get('stepConfigs') && this.get('stepConfigs.length')) { this.set('isEditMode', true); this.get('stepConfigs').forEach(function (_stepConfig) { _stepConfig.get('configs').setEach('isEditable', true); _stepConfig.get('configs').forEach(function (_config) { _config.set('isEditable', _config.get('name') != 'realm'); }); }, this); } }, _updateConfigs: function _updateConfigs() { this.makeConfigsUneditable(true); }, /** * @method makeConfigsUneditable * @param configsUpdated */ makeConfigsUneditable: function makeConfigsUneditable(configsUpdated) { this.set('isEditMode', false); this.get('stepConfigs').forEach(function (_stepConfig) { _stepConfig.get('configs').forEach(function (_config) { if (configsUpdated === true) { // configsUpdated should be checked for boolean true _config.set('savedValue', _config.get('value')); _config.set('defaultValue', _config.get('value')); } else { _config.set('value', _config.get('savedValue') || _config.get('defaultValue')); } _config.set('isEditable', false); }); }, this); }, /** * Update kerberos descriptor and regenerate keytabs */ submit: function submit(context) { var callback; var self = this; var kerberosDescriptor = this.get('kerberosDescriptor'); var configs = []; this.get('stepConfigs').forEach(function (_stepConfig) { configs = configs.concat(_stepConfig.get('configs')); }); callback = function callback() { return App.ajax.send({ name: 'admin.kerberos.cluster.artifact.update', sender: self, data: { artifactName: 'kerberos_descriptor', data: { artifact_data: kerberosDescriptor } }, success: '_updateConfigs', error: 'createKerberosDescriptor' }); }; this.updateKerberosDescriptor(kerberosDescriptor, configs); if (this.get('isManualKerberos')) { callback().done(function () { self.regenerateKeytabsRequest(false, false); }); } else { this.restartServicesAfterRegenerate(false, callback); } }, createKerberosDescriptor: function createKerberosDescriptor(requestData, ajaxOptions, error, opt, params) { if (requestData && requestData.status === 404) { var artifactName = params.artifactName, data = params.data; App.ajax.send({ name: 'admin.kerberos.cluster.artifact.create', sender: self, data: { artifactName: artifactName, data: data }, success: '_updateConfigs' }); } }, /** * List of the warnings regarding specific services before enabling/disabling Kerberos. * * @type {String[]} */ serviceAlerts: function () { var messages = []; var serviceAlertMap = { YARN: Em.I18n.t('admin.kerberos.service.alert.yarn') }; var installedServices = App.Service.find().mapProperty('serviceName'); Em.keys(serviceAlertMap).forEach(function (serviceName) { if (installedServices.contains(serviceName)) { messages.push(serviceAlertMap[serviceName]); } }); return messages; }.property(), /** * Check for additional info to display before enabling/disabling kerberos and show appropriate * messages in popup if needed. * @returns {$.Deferred} - promise */ checkServiceWarnings: function checkServiceWarnings() { var dfd = $.Deferred(); this.displayServiceWarnings(this.get('serviceAlerts'), dfd); return dfd.promise(); }, /** * Show appropriate message regarding changes affected after enabling/disabling Kerberos * * @param {String[]} messages - list of the messages to display * @param {$.Deferred} dfd - used to break recursive calls and reject/resolve promise returned by <code>checkServiceWarnings</code> */ displayServiceWarnings: function displayServiceWarnings(messages, dfd) { var self = this; if (!messages.get('length')) { dfd.resolve(); } else { App.showConfirmationPopup(function () { self.displayServiceWarnings(messages.slice(1), dfd); }, messages[0], function () { dfd.reject(); }, Em.I18n.t('common.warning'), Em.I18n.t('common.proceedAnyway')); } }, showManageKDCCredentialsPopup: function showManageKDCCredentialsPopup() { return App.showManageCredentialsPopup(); }, loadStep: function loadStep() { var self = this; if (this.get('isRecommendedLoaded') === false) { return; } this.clearStep(); this.getDescriptor().then(function (properties) { self.setStepConfigs(self.createServicesStackDescriptorConfigs(properties)); }).always(function () { self.set('isRecommendedLoaded', true); }); }, showDownloadCsv: function () { var hasUpgradePrivilege = App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK'); return hasUpgradePrivilege; }.property(), downloadCSV: function downloadCSV() { App.router.get('kerberosWizardStep5Controller').getCSVData(false); } }); }); |