2
0

ldap.html 14 KB

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