saml.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 isSamlEnabled && 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>{{ 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.SAML.entry_point") }}</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.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. </tbody>
  114. </table>
  115. <h4>Attribute Mapping</h4>
  116. <table class="table authentication-settings-table {% if useOnlyEnvVars %}use-only-env-vars{% endif %}">
  117. <colgroup>
  118. <col class="item-name">
  119. <col class="from-db">
  120. <col class="from-env-vars">
  121. </colgroup>
  122. <thead>
  123. <tr><th></th><th>Database</th><th>Environment variables</th></tr>
  124. </thead>
  125. <tbody>
  126. <tr>
  127. <th>Identifier</th>
  128. <td>
  129. <input class="form-control"
  130. type="text"
  131. name="settingForm[security:passport-saml:attrMapId]"
  132. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapId') || '' }}"
  133. {% if useOnlyEnvVars %}readonly{% endif %}>
  134. <p class="help-block">
  135. <small>
  136. {{ t("security_setting.SAML.id_detail") }}
  137. </small>
  138. </p>
  139. </td>
  140. <td>
  141. <input class="form-control"
  142. type="text"
  143. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapId') || '' }}"
  144. readonly>
  145. <p class="help-block">
  146. <small>
  147. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_ID") }}
  148. </small>
  149. </p>
  150. </td>
  151. </tr>
  152. <tr>
  153. <th>Username</th>
  154. <td>
  155. <input class="form-control"
  156. type="text"
  157. name="settingForm[security:passport-saml:attrMapUsername]"
  158. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapUsername') || '' }}"
  159. {% if useOnlyEnvVars %}readonly{% endif %}>
  160. <p class="help-block">
  161. <small>
  162. {{ t("security_setting.SAML.username_detail") }}
  163. </small>
  164. </p>
  165. </td>
  166. <td>
  167. <input class="form-control"
  168. type="text"
  169. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapUsername') || '' }}"
  170. readonly>
  171. <p class="help-block">
  172. <small>
  173. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_USERNAME") }}
  174. </small>
  175. </p>
  176. </td>
  177. </tr>
  178. <tr>
  179. <th>Mail</th>
  180. <td>
  181. <input class="form-control"
  182. type="text"
  183. name="settingForm[security:passport-saml:attrMapMail]"
  184. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapMail') || '' }}"
  185. {% if useOnlyEnvVars %}readonly{% endif %}>
  186. <p class="help-block">
  187. <small>
  188. {{ t("security_setting.SAML.mapping_detail", t("Email")) }}
  189. </small>
  190. </td>
  191. <td>
  192. <input class="form-control"
  193. type="text"
  194. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapMail') || '' }}"
  195. readonly>
  196. <p class="help-block">
  197. <small>
  198. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_MAIL") }}
  199. </small>
  200. </p>
  201. </td>
  202. </tr>
  203. <tr>
  204. <th>{{ t("security_setting.SAML.First Name") }}</th>
  205. <td>
  206. <input class="form-control"
  207. type="text"
  208. name="settingForm[security:passport-saml:attrMapFirstName]"
  209. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapFirstName') || '' }}"
  210. {% if useOnlyEnvVars %}readonly{% endif %}>
  211. <p class="help-block">
  212. <small>
  213. {{ t("security_setting.SAML.mapping_detail", t("security_setting.SAML.First Name")) }}
  214. </small>
  215. </p>
  216. </td>
  217. <td>
  218. <input class="form-control"
  219. type="text"
  220. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapFirstName') || '' }}"
  221. readonly>
  222. <p class="help-block">
  223. <small>
  224. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_FIRST_NAME") }}<br>
  225. {{ t("security_setting.Use default if both are empty", "firstName") }}
  226. </small>
  227. </p>
  228. </td>
  229. </tr>
  230. <tr>
  231. <th>{{ t("security_setting.SAML.Last Name") }}</th>
  232. <td>
  233. <input class="form-control"
  234. type="text"
  235. name="settingForm[security:passport-saml:attrMapLastName]"
  236. value="{{ getConfigFromDB('crowi', 'security:passport-saml:attrMapLastName') || '' }}"
  237. {% if useOnlyEnvVars %}readonly{% endif %}>
  238. <p class="help-block">
  239. <small>
  240. {{ t("security_setting.SAML.mapping_detail", t("security_setting.SAML.Last Name")) }}
  241. </small>
  242. </p>
  243. </td>
  244. <td>
  245. <input class="form-control"
  246. type="text"
  247. value="{{ getConfigFromEnvVars('crowi', 'security:passport-saml:attrMapLastName') || '' }}"
  248. readonly>
  249. <p class="help-block">
  250. <small>
  251. {{ t("security_setting.SAML.Use env var if empty", "SAML_ATTR_MAPPING_LAST_NAME") }}<br>
  252. {{ t("security_setting.Use default if both are empty", "lastName") }}
  253. </small>
  254. </p>
  255. </td>
  256. </tr>
  257. </tbody>
  258. </table>
  259. <h4>Attribute Mapping Options</h4>
  260. <div class="form-group">
  261. <div class="col-xs-offset-1">
  262. <div class="checkbox checkbox-info">
  263. <input id="bindByUserName-SAML"
  264. type="checkbox"
  265. name="settingForm[security:passport-saml:isSameUsernameTreatedAsIdenticalUser]"
  266. value="1"
  267. {% if settingForm['security:passport-saml:isSameUsernameTreatedAsIdenticalUser'] %}checked{% endif %} />
  268. <label for="bindByUserName-SAML">
  269. {{ t("security_setting.Treat username matching as identical", "username") }}
  270. </label>
  271. <p class="help-block">
  272. <small>
  273. {{ t("security_setting.Treat username matching as identical_warn", "username") }}
  274. </small>
  275. </p>
  276. </div>
  277. </div>
  278. </div>
  279. <div class="form-group">
  280. <div class="col-xs-offset-1">
  281. <div class="checkbox checkbox-info">
  282. <input id="bindByEmail-SAML"
  283. type="checkbox"
  284. name="settingForm[security:passport-saml:isSameEmailTreatedAsIdenticalUser]"
  285. value="1"
  286. {% if settingForm['security:passport-saml:isSameEmailTreatedAsIdenticalUser'] %}checked{% endif %} />
  287. <label for="bindByEmail-SAML">
  288. {{ t("security_setting.Treat email matching as identical", "email") }}
  289. </label>
  290. <p class="help-block">
  291. <small>
  292. {{ t("security_setting.Treat email matching as identical_warn", "email") }}
  293. </small>
  294. </p>
  295. </div>
  296. </div>
  297. </div>
  298. <h4>Options</h4>
  299. <table class="table authentication-settings-table {% if useOnlyEnvVars %}use-only-env-vars{% endif %}">
  300. <colgroup>
  301. <col class="item-name">
  302. <col class="from-db">
  303. <col class="from-env-vars">
  304. </colgroup>
  305. <thead>
  306. <tr><th></th><th>Database</th><th>Environment variables</th></tr>
  307. </thead>
  308. <tbody>
  309. <tr>
  310. <th>Certificate</th>
  311. <td>
  312. <textarea class="form-control input-sm"
  313. type="text"
  314. rows="5"
  315. name="settingForm[security:passport-saml:cert]"
  316. {% if useOnlyEnvVars %}readonly{% endif %}
  317. >{{ getConfigFromDB('crowi', 'security:passport-saml:cert') || '' }}</textarea>
  318. <p class="help-block">
  319. <small>
  320. {{ t("security_setting.SAML.cert_detail1") }}
  321. </small>
  322. </p>
  323. <p>
  324. <small>
  325. e.g.
  326. <pre>-----BEGIN CERTIFICATE-----
  327. MIICBzCCAXACCQD4US7+0A/b/zANBgkqhkiG9w0BAQsFADBIMQswCQYDVQQGEwJK
  328. UDEOMAwGA1UECAwFVG9reW8xFTATBgNVBAoMDFdFU0VFSywgSW5jLjESMBAGA1UE
  329. ...
  330. crmVwBzbloUO2l6k1ibwD2WVwpdxMKIF5z58HfKAvxZAzCHE7kMEZr1ge30WRXQA
  331. pWVdnzS1VCO8fKsJ7YYIr+JmHvseph3kFUOI5RqkCcMZlKUv83aUThsTHw==
  332. -----END CERTIFICATE-----</pre>
  333. </small>
  334. </p>
  335. </td>
  336. <td>
  337. <textarea class="form-control input-sm"
  338. type="text"
  339. rows="5"
  340. readonly
  341. >{{ getConfigFromEnvVars('crowi', 'security:passport-saml:cert') || '' }}</textarea>
  342. <p class="help-block">
  343. <small>
  344. {{ t("security_setting.SAML.Use env var if empty", "SAML_CERT") }}<br>
  345. {{ t("security_setting.SAML.cert_detail2") }}
  346. </small>
  347. </p>
  348. </td>
  349. </tr>
  350. </tbody>
  351. </table>
  352. </fieldset>
  353. <div class="form-group" id="btn-update">
  354. <div class="col-xs-offset-3 col-xs-6">
  355. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  356. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  357. </div>
  358. </div>
  359. </form>
  360. <script>
  361. $('.btn-group-disabled').on('click', '.btn', function() {
  362. return false;
  363. });
  364. $('input[name="settingForm[security:passport-saml:isEnabled]"]').change(function() {
  365. const isEnabled = ($(this).val() === "true");
  366. if (isEnabled) {
  367. $('#passport-saml-hide-when-disabled').show(400);
  368. }
  369. else {
  370. $('#passport-saml-hide-when-disabled').hide(400);
  371. }
  372. });
  373. $('.authentication-settings-table:not(.use-only-env-vars) tbody tr').each(function(_, element) {
  374. const inputElemFromDB = $('td:nth-of-type(1) input', element);
  375. const inputElemFromEnvVars = $('td:nth-of-type(2) input', element);
  376. const addClassToUsedInputElem = function() {
  377. console.log(inputElemFromDB.val());
  378. if (inputElemFromDB.val() === '') {
  379. inputElemFromEnvVars.parent().removeClass('unused');
  380. }
  381. else {
  382. inputElemFromEnvVars.parent().addClass('unused');
  383. }
  384. };
  385. addClassToUsedInputElem();
  386. inputElemFromDB.keyup(addClassToUsedInputElem);
  387. });
  388. </script>