authentication.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. App.Authentication = DS.Model.extend({
  19. method:DS.attr('boolean'), // use LDAP
  20. primaryServer:DS.attr('string'),
  21. secondaryServer:DS.attr('string'),
  22. useSsl:DS.attr('boolean'),
  23. bindMethod:DS.attr('boolean'), // use credentials
  24. bindUser:DS.attr('string'),
  25. password:DS.attr('string'),
  26. passwordRetype:DS.attr('string'),
  27. searchBaseDn:DS.attr('string'),
  28. usernameAttribute:DS.attr('string')
  29. });
  30. App.Authentication.FIXTURES = [
  31. {
  32. id:1,
  33. method:0,
  34. primary_server:"",
  35. secondary_server:"",
  36. use_ssl:false,
  37. bind_method:0,
  38. bind_user:"",
  39. password:"",
  40. password_retype:"",
  41. search_base_dn:"",
  42. username_attribute:""
  43. }
  44. ]
  45. App.AuthenticationForm = App.Form.extend({
  46. testResult:false,
  47. isObjectNew:false,
  48. fieldsOptions:[
  49. { name:"method", displayName:"", isRequired:false, displayType:"select",
  50. values:[
  51. {value:0, label:Em.I18n.t("admin.authentication.form.method.database")},
  52. {value:1, label:Em.I18n.t("admin.authentication.form.method.ldap")}
  53. ]
  54. },
  55. { name:"primaryServer", displayName:Em.I18n.t("admin.authentication.form.primaryServer"), /*validator:'ipaddress',*/
  56. isRequired:function () {
  57. return this.get('form.field.method.value');
  58. }.property('form.field.method.value')
  59. },
  60. { name:"secondaryServer", displayName:Em.I18n.t("admin.authentication.form.secondaryServer"), /*validator:'ipaddress',*/ isRequired:false},
  61. { name:"useSsl", displayName:Em.I18n.t("admin.authentication.form.useSsl"), displayType:"checkbox", isRequired:false },
  62. { name:"bindMethod", displayName:'', displayType:"select", isRequired:false,
  63. values:[
  64. {value:0, label:Em.I18n.t("admin.authentication.form.bind.anonymously")},
  65. {value:1, label:Em.I18n.t("admin.authentication.form.bind.useCrenedtials")}
  66. ]},
  67. { name:"bindUser", displayName:Em.I18n.t('admin.authentication.form.bindUserDN'), isRequired:function () {
  68. return this.get('form.field.bindMethod.value');
  69. }.property('form.field.bindMethod.value')},
  70. { name:"password", displayName:Em.I18n.t('form.password'), displayType:"password",
  71. isRequired:function () {
  72. return this.get('form.field.bindMethod.value');
  73. }.property('form.field.bindMethod.value') },
  74. { name:"passwordRetype", displayName:Em.I18n.t('form.passwordRetype'), displayType:"password",
  75. validator: "passwordRetype",
  76. isRequired:function () {
  77. return this.get('form.field.bindMethod.value');
  78. }.property('form.field.bindMethod.value')},
  79. { name:"searchBaseDn", displayName:Em.I18n.t('admin.authentication.form.searchBaseDN'),
  80. isRequired:function () {
  81. return this.get('form.field.method.value');
  82. }.property('form.field.method.value')
  83. },
  84. { name:"usernameAttribute", displayName:Em.I18n.t('admin.authentication.form.usernameAttribute'),
  85. isRequired:function () {
  86. return this.get('form.field.method.value');
  87. }.property('form.field.method.value')
  88. },
  89. { name:"userDN", displayName:Em.I18n.t('admin.authentication.form.userDN') },
  90. { name:"userPassword", displayName:Em.I18n.t('admin.authentication.form.password'), displayType:'password'}
  91. ],
  92. fields:[],
  93. testConfiguration:function () {
  94. console.warn('Configuration test is randomized');
  95. this.set('testResult', parseInt(Math.random() * 2));
  96. return true;
  97. },
  98. testConfigurationMessage:function () {
  99. return this.get('testResult') ? Em.I18n.t('admin.authentication.form.test.success') : Em.I18n.t('admin.authentication.form.test.fail');
  100. }.property('testResult'),
  101. testConfigurationClass:function () {
  102. return this.get('testResult') ? "text-success" : "text-error";
  103. }.property('testConfigurationMessage'),
  104. })
  105. ;