ldap.html 14 KB

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