ldap.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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">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">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">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="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") }}
  98. </small>
  99. </p>
  100. <p>
  101. <small>
  102. {{ t("security_setting.ldap.search_filter_example") }}: <code>(|(uid={% raw %}{{username}}{% endraw %})(mail={% raw %}{{username}}{% endraw %}))</code>
  103. </small>
  104. </p>
  105. </div>
  106. </div>
  107. <h4>Attribute Mapping ({{ t("security_setting.optional") }})</h4>
  108. <div class="form-group">
  109. <label for="settingForm[security:passport-ldap:attrMapUsername]" class="col-xs-3 control-label">username</label>
  110. <div class="col-xs-6">
  111. <input class="form-control" type="text" placeholder="Default: uid"
  112. name="settingForm[security:passport-ldap:attrMapUsername]" value="{{ settingForm['security:passport-ldap:attrMapUsername'] || '' }}">
  113. <p class="help-block">
  114. <small>
  115. {{ t("security_setting.ldap.username_detail") }}
  116. </small>
  117. </p>
  118. <div class="checkbox checkbox-info">
  119. <input type="checkbox" id="cbSameUsernameTreatedAsIdenticalUser" name="settingForm[security:passport-ldap:isSameUsernameTreatedAsIdenticalUser]" value="1"
  120. {% if settingForm['security:passport-ldap:isSameUsernameTreatedAsIdenticalUser'] %}checked{% endif %} />
  121. <label for="cbSameUsernameTreatedAsIdenticalUser">
  122. {{ t("security_setting.ldap.Treat username matching as identical") }}
  123. </label>
  124. <p class="help-block">
  125. <small>
  126. {{ t("security_setting.ldap.Treat username matching as identical_warn") }}
  127. </small>
  128. </p>
  129. </div>
  130. </div>
  131. </div>
  132. <h4>{{ t("security_setting.ldap.group_search_filter") }} ({{ t("security_setting.optional") }})</h4>
  133. <div class="form-group">
  134. <label for="settingForm[security:passport-ldap:groupSearchBase]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_search_base_DN") }}</label>
  135. <div class="col-xs-6">
  136. <input class="form-control" type="text"
  137. name="settingForm[security:passport-ldap:groupSearchBase]" value="{{ settingForm['security:passport-ldap:groupSearchBase'] || '' }}">
  138. <p class="help-block">
  139. <small>
  140. {{ t("security_setting.ldap.group_search_base_DN_detail") }}<br>
  141. {{ t("security_setting.example") }}: <code>ou=groups,dc=domain,dc=com</code>
  142. </small>
  143. </p>
  144. </div>
  145. </div>
  146. <div class="form-group">
  147. <label for="settingForm[security:passport-ldap:groupSearchFilter]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_search_filter") }}</label>
  148. <div class="col-xs-6">
  149. <input class="form-control" type="text"
  150. name="settingForm[security:passport-ldap:groupSearchFilter]" value="{{ settingForm['security:passport-ldap:groupSearchFilter'] || '' }}">
  151. <p class="help-block">
  152. <small>
  153. {{ t("security_setting.ldap.group_search_filter_detail1") }}<br>
  154. {{ t("security_setting.ldap.group_search_filter_detail2") }}
  155. </small>
  156. </p>
  157. <p class="help-block">
  158. <small>
  159. {{ t("security_setting.example") }}: {{ t("security_setting.ldap.group_search_filter_detail3") }}
  160. </small>
  161. </p>
  162. </div>
  163. </div>
  164. <div class="form-group">
  165. <label for="settingForm[security:passport-ldap:groupSearchFilter]" class="col-xs-3 control-label">{{ t("security_setting.ldap.group_search_user_DN_property") }}</label>
  166. <div class="col-xs-6">
  167. <input class="form-control" type="text" placeholder="Default: uid"
  168. name="settingForm[security:passport-ldap:groupDnProperty]" value="{{ settingForm['security:passport-ldap:groupDnProperty'] || '' }}">
  169. <p class="help-block">
  170. <small>
  171. {{ t("security_setting.ldap.group_search_user_DN_property_detail") }}
  172. </small>
  173. </p>
  174. </div>
  175. </div>
  176. </div><!-- /.passport-ldap-configurations -->
  177. <div class="form-group">
  178. <div class="col-xs-offset-3 col-xs-6">
  179. <button type="submit" class="btn btn-primary">{# the first element is the default button to submit #}
  180. {{ t('Update') }}
  181. </button>
  182. <button type="button"
  183. class="btn btn-default passport-ldap-hide-when-disabled"
  184. data-target="#test-ldap-account" data-toggle="modal"
  185. {%if !isLdapEnabled %}style="display: none;"{% endif %}>
  186. {{ t("security_setting.ldap.test_config") }}
  187. </button>
  188. </div>
  189. </div>
  190. </fieldset>
  191. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  192. <script>
  193. // switch display according to on / off of radio buttons
  194. $('input[name="{{nameForIsLdapEnabled}}"]:radio').change(function() {
  195. const isEnabled = ($(this).val() === "true");
  196. if (isEnabled) {
  197. $('.passport-ldap-hide-when-disabled').show(400);
  198. }
  199. else {
  200. $('.passport-ldap-hide-when-disabled').hide(400);
  201. }
  202. });
  203. // switch display according to on / off of radio buttons
  204. $('input[name="{{nameForIsUserBind}}"]:radio').change(function() {
  205. const isUserBind = ($(this).val() === "true");
  206. if (isUserBind) {
  207. $('input.passport-ldap-managerbind').hide();
  208. $('.help-block.passport-ldap-managerbind').hide();
  209. $('.help-block.passport-ldap-userbind').show();
  210. }
  211. else {
  212. $('input.passport-ldap-managerbind').show();
  213. $('.help-block.passport-ldap-managerbind').show();
  214. $('.help-block.passport-ldap-userbind').hide();
  215. }
  216. });
  217. // store which button is clicked when submit
  218. var submittedButton;
  219. $('button[type="submit"]').click(function() {
  220. submittedButton = $(this);
  221. });
  222. $('#ldapSetting, #ldapTest').each(function() {
  223. $(this).submit(function()
  224. {
  225. function showMessage(formId, msg, status) {
  226. $('#' + formId + ' .alert').remove();
  227. if (!status) {
  228. status = 'success';
  229. }
  230. var $message = $('<p class="alert"></p>');
  231. $message.addClass('alert-' + status);
  232. $message.html(msg.replace('\n', '<br>'));
  233. $message.insertAfter('#' + formId + ' legend');
  234. if (status == 'success') {
  235. setTimeout(function()
  236. {
  237. $message.fadeOut({
  238. complete: function() {
  239. $message.remove();
  240. }
  241. });
  242. }, 5000);
  243. }
  244. }
  245. var $form = $(this);
  246. var $id = $form.attr('id');
  247. var $button = submittedButton;
  248. var $action = $button.attr('formaction') || $form.attr('action');
  249. $button.attr('disabled', 'disabled');
  250. var jqxhr = $.post($action, $form.serialize(), function(data)
  251. {
  252. if (data.status) {
  253. const message = data.message || '更新しました';
  254. showMessage($id, message);
  255. } else {
  256. showMessage($id, data.message, 'danger');
  257. }
  258. })
  259. .fail(function() {
  260. showMessage($id, 'エラーが発生しました', 'danger');
  261. })
  262. .always(function() {
  263. $button.prop('disabled', false);
  264. });
  265. return false;
  266. });
  267. });
  268. </script>
  269. </form>
  270. <div class="modal test-ldap-account" id="test-ldap-account">
  271. <div class="modal-dialog">
  272. <div class="modal-content">
  273. <div class="modal-header">
  274. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  275. <div class="modal-title">{{ t('Test LDAP Account') }}</div>
  276. </div>
  277. <div class="modal-body">
  278. {% include '../../../widget/passport/ldap-association-tester.html' %}
  279. </div><!-- /.modal-body -->
  280. </div><!-- /.modal-content -->
  281. </div><!-- /.modal-dialog -->
  282. <script>
  283. /**
  284. * associate (submit the form)
  285. */
  286. function associateLdap() {
  287. var $form = $('#formLdapAssociationContainer > form');
  288. var $action = '/me/external-accounts/associateLdap';
  289. $form.attr('action', $action);
  290. $form.submit();
  291. }
  292. </script>
  293. </div><!-- /.modal -->