ldap.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <form action="/_api/admin/security/passport-ldap" method="post" class="form-horizontal" id="ldapSetting" role="form">
  2. <fieldset>
  3. <legend>LDAP {{ t("security_setting.configuration") }}</legend>
  4. {% set nameForIsLdapEnabled = "settingForm[security:passport-ldap:isEnabled]" %}
  5. {% set isLdapEnabled = settingForm['security:passport-ldap:isEnabled'] %}
  6. <div class="form-group">
  7. <label for="{{nameForIsLdapEnabled}}" class="col-xs-3 control-label">{{ t("security_setting.ldap.use_ldap") }}</label>
  8. <div class="col-xs-6">
  9. <div class="btn-group btn-toggle" data-toggle="buttons">
  10. <label class="btn btn-default btn-rounded btn-outline {% if isLdapEnabled %}active{% endif %}" data-active-class="primary">
  11. <input name="{{nameForIsLdapEnabled}}" value="true" type="radio"
  12. {% if true === isLdapEnabled %}checked{% endif %}> ON
  13. </label>
  14. <label class="btn btn-default btn-rounded btn-outline {% if !isLdapEnabled %}active{% endif %}" data-active-class="default">
  15. <input name="{{nameForIsLdapEnabled}}" value="false" type="radio"
  16. {% if !isLdapEnabled %}checked{% endif %}> OFF
  17. </label>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="passport-ldap-hide-when-disabled" {%if !isLdapEnabled %}style="display: none;"{% endif %}>
  22. <div class="form-group">
  23. <label for="settingForm[security:passport-ldap:serverUrl]" class="col-xs-3 control-label">{{ t("security_setting.ldap.server_url") }}</label>
  24. <div class="col-xs-6">
  25. <input class="form-control" type="text"
  26. name="settingForm[security:passport-ldap:serverUrl]" value="{{ settingForm['security:passport-ldap:serverUrl'] || '' }}">
  27. <p class="help-block">
  28. <small>
  29. {{ t("security_setting.ldap.server_url_detail") }}<br>
  30. {{ t("security_setting.example") }}: <code>ldaps://ldap.company.com/ou=people,dc=company,dc=com</code>
  31. </small>
  32. </p>
  33. </div>
  34. </div>
  35. {% set nameForIsUserBind = "settingForm[security:passport-ldap:isUserBind]" %}
  36. {% set isUserBind = settingForm['security:passport-ldap:isUserBind'] %}
  37. <div class="form-group">
  38. <label for="{{nameForIsUserBind}}" class="col-xs-3 control-label">{{ t("security_setting.ldap.bind_mode") }}</label>
  39. <div class="col-xs-6">
  40. <div class="btn-group btn-toggle" data-toggle="buttons">
  41. <label class="btn btn-default btn-rounded btn-outline {% if !isUserBind %}active{% endif %}" data-active-class="primary">
  42. <input name="{{nameForIsUserBind}}" value="false" type="radio"
  43. {% if !isUserBind %}checked{% endif %}> {{ t("security_setting.ldap.bind_manager") }}
  44. </label>
  45. <label class="btn btn-default btn-rounded btn-outline {% if isUserBind %}active{% endif %}" data-active-class="primary">
  46. <input name="{{nameForIsUserBind}}" value="true" type="radio"
  47. {% if isUserBind %}checked{% endif %}> {{ t("security_setting.ldap.bind_user") }}
  48. </label>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="form-group">
  53. <label for="settingForm[security:passport-ldap:bindDN]" class="col-xs-3 control-label">{{ t("security_setting.ldap.bind_DN") }}</label>
  54. <div class="col-xs-6">
  55. <input class="form-control" type="text"
  56. name="settingForm[security:passport-ldap:bindDN]" value="{{ settingForm['security:passport-ldap:bindDN'] || '' }}">
  57. <p class="help-block passport-ldap-managerbind" {% if isUserBind %}style="display: none;"{% endif %}>
  58. <small>
  59. {{ t("security_setting.ldap.bind_DN_manager_detail") }}
  60. </small>
  61. </p>
  62. <p class="help-block passport-ldap-userbind" {% if !isUserBind %}style="display: none;"{% endif %}>
  63. <small>
  64. {{ t("security_setting.ldap.bind_DN_user_detail1") }}<br>
  65. {{ t("security_setting.ldap.bind_DN_user_detail2") }}<br>
  66. {{ t("security_setting.example") }}: <code>uid={% raw %}{{username}}{% endraw %},dc=domain,dc=com</code><br>
  67. </small>
  68. </p>
  69. </div>
  70. </div>
  71. <div class="form-group">
  72. <label for="settingForm[security:passport-ldap:bindDNPassword]" class="col-xs-3 control-label">{{ t("security_setting.ldap.bind_DN_password") }}</label>
  73. <div class="col-xs-6">
  74. <input class="form-control passport-ldap-managerbind" type="text" {% if isUserBind %}style="display: none;"{% endif %}
  75. name="settingForm[security:passport-ldap:bindDNPassword]" value="{{ settingForm['security:passport-ldap:bindDNPassword'] || '' }}">
  76. <p class="help-block passport-ldap-managerbind">
  77. <small>
  78. {{ t("security_setting.ldap.bind_DN_password_manager_detail") }}
  79. </small>
  80. </p>
  81. <p class="help-block passport-ldap-userbind" {% if !isUserBind %}style="display: none;"{% endif %}>
  82. <small>
  83. {{ t("security_setting.ldap.bind_DN_password_user_detail") }}
  84. </small>
  85. </p>
  86. </div>
  87. </div>
  88. <div class="form-group">
  89. <label for="settingForm[security:passport-ldap:searchFilter]" class="col-xs-3 control-label">{{ t("security_setting.ldap.search_filter") }}</label>
  90. <div class="col-xs-6">
  91. <input class="form-control" type="text" placeholder="{{ t("security_setting.default") }}: (uid={% raw %}{{username}}{% endraw %})"
  92. name="settingForm[security:passport-ldap:searchFilter]" value="{{ settingForm['security:passport-ldap:searchFilter'] || '' }}">
  93. <p class="help-block">
  94. <small>
  95. {{ t("security_setting.ldap.search_filter_detail1") }}<br>
  96. {{ t("security_setting.ldap.search_filter_detail2") }}<br>
  97. {{ t("security_setting.ldap.search_filter_detail3") }}<br>
  98. <br>
  99. {{ t("security_setting.ldap.search_filter_example") }}: <code>(|(uid={% raw %}{{username}}{% endraw %})(mail={% raw %}{{username}}{% endraw %}))</code>
  100. </small>
  101. </p>
  102. </div>
  103. </div>
  104. <h4>{{ t("security_setting.ldap.attribute_mapping") }} ({{ t("security_setting.optional") }})</h4>
  105. <div class="form-group">
  106. <label for="settingForm[security:passport-ldap:attrMapUsername]" class="col-xs-3 control-label">{{ t("security_setting.ldap.username") }}</label>
  107. <div class="col-xs-6">
  108. <input class="form-control" type="text" placeholder="{{ t("security_setting.default") }}: uid"
  109. name="settingForm[security:passport-ldap:attrMapUsername]" value="{{ settingForm['security:passport-ldap:attrMapUsername'] || '' }}">
  110. <p class="help-block">
  111. <small>
  112. {{ t("security_setting.ldap.username_detail") }}
  113. </small>
  114. </p>
  115. <div class="checkbox checkbox-info">
  116. <input type="checkbox" id="cbSameUsernameTreatedAsIdenticalUser" name="settingForm[security:passport-ldap:isSameUsernameTreatedAsIdenticalUser]" value="1"
  117. {% if settingForm['security:passport-ldap:isSameUsernameTreatedAsIdenticalUser'] %}checked{% endif %} />
  118. <label for="cbSameUsernameTreatedAsIdenticalUser">
  119. {{ t("security_setting.ldap.Treat username matching as identical") }}
  120. </label>
  121. </div>
  122. </div>
  123. </div>
  124. <h4>{{ t("security_setting.ldap.group_search_filter") }} ({{ t("security_setting.optional") }})</h4>
  125. <div class="form-group">
  126. <label for="settingForm[security:passport-ldap:groupSearchBase]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_search_base_DN") }}</label>
  127. <div class="col-xs-6">
  128. <input class="form-control" type="text"
  129. name="settingForm[security:passport-ldap:groupSearchBase]" value="{{ settingForm['security:passport-ldap:groupSearchBase'] || '' }}">
  130. <p class="help-block">
  131. <small>
  132. {{ t("security_setting.ldap.group_search_base_DN_detail") }}<br>
  133. {{ t("security_setting.example") }}: <code>ou=groups,dc=domain,dc=com</code><br>
  134. </small>
  135. </p>
  136. </div>
  137. </div>
  138. <div class="form-group">
  139. <label for="settingForm[security:passport-ldap:groupSearchFilter]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_search_filter") }}</label>
  140. <div class="col-xs-6">
  141. <input class="form-control" type="text"
  142. name="settingForm[security:passport-ldap:groupSearchFilter]" value="{{ settingForm['security:passport-ldap:groupSearchFilter'] || '' }}">
  143. <p class="help-block">
  144. <small>
  145. {{ t("security_setting.ldap.group_search_filter_detail1") }}<br>
  146. {{ t("security_setting.ldap.group_search_filter_detail2") }}<br>
  147. <br>
  148. {{ t("security_setting.example") }}: {{ t("security_setting.ldap.group_search_filter_detail3") }}
  149. </small>
  150. </p>
  151. </div>
  152. </div>
  153. <div class="form-group">
  154. <label for="settingForm[security:passport-ldap:groupSearchFilter]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_DN_property") }}</label>
  155. <div class="col-xs-6">
  156. <input class="form-control" type="text" placeholder="{{ t("security_setting.default") }}: uid"
  157. name="settingForm[security:passport-ldap:groupDnProperty]" value="{{ settingForm['security:passport-ldap:groupDnProperty'] || '' }}">
  158. <p class="help-block">
  159. <small>
  160. {{ t("security_setting.ldap.group_DN_property_detail") }}
  161. </small>
  162. </p>
  163. </div>
  164. </div>
  165. </div><!-- /.passport-ldap-configurations -->
  166. <div class="form-group">
  167. <div class="col-xs-offset-3 col-xs-6">
  168. <button type="submit" class="btn btn-primary">{# the first element is the default button to submit #}
  169. {{ t('Update') }}
  170. </button>
  171. <button type="button"
  172. class="btn btn-default passport-ldap-hide-when-disabled"
  173. data-target="#test-ldap-account" data-toggle="modal"
  174. {%if !isLdapEnabled %}style="display: none;"{% endif %}>
  175. {{ t("security_setting.ldap.test_config") }}
  176. </button>
  177. </div>
  178. </div>
  179. </fieldset>
  180. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  181. <script>
  182. // switch display according to on / off of radio buttons
  183. $('input[name="{{nameForIsLdapEnabled}}"]:radio').change(function() {
  184. const isEnabled = ($(this).val() === "true");
  185. if (isEnabled) {
  186. $('.passport-ldap-hide-when-disabled').show(400);
  187. }
  188. else {
  189. $('.passport-ldap-hide-when-disabled').hide(400);
  190. }
  191. });
  192. // switch display according to on / off of radio buttons
  193. $('input[name="{{nameForIsUserBind}}"]:radio').change(function() {
  194. const isUserBind = ($(this).val() === "true");
  195. if (isUserBind) {
  196. $('input.passport-ldap-managerbind').hide();
  197. $('.help-block.passport-ldap-managerbind').hide();
  198. $('.help-block.passport-ldap-userbind').show();
  199. }
  200. else {
  201. $('input.passport-ldap-managerbind').show();
  202. $('.help-block.passport-ldap-managerbind').show();
  203. $('.help-block.passport-ldap-userbind').hide();
  204. }
  205. });
  206. // store which button is clicked when submit
  207. var submittedButton;
  208. $('button[type="submit"]').click(function() {
  209. submittedButton = $(this);
  210. });
  211. $('#ldapSetting, #ldapTest').each(function() {
  212. $(this).submit(function()
  213. {
  214. function showMessage(formId, msg, status) {
  215. $('#' + formId + ' .alert').remove();
  216. if (!status) {
  217. status = 'success';
  218. }
  219. var $message = $('<p class="alert"></p>');
  220. $message.addClass('alert-' + status);
  221. $message.html(msg.replace('\n', '<br>'));
  222. $message.insertAfter('#' + formId + ' legend');
  223. if (status == 'success') {
  224. setTimeout(function()
  225. {
  226. $message.fadeOut({
  227. complete: function() {
  228. $message.remove();
  229. }
  230. });
  231. }, 5000);
  232. }
  233. }
  234. var $form = $(this);
  235. var $id = $form.attr('id');
  236. var $button = submittedButton;
  237. var $action = $button.attr('formaction') || $form.attr('action');
  238. $button.attr('disabled', 'disabled');
  239. var jqxhr = $.post($action, $form.serialize(), function(data)
  240. {
  241. if (data.status) {
  242. const message = data.message || '更新しました';
  243. showMessage($id, message);
  244. } else {
  245. showMessage($id, data.message, 'danger');
  246. }
  247. })
  248. .fail(function() {
  249. showMessage($id, 'エラーが発生しました', 'danger');
  250. })
  251. .always(function() {
  252. $button.prop('disabled', false);
  253. });
  254. return false;
  255. });
  256. });
  257. </script>
  258. </form>
  259. <div class="modal test-ldap-account" id="test-ldap-account">
  260. <div class="modal-dialog">
  261. <div class="modal-content">
  262. <div class="modal-header">
  263. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  264. <div class="modal-title">{{ t('Test LDAP Account') }}</div>
  265. </div>
  266. <div class="modal-body">
  267. {% include '../../../widget/passport/ldap-association-tester.html' %}
  268. </div><!-- /.modal-body -->
  269. </div><!-- /.modal-content -->
  270. </div><!-- /.modal-dialog -->
  271. <script>
  272. /**
  273. * associate (submit the form)
  274. */
  275. function associateLdap() {
  276. var $form = $('#formLdapAssociationContainer > form');
  277. var $action = '/me/external-accounts/associateLdap';
  278. $form.attr('action', $action);
  279. $form.submit();
  280. }
  281. </script>
  282. </div><!-- /.modal -->