kdc_credentials_controller_mixin.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var credentialsUtils = require('utils/credentials');
  20. App.KDCCredentialsControllerMixin = Em.Mixin.create({
  21. /**
  22. * Alias name used to store KDC credentials
  23. *
  24. * @type {string}
  25. */
  26. credentialAlias: credentialsUtils.ALIAS.KDC_CREDENTIALS,
  27. /**
  28. * Returns <code>true</code> if persisted secure storage available.
  29. *
  30. * @type {boolean}
  31. */
  32. isStorePersisted: Em.computed.alias('App.isCredentialStorePersistent'),
  33. /**
  34. * List of required UI-only properties needed for storing KDC credentials
  35. *
  36. * @type {object[]}
  37. */
  38. credentialsStoreConfigs: [
  39. {
  40. name: 'persist_credentials',
  41. displayType: 'checkbox',
  42. value: 'false',
  43. recommendedValue: 'false',
  44. supportsFinal: false,
  45. recommendedIsFinal: false,
  46. displayName: Em.I18n.t('admin.kerberos.credentials.store.label'),
  47. category: 'Kadmin',
  48. isRequired: false,
  49. isRequiredByAgent: false,
  50. hintMessage: false,
  51. rightSideLabel: true,
  52. isEditable: true,
  53. index: 3
  54. }
  55. ],
  56. /**
  57. * @param {object} resource resource info to set e.g.
  58. * <code>
  59. * {
  60. * principal: "USERNAME",
  61. * key: "SecretKey",
  62. * type: "persisted"
  63. * }
  64. * </code>
  65. *
  66. * Where:
  67. * <ul>
  68. * <li>principal: the principal (or username) part of the credential to store</li>
  69. * <li>key: the secret key part of the credential to store</li>
  70. * <li>type: declares the storage facility type: "persisted" or "temporary"</li>
  71. * </ul>
  72. * @returns {$.Deferred} promise object
  73. */
  74. createKDCCredentials: function(configs) {
  75. var resource = credentialsUtils.createCredentialResource(
  76. configs.findProperty('name', 'admin_principal').get('value'),
  77. configs.findProperty('name', 'admin_password').get('value'),
  78. this._getStorageTypeValue(configs));
  79. return credentialsUtils.createOrUpdateCredentials(App.get('clusterName'), this.get('credentialAlias'), resource);
  80. },
  81. /**
  82. * Remove KDC credentials
  83. *
  84. * @returns {$.Deferred} promise object
  85. */
  86. removeKDCCredentials: function() {
  87. return credentialsUtils.removeCredentials(App.get('clusterName'), this.get('credentialAlias'));
  88. },
  89. /**
  90. * @see createKDCCredentials
  91. * @param {object} resource
  92. * @returns {$.Deferred} promise object
  93. */
  94. updateKDCCredentials: function(resource) {
  95. return credentialsUtils.updateCredentials(App.get('clusterName'), this.get('credentialAlias'), resource);
  96. },
  97. /**
  98. * Generate additional properties regarding KDC credential storage
  99. *
  100. * @param {App.ServiceConfigProperty[]} configs list of configs
  101. */
  102. initilizeKDCStoreProperties: function(configs) {
  103. var self = this;
  104. this.get('credentialsStoreConfigs').forEach(function(item) {
  105. var configObject = App.config.createDefaultConfig(item.name, 'KERBEROS', 'krb5-conf.xml', false, false);
  106. $.extend(configObject, item);
  107. if (item.name === 'persist_credentials') {
  108. if (self.get('isStorePersisted')) {
  109. configObject.hintMessage = Em.I18n.t('admin.kerberos.credentials.store.hint.supported');
  110. } else {
  111. configObject.hintMessage = Em.I18n.t('admin.kerberos.credentials.store.hint.not.supported');
  112. configObject.isEditable = false;
  113. }
  114. }
  115. configs.pushObject(configObject);
  116. });
  117. },
  118. /**
  119. * Return storage type e.g. <b>temporary</b>, <b>persisted</b>
  120. *
  121. * @param {App.ServiceConfigProperty[]} configs configs array from step configs
  122. * @returns {string} storage type value
  123. */
  124. _getStorageTypeValue: function(configs) {
  125. if (this.get('isStorePersisted')) {
  126. return configs.findProperty('name', 'persist_credentials').get('value') === "true" ?
  127. credentialsUtils.STORE_TYPES.PERSISTENT :
  128. credentialsUtils.STORE_TYPES.TEMPORARY;
  129. }
  130. return credentialsUtils.STORE_TYPES.TEMPORARY;
  131. }
  132. });