ldap.html 15 KB

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