saml.html 16 KB

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