saml.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <form action="/_api/admin/security/passport-saml" method="post" class="form-horizontal passportStrategy" id="samlSetting" role="form"
  2. {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  3. <legend class="alert-anchor">{{ t("security_setting.SAML.name") }} {{ t("security_setting.configuration") }}</legend>
  4. {% set nameForIsSamlEnabled = "settingForm[security:passport-saml:isEnabled]" %}
  5. {% set isSamlEnabled = getConfig('crowi', 'security:passport-saml:isEnabled') %}
  6. {% set useOnlyEnvVars = getConfig('crowi', 'security:passport-saml:useOnlyEnvVarsForSomeOptions') %}
  7. {% if useOnlyEnvVars %}
  8. <p class="alert alert-info">
  9. {{ t("security_setting.SAML.note for the only env option", "SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS") }}
  10. </p>
  11. {% endif %}
  12. <div class="form-group">
  13. <label class="col-xs-3 control-label">{{ t("security_setting.SAML.name") }}</label>
  14. <div class="col-xs-6">
  15. <div class="btn-group btn-toggle {% if useOnlyEnvVars %}btn-group-disabled{% endif %}" data-toggle="buttons">
  16. <label class="btn btn-default btn-rounded btn-outline {% if isSamlEnabled %}active{% endif %}" data-active-class="primary">
  17. <input name="{{nameForIsSamlEnabled}}"
  18. value="true"
  19. type="radio"
  20. {% if true === isSamlEnabled %}checked{% endif %}
  21. {% if useOnlyEnvVars %}readonly{% endif %}> ON
  22. </label>
  23. <label class="btn btn-default btn-rounded btn-outline {% if !isSamlEnabled %}active{% endif %}" data-active-class="default">
  24. <input name="{{nameForIsSamlEnabled}}"
  25. value="false"
  26. type="radio"
  27. {% if !isSamlEnabled %}checked{% endif %}
  28. {% if useOnlyEnvVars %}readonly{% endif %}> OFF
  29. </label>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-xs-3 control-label">{{ t("security_setting.callback_URL") }}</label>
  35. <div class="col-xs-6">
  36. <input class="form-control"
  37. type="text"
  38. value="{% if settingForm['app:siteUrl'] %}{{ settingForm['app:siteUrl'] }}{% else %}[INVALID] {% endif %}/passport/saml/callback"
  39. readonly>
  40. <p class="help-block small">{{ t("security_setting.desc_of_callback_URL", 'SAML Identity') }}</p>
  41. {% if !settingForm['app:siteUrl'] %}
  42. <div class="alert alert-danger">
  43. <i class="icon-exclamation"></i> {{ t("security_setting.alert_siteUrl_is_not_set", '<a href="/admin/app">' + t('App settings') + '<i class="icon-login"></i></a>') }}
  44. </div>
  45. {% endif %}
  46. </div>
  47. </div>
  48. <fieldset id="passport-saml-hide-when-disabled" {%if !isSamlEnabled %}style="display: none;"{% endif %}>
  49. {% set missingMandatoryConfigKeys = getSamlMissingMandatoryConfigKeys() %}
  50. {% if missingMandatoryConfigKeys.length !== 0 %}
  51. <div class="alert alert-danger">
  52. {{ t("security_setting.missing mandatory configs") }}
  53. <ul>
  54. {% for missingMandatoryConfigKey in missingMandatoryConfigKeys %}
  55. <li>{{ t("security_setting.form_item_name." + missingMandatoryConfigKey) }}</li>
  56. {% endfor %}
  57. </ul>
  58. </div>
  59. {% endif %}
  60. <h4>Basic Settings</h4>
  61. <table class="table authentication-settings-table {% if useOnlyEnvVars %}use-only-env-vars{% endif %}">
  62. <colgroup>
  63. <col class="item-name">
  64. <col class="from-db">
  65. <col class="from-env-vars">
  66. </colgroup>
  67. <thead>
  68. <tr><th></th><th>Database</th><th>Environment variables</th></tr>
  69. </thead>
  70. <tbody>
  71. <tr>
  72. <th>{{ t("security_setting.form_item_name.security:passport-saml:entryPoint") }}</th>
  73. <td>
  74. <input class="form-control"
  75. type="text"
  76. name="settingForm[security:passport-saml:entryPoint]"
  77. value="{{ getConfigFromDB('crowi', 'security:passport-saml:entryPoint') || '' }}"
  78. {% if useOnlyEnvVars %}readonly{% endif %}>
  79. </td>
  80. <td>
  81. <input class="form-control"
  82. type="text"
  83. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:entryPoint') || '' }}"
  84. readonly>
  85. <p class="help-block">
  86. <small>
  87. {{ t("security_setting.SAML.Use env var if empty", "SAML_ENTRY_POINT") }}
  88. </small>
  89. </p>
  90. </td>
  91. </tr>
  92. <tr>
  93. <th>{{ t("security_setting.form_item_name.security:passport-saml:issuer") }}</th>
  94. <td>
  95. <input class="form-control"
  96. type="text"
  97. name="settingForm[security:passport-saml:issuer]"
  98. value="{{ getConfigFromDB('crowi', 'security:passport-saml:issuer') || '' }}"
  99. {% if useOnlyEnvVars %}readonly{% endif %}>
  100. </td>
  101. <td>
  102. <input class="form-control"
  103. type="text"
  104. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:issuer') || '' }}"
  105. readonly>
  106. <p class="help-block">
  107. <small>
  108. {{ t("security_setting.SAML.Use env var if empty", "SAML_ISSUER") }}
  109. </small>
  110. </p>
  111. </td>
  112. </tr>
  113. <tr>
  114. <th>{{ t("security_setting.form_item_name.security:passport-saml:cert") }}</th>
  115. <td>
  116. <textarea class="form-control input-sm"
  117. type="text"
  118. rows="5"
  119. name="settingForm[security:passport-saml:cert]"
  120. {% if useOnlyEnvVars %}readonly{% endif %}
  121. >{{ getConfigFromDB('crowi', 'security:passport-saml:cert') || '' }}</textarea>
  122. <p class="help-block">
  123. <small>
  124. {{ t("security_setting.SAML.cert_detail") }}
  125. </small>
  126. </p>
  127. <p>
  128. <small>
  129. e.g.
  130. <pre>-----BEGIN CERTIFICATE-----
  131. MIICBzCCAXACCQD4US7+0A/b/zANBgkqhkiG9w0BAQsFADBIMQswCQYDVQQGEwJK
  132. UDEOMAwGA1UECAwFVG9reW8xFTATBgNVBAoMDFdFU0VFSywgSW5jLjESMBAGA1UE
  133. ...
  134. crmVwBzbloUO2l6k1ibwD2WVwpdxMKIF5z58HfKAvxZAzCHE7kMEZr1ge30WRXQA
  135. pWVdnzS1VCO8fKsJ7YYIr+JmHvseph3kFUOI5RqkCcMZlKUv83aUThsTHw==
  136. -----END CERTIFICATE-----</pre>
  137. </small>
  138. </p>
  139. </td>
  140. <td>
  141. <textarea class="form-control input-sm"
  142. type="text"
  143. rows="5"
  144. readonly
  145. >{{ getConfigFromEnvVars('crowi', 'security:passport-saml:cert') || '' }}</textarea>
  146. <p class="help-block">
  147. <small>
  148. {{ t("security_setting.SAML.Use env var if empty", "SAML_CERT") }}
  149. </small>
  150. </p>
  151. </td>
  152. </tr>
  153. </tbody>
  154. </table>
  155. <h4>Attribute Mapping</h4>
  156. <table class="table authentication-settings-table {% if useOnlyEnvVars %}use-only-env-vars{% endif %}">
  157. <colgroup>
  158. <col class="item-name">
  159. <col class="from-db">
  160. <col class="from-env-vars">
  161. </colgroup>
  162. <thead>
  163. <tr><th></th><th>Database</th><th>Environment variables</th></tr>
  164. </thead>
  165. <tbody>
  166. <tr>
  167. <th>{{ t("security_setting.form_item_name.security:passport-saml:attrMapId") }}</th>
  168. <td>
  169. <input class="form-control"
  170. type="text"
  171. name="settingForm[security:passport-saml:attrMapId]"
  172. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapId') || '' }}"
  173. {% if useOnlyEnvVars %}readonly{% endif %}>
  174. <p class="help-block">
  175. <small>
  176. {{ t("security_setting.SAML.id_detail") }}
  177. </small>
  178. </p>
  179. </td>
  180. <td>
  181. <input class="form-control"
  182. type="text"
  183. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapId') || '' }}"
  184. readonly>
  185. <p class="help-block">
  186. <small>
  187. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_ID") }}
  188. </small>
  189. </p>
  190. </td>
  191. </tr>
  192. <tr>
  193. <th>{{ t("security_setting.form_item_name.security:passport-saml:attrMapUsername") }}</th>
  194. <td>
  195. <input class="form-control"
  196. type="text"
  197. name="settingForm[security:passport-saml:attrMapUsername]"
  198. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapUsername') || '' }}"
  199. {% if useOnlyEnvVars %}readonly{% endif %}>
  200. <p class="help-block">
  201. <small>
  202. {{ t("security_setting.SAML.username_detail") }}
  203. </small>
  204. </p>
  205. </td>
  206. <td>
  207. <input class="form-control"
  208. type="text"
  209. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapUsername') || '' }}"
  210. readonly>
  211. <p class="help-block">
  212. <small>
  213. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_USERNAME") }}
  214. </small>
  215. </p>
  216. </td>
  217. </tr>
  218. <tr>
  219. <th>{{ t("security_setting.form_item_name.security:passport-saml:attrMapMail") }}</th>
  220. <td>
  221. <input class="form-control"
  222. type="text"
  223. name="settingForm[security:passport-saml:attrMapMail]"
  224. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapMail') || '' }}"
  225. {% if useOnlyEnvVars %}readonly{% endif %}>
  226. <p class="help-block">
  227. <small>
  228. {{ t("security_setting.SAML.mapping_detail", t("Email")) }}
  229. </small>
  230. </td>
  231. <td>
  232. <input class="form-control"
  233. type="text"
  234. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapMail') || '' }}"
  235. readonly>
  236. <p class="help-block">
  237. <small>
  238. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_MAIL") }}
  239. </small>
  240. </p>
  241. </td>
  242. </tr>
  243. <tr>
  244. <th>{{ t("security_setting.form_item_name.security:passport-saml:attrMapFirstName") }}</th>
  245. <td>
  246. <input class="form-control"
  247. type="text"
  248. name="settingForm[security:passport-saml:attrMapFirstName]"
  249. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapFirstName') || '' }}"
  250. {% if useOnlyEnvVars %}readonly{% endif %}>
  251. <p class="help-block">
  252. <small>
  253. {{ t("security_setting.SAML.mapping_detail", t("security_setting.form_item_name.security:passport-saml:attrMapFirstName")) }}
  254. </small>
  255. </p>
  256. </td>
  257. <td>
  258. <input class="form-control"
  259. type="text"
  260. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapFirstName') || '' }}"
  261. readonly>
  262. <p class="help-block">
  263. <small>
  264. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_FIRST_NAME") }}<br>
  265. {{ t("security_setting.Use default if both are empty", "firstName") }}
  266. </small>
  267. </p>
  268. </td>
  269. </tr>
  270. <tr>
  271. <th>{{ t("security_setting.form_item_name.security:passport-saml:attrMapLastName") }}</th>
  272. <td>
  273. <input class="form-control"
  274. type="text"
  275. name="settingForm[security:passport-saml:attrMapLastName]"
  276. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapLastName') || '' }}"
  277. {% if useOnlyEnvVars %}readonly{% endif %}>
  278. <p class="help-block">
  279. <small>
  280. {{ t("security_setting.SAML.mapping_detail", t("security_setting.form_item_name.security:passport-saml:attrMapLastName")) }}
  281. </small>
  282. </p>
  283. </td>
  284. <td>
  285. <input class="form-control"
  286. type="text"
  287. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapLastName') || '' }}"
  288. readonly>
  289. <p class="help-block">
  290. <small>
  291. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_LAST_NAME") }}<br>
  292. {{ t("security_setting.Use default if both are empty", "lastName") }}
  293. </small>
  294. </p>
  295. </td>
  296. </tr>
  297. </tbody>
  298. </table>
  299. <h4>Attribute Mapping Options</h4>
  300. <div class="form-group">
  301. <div class="col-xs-offset-1">
  302. <div class="checkbox checkbox-info">
  303. <input id="bindByUserName-SAML"
  304. type="checkbox"
  305. name="settingForm[security:passport-saml:isSameUsernameTreatedAsIdenticalUser]"
  306. value="1"
  307. {% if getConfig('crowi', 'security:passport-saml:isSameUsernameTreatedAsIdenticalUser') %}checked{% endif %} />
  308. <label for="bindByUserName-SAML">
  309. {{ t("security_setting.Treat username matching as identical", "username") }}
  310. </label>
  311. <p class="help-block">
  312. <small>
  313. {{ t("security_setting.Treat username matching as identical_warn", "username") }}
  314. </small>
  315. </p>
  316. </div>
  317. </div>
  318. </div>
  319. <div class="form-group">
  320. <div class="col-xs-offset-1">
  321. <div class="checkbox checkbox-info">
  322. <input id="bindByEmail-SAML"
  323. type="checkbox"
  324. name="settingForm[security:passport-saml:isSameEmailTreatedAsIdenticalUser]"
  325. value="1"
  326. {% if getConfig('crowi', 'security:passport-saml:isSameEmailTreatedAsIdenticalUser') %}checked{% endif %} />
  327. <label for="bindByEmail-SAML">
  328. {{ t("security_setting.Treat email matching as identical", "email") }}
  329. </label>
  330. <p class="help-block">
  331. <small>
  332. {{ t("security_setting.Treat email matching as identical_warn", "email") }}
  333. </small>
  334. </p>
  335. </div>
  336. </div>
  337. </div>
  338. </fieldset>
  339. <div class="form-group" id="btn-update">
  340. <div class="col-xs-offset-3 col-xs-6">
  341. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  342. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  343. </div>
  344. </div>
  345. </form>
  346. <script>
  347. $('.btn-group-disabled').on('click', '.btn', function() {
  348. return false;
  349. });
  350. $('input[name="settingForm[security:passport-saml:isEnabled]"]').change(function() {
  351. const isEnabled = ($(this).val() === "true");
  352. if (isEnabled) {
  353. $('#passport-saml-hide-when-disabled').show(400);
  354. }
  355. else {
  356. $('#passport-saml-hide-when-disabled').hide(400);
  357. }
  358. });
  359. /**
  360. * The following script sets the class name 'unused' to the cell in from-env-vars column
  361. * when the value of the corresponding cell from the database is not empty.
  362. * It is used to indicate that the system does not use a value from the environment variables by setting a css style.
  363. * This behavior is disabled when the system is in the use-only-env-vars mode.
  364. */
  365. $('.authentication-settings-table:not(.use-only-env-vars) tbody tr').each(function(_, element) {
  366. const inputElemFromDB = $('td:nth-of-type(1) input[type="text"], td:nth-of-type(1) textarea', element);
  367. const inputElemFromEnvVars = $('td:nth-of-type(2) input[type="text"], td:nth-of-type(2) textarea', element);
  368. // initialize
  369. addClassToUnusedInputElemFromEnvVars(inputElemFromDB, inputElemFromEnvVars);
  370. // set keyup event handler
  371. inputElemFromDB.keyup(function () { addClassToUnusedInputElemFromEnvVars(inputElemFromDB, inputElemFromEnvVars) });
  372. });
  373. function addClassToUnusedInputElemFromEnvVars(inputElemFromDB, inputElemFromEnvVars) {
  374. if (inputElemFromDB.val() === '') {
  375. inputElemFromEnvVars.parent().removeClass('unused');
  376. }
  377. else {
  378. inputElemFromEnvVars.parent().addClass('unused');
  379. }
  380. };
  381. </script>