SecurityLdapSetting.jsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { createSubscribedElement } from '../../UnstatedUtils';
  5. import AppContainer from '../../../services/AppContainer';
  6. import AdminSecurityContainer from '../../../services/AdminSecurityContainer';
  7. class SecurityLdapSetting extends React.Component {
  8. render() {
  9. const { t, adminSecurityContainer } = this.props;
  10. const { ldapConfig } = adminSecurityContainer.state;
  11. return (
  12. <React.Fragment>
  13. <h2 className="alert-anchor border-bottom">
  14. LDAP { t('security_setting.configuration') }
  15. </h2>
  16. <div className="row mb-5">
  17. <strong className="col-xs-3 text-right">Use LDAP</strong>
  18. <div className="col-xs-6 text-left">
  19. <div className="checkbox checkbox-success">
  20. <input
  21. id="isLdapEnabled"
  22. type="checkbox"
  23. checked={ldapConfig.isEnabled}
  24. onChange={() => { adminSecurityContainer.switchIsLdapEnabled() }}
  25. />
  26. <label htmlFor="isLdapEnabled">
  27. { t('security_setting.ldap.enable_ldap') }
  28. </label>
  29. </div>
  30. </div>
  31. </div>
  32. {ldapConfig.isEnabled && (
  33. <React.Fragment>
  34. <div className="row mb-5">
  35. <label htmlFor="serverUrl" className="col-xs-3 control-label text-right">Server URL</label>
  36. <div className="col-xs-6">
  37. <input
  38. className="form-control"
  39. type="text"
  40. name="serverUrl"
  41. value={ldapConfig.serverUrl}
  42. onChange={e => adminSecurityContainer.changeServerUrl(e.target.value)}
  43. />
  44. <small>
  45. <p
  46. className="help-block"
  47. // eslint-disable-next-line react/no-danger
  48. dangerouslySetInnerHTML={{ __html: t('security_setting.ldap.server_url_detail') }}
  49. />
  50. { t('security_setting.example') }: <code>ldaps://ldap.company.com/ou=people,dc=company,dc=com</code>
  51. </small>
  52. </div>
  53. </div>
  54. <div className="row mb-5">
  55. <strong className="col-xs-3 text-right">{ t('security_setting.ldap.bind_mode') }</strong>
  56. <div className="col-xs-6 text-left">
  57. <div className="my-0 btn-group">
  58. <div className="dropdown">
  59. <button className="btn btn-default dropdown-toggle w-100" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  60. <span className="pull-left">{t(`security_setting.ldap.bind_${ldapConfig.bindMode}`)}</span>
  61. <span className="bs-caret pull-right">
  62. <span className="caret" />
  63. </span>
  64. </button>
  65. {/* TODO adjust dropdown after BS4 */}
  66. <ul className="dropdown-menu" role="menu">
  67. <li key="manager" role="presentation" type="button" onClick={() => { adminSecurityContainer.changeLdapBindMode('manager') }}>
  68. <a role="menuitem">{ t('security_setting.ldap.bind_manager') }</a>
  69. </li>
  70. <li key="user" role="presentation" type="button" onClick={() => { adminSecurityContainer.changeLdapBindMode('user') }}>
  71. <a role="menuitem">{ t('security_setting.ldap.bind_user') }</a>
  72. </li>
  73. </ul>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div className="row mb-5">
  79. <strong className="col-xs-3 text-right">Bind DN</strong>
  80. <div className="col-xs-6">
  81. <input
  82. className="form-control"
  83. type="text"
  84. name="bindDN"
  85. value={ldapConfig.bindDN}
  86. onChange={e => adminSecurityContainer.changeBindDN(e.target.value)}
  87. />
  88. {(ldapConfig.bindMode === 'manager') ? (
  89. <p className="help-block passport-ldap-managerbind">
  90. <small>
  91. { t('security_setting.ldap.bind_DN_manager_detail') }<br />
  92. { t('security_setting.example') }1: <code>uid=admin,dc=domain,dc=com</code><br />
  93. { t('security_setting.example') }2: <code>admin@domain.com</code>
  94. </small>
  95. </p>
  96. ) : (
  97. <p className="help-block passport-ldap-userbind">
  98. <small>
  99. { t('security_setting.ldap.bind_DN_user_detail1')}<br />
  100. {/* eslint-disable-next-line react/no-danger */}
  101. <span dangerouslySetInnerHTML={{ __html: t('security_setting.ldap.bind_DN_user_detail2') }} /><br />
  102. { t('security_setting.example') }1: <code>uid={'{{ username }}'},dc=domain,dc=com</code><br />
  103. { t('security_setting.example') }2: <code>{'{{ username }}'}@domain.com</code>
  104. </small>
  105. </p>
  106. )}
  107. </div>
  108. </div>
  109. <div className="row mb-5">
  110. <label htmlFor="bindDNPassword" className="col-xs-3 control-label text-right">{ t('security_setting.ldap.bind_DN_password') }</label>
  111. <div className="col-xs-6">
  112. <input
  113. className="form-control passport-ldap-managerbind"
  114. type="password"
  115. name="bindDNPassword"
  116. value={ldapConfig.bindDNPassword}
  117. onChange={e => adminSecurityContainer.changeBindDNPassword(e.target.value)}
  118. />
  119. {(ldapConfig.bindMode === 'manager') ? (
  120. <p className="help-block passport-ldap-managerbind">
  121. <small>
  122. { t('security_setting.ldap.bind_DN_password_manager_detail') }
  123. </small>
  124. </p>
  125. ) : (
  126. <p className="help-block passport-ldap-userbind">
  127. <small>
  128. { t('security_setting.ldap.bind_DN_password_user_detail') }
  129. </small>
  130. </p>
  131. )}
  132. </div>
  133. </div>
  134. <div className="row mb-5">
  135. <strong className="col-xs-3 text-right">{ t('security_setting.ldap.search_filter') }</strong>
  136. <div className="col-xs-6">
  137. <input
  138. className="form-control"
  139. type="text"
  140. name="searchFilter"
  141. value={ldapConfig.searchFilter}
  142. onChange={e => adminSecurityContainer.changeSearchFilter(e.target.value)}
  143. />
  144. <p className="help-block">
  145. <small>
  146. { t('security_setting.ldap.search_filter_detail1') }<br />
  147. {/* eslint-disable-next-line react/no-danger */}
  148. <span dangerouslySetInnerHTML={{ __html: t('security_setting.ldap.search_filter_detail2') }} /><br />
  149. {/* eslint-disable-next-line react/no-danger */}
  150. <span dangerouslySetInnerHTML={{ __html: t('security_setting.ldap.search_filter_detail3') }} />
  151. </small>
  152. </p>
  153. <p className="help-block">
  154. <small>
  155. { t('security_setting.example') }1 - { t('security_setting.ldap.search_filter_example1') }:
  156. <code>(|(uid={'{{ username }}'})(mail={'{{ username }}'}))</code><br />
  157. { t('security_setting.example') }2 - { t('security_setting.ldap.search_filter_example2') }:
  158. <code>(sAMAccountName={'{{ username }}'})</code>
  159. </small>
  160. </p>
  161. </div>
  162. </div>
  163. <h3 className="alert-anchor border-bottom">
  164. Attribute Mapping ({ t('security_setting.optional') })
  165. </h3>
  166. {/* GW-617 create form */}
  167. <h3 className="alert-anchor border-bottom">
  168. { t('security_setting.ldap.group_search_filter') } ({ t('security_setting.optional') })
  169. </h3>
  170. {/* GW-617 create form */}
  171. </React.Fragment>
  172. )}
  173. </React.Fragment>
  174. );
  175. }
  176. }
  177. SecurityLdapSetting.propTypes = {
  178. t: PropTypes.func.isRequired, // i18next
  179. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  180. adminSecurityContainer: PropTypes.instanceOf(AdminSecurityContainer).isRequired,
  181. };
  182. const SecurityLdapSettingWrapper = (props) => {
  183. return createSubscribedElement(SecurityLdapSetting, props, [AppContainer, AdminSecurityContainer]);
  184. };
  185. export default withTranslation()(SecurityLdapSettingWrapper);