index.adoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. [[migration]]
  2. = Preparing for 6.0
  3. :spring-security-reference-base-url: https://docs.spring.io/spring-security/reference
  4. The Spring Security team has prepared the 5.8 release to simplify upgrading to Spring Security 6.0.
  5. Use 5.8 and the steps below to minimize changes when
  6. ifdef::spring-security-version[]
  7. {spring-security-reference-base-url}/6.0/migration/index.html[updating to 6.0].
  8. endif::[]
  9. ifndef::spring-security-version[]
  10. updating to 6.0.
  11. endif::[]
  12. == Update to Spring Security 5.8
  13. The first step is to ensure you are the latest patch release of Spring Boot 2.7.
  14. Next, you should ensure you are on the latest patch release of Spring Security 5.8.
  15. If you are using Spring Boot, you will need to override the Spring Boot version from Spring Security 5.7 to 5.8.
  16. Spring Security 5.8 is fully compatible with Spring Security 5.7 and thus Spring Boot 2.7.
  17. For directions, on how to update to Spring Security 5.8 visit the xref:getting-spring-security.adoc[] section of the reference guide.
  18. == Update Password Encoding
  19. In 6.0, password encoding minimums are updated for PBKDF2, SCrypt, and Argon2.
  20. [NOTE]
  21. ====
  22. If you are using the default password encoder, then there are no preparation steps to follow and this section can be skipped.
  23. ====
  24. === Update `Pbkdf2PasswordEncoder`
  25. If you are xref:features/authentication/password-storage.adoc#authentication-password-storage-pbkdf2[using `Pbkdf2PasswordEncoder`], the constructors are replaced with static factories that refer to the Spring Security version that the given settings apply to.
  26. ==== Replace Deprecated Constructor Usage
  27. If you use the default constructor, you should begin by changing:
  28. [tabs]
  29. ======
  30. Java::
  31. +
  32. [source,java,role="primary"]
  33. ----
  34. @Bean
  35. PasswordEncoder passwordEncoder() {
  36. return new Pbkdf2PasswordEncoder();
  37. }
  38. ----
  39. Kotlin::
  40. +
  41. [source,kotlin,role="secondary"]
  42. ----
  43. @Bean
  44. fun passwordEncoder(): PasswordEncoder {
  45. return Pbkdf2PasswordEncoder()
  46. }
  47. ----
  48. ======
  49. to:
  50. [tabs]
  51. ======
  52. Java::
  53. +
  54. [source,java,role="primary"]
  55. ----
  56. @Bean
  57. PasswordEncoder passwordEncoder() {
  58. return Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_5();
  59. }
  60. ----
  61. Kotlin::
  62. +
  63. [source,kotlin,role="secondary"]
  64. ----
  65. @Bean
  66. fun passwordEncoder(): PasswordEncoder {
  67. return Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_5()
  68. }
  69. ----
  70. ======
  71. Or, if you have custom settings, change to the constructor that specifies all settings, like so:
  72. [tabs]
  73. ======
  74. Java::
  75. +
  76. [source,java,role="primary"]
  77. ----
  78. @Bean
  79. PasswordEncoder passwordEncoder() {
  80. PasswordEncoder current = new Pbkdf2PasswordEncoder("mysecret".getBytes(UTF_8), 320000);
  81. return current;
  82. }
  83. ----
  84. Kotlin::
  85. +
  86. [source,kotlin,role="secondary"]
  87. ----
  88. @Bean
  89. fun passwordEncoder(): PasswordEncoder {
  90. val current: PasswordEncoder = Pbkdf2PasswordEncoder("mysecret".getBytes(UTF_8), 320000)
  91. return current
  92. }
  93. ----
  94. ======
  95. Change them to use the fully-specified constructor, like the following:
  96. [tabs]
  97. ======
  98. Java::
  99. +
  100. [source,java,role="primary"]
  101. ----
  102. @Bean
  103. PasswordEncoder passwordEncoder() {
  104. PasswordEncoder current = new Pbkdf2PasswordEncoder("mysecret".getBytes(UTF_8), 16, 185000, 256);
  105. return current;
  106. }
  107. ----
  108. Kotlin::
  109. +
  110. [source,kotlin,role="secondary"]
  111. ----
  112. @Bean
  113. fun passwordEncoder(): PasswordEncoder {
  114. val current: PasswordEncoder = Pbkdf2PasswordEncoder("mysecret".getBytes(UTF_8), 16, 185000, 256)
  115. return current
  116. }
  117. ----
  118. ======
  119. ==== Use `DelegatingPasswordEncoder`
  120. Once you are not using the deprecated constructor, the next step is to prepare your code to upgrade to the latest standards by using `DelegatingPasswordEncoder`.
  121. The following code configures the delegating encoder to detect passwords that are using `current` and replace them with the latest:
  122. [tabs]
  123. ======
  124. Java::
  125. +
  126. [source,java,role="primary"]
  127. ----
  128. @Bean
  129. PasswordEncoder passwordEncoder() {
  130. String prefix = "pbkdf2@5.8";
  131. PasswordEncoder current = // ... see previous step
  132. PasswordEncoder upgraded = Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8();
  133. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded));
  134. delegating.setDefaultPasswordEncoderForMatches(current);
  135. return delegating;
  136. }
  137. ----
  138. Kotlin::
  139. +
  140. [source,kotlin,role="secondary"]
  141. ----
  142. @Bean
  143. fun passwordEncoder(): PasswordEncoder {
  144. String prefix = "pbkdf2@5.8"
  145. PasswordEncoder current = // ... see previous step
  146. PasswordEncoder upgraded = Pbkdf2PasswordEncoder.defaultsForSpringSecurity_v5_8()
  147. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded))
  148. delegating.setDefaultPasswordEncoderForMatches(current)
  149. return delegating
  150. }
  151. ----
  152. ======
  153. === Update `SCryptPasswordEncoder`
  154. If you are xref:features/authentication/password-storage.adoc#authentication-password-storage-scrypt[using `SCryptPasswordEncoder`], the constructors are replaced with static factories that refer to the Spring Security version that the given settings apply to.
  155. ==== Replace Deprecated Constructor Usage
  156. If you use the default constructor, you should begin by changing:
  157. [tabs]
  158. ======
  159. Java::
  160. +
  161. [source,java,role="primary"]
  162. ----
  163. @Bean
  164. PasswordEncoder passwordEncoder() {
  165. return new SCryptPasswordEncoder();
  166. }
  167. ----
  168. Kotlin::
  169. +
  170. [source,kotlin,role="secondary"]
  171. ----
  172. @Bean
  173. fun passwordEncoder(): PasswordEncoder {
  174. return SCryptPasswordEncoder()
  175. }
  176. ----
  177. ======
  178. to:
  179. [tabs]
  180. ======
  181. Java::
  182. +
  183. [source,java,role="primary"]
  184. ----
  185. @Bean
  186. PasswordEncoder passwordEncoder() {
  187. return SCryptPasswordEncoder.defaultsForSpringSecurity_v4_1();
  188. }
  189. ----
  190. Kotlin::
  191. +
  192. [source,kotlin,role="secondary"]
  193. ----
  194. @Bean
  195. fun passwordEncoder(): PasswordEncoder {
  196. return SCryptPasswordEncoder.defaultsForSpringSecurity_v4_1()
  197. }
  198. ----
  199. ======
  200. ==== Use `DelegatingPasswordEncoder`
  201. Once you are not using the deprecated constructor, the next step is to prepare your code to upgrade to the latest standards by using `DelegatingPasswordEncoder`.
  202. The following code configures the delegating encoder to detect passwords that are using `current` and replace them with the latest:
  203. [tabs]
  204. ======
  205. Java::
  206. +
  207. [source,java,role="primary"]
  208. ----
  209. @Bean
  210. PasswordEncoder passwordEncoder() {
  211. String prefix = "scrypt@5.8";
  212. PasswordEncoder current = // ... see previous step
  213. PasswordEncoder upgraded = SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8();
  214. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded));
  215. delegating.setDefaultPasswordEncoderForMatches(current);
  216. return delegating;
  217. }
  218. ----
  219. Kotlin::
  220. +
  221. [source,kotlin,role="secondary"]
  222. ----
  223. @Bean
  224. fun passwordEncoder(): PasswordEncoder {
  225. String prefix = "scrypt@5.8"
  226. PasswordEncoder current = // ... see previous step
  227. PasswordEncoder upgraded = SCryptPasswordEncoder.defaultsForSpringSecurity_v5_8()
  228. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded))
  229. delegating.setDefaultPasswordEncoderForMatches(current)
  230. return delegating
  231. }
  232. ----
  233. ======
  234. === Update `Argon2PasswordEncoder`
  235. If you are xref:features/authentication/password-storage.adoc#authentication-password-storage-argon2[using `Argon2PasswordEncoder`], the constructors are replaced with static factories that refer to the Spring Security version that the given settings apply to.
  236. ==== Replace Deprecated Constructor Usage
  237. If you use the default constructor, you should begin by changing:
  238. [tabs]
  239. ======
  240. Java::
  241. +
  242. [source,java,role="primary"]
  243. ----
  244. @Bean
  245. PasswordEncoder passwordEncoder() {
  246. return new Argon2PasswordEncoder();
  247. }
  248. ----
  249. Kotlin::
  250. +
  251. [source,kotlin,role="secondary"]
  252. ----
  253. @Bean
  254. fun passwordEncoder(): PasswordEncoder {
  255. return Argon2PasswordEncoder()
  256. }
  257. ----
  258. ======
  259. to:
  260. [tabs]
  261. ======
  262. Java::
  263. +
  264. [source,java,role="primary"]
  265. ----
  266. @Bean
  267. PasswordEncoder passwordEncoder() {
  268. return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_2();
  269. }
  270. ----
  271. Kotlin::
  272. +
  273. [source,kotlin,role="secondary"]
  274. ----
  275. @Bean
  276. fun passwordEncoder(): PasswordEncoder {
  277. return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_2()
  278. }
  279. ----
  280. ======
  281. ==== Use `DelegatingPasswordEncoder`
  282. Once you are not using the deprecated constructor, the next step is to prepare your code to upgrade to the latest standards by using `DelegatingPasswordEncoder`.
  283. The following code configures the delegating encoder to detect passwords that are using `current` and replace them with the latest:
  284. [tabs]
  285. ======
  286. Java::
  287. +
  288. [source,java,role="primary"]
  289. ----
  290. @Bean
  291. PasswordEncoder passwordEncoder() {
  292. String prefix = "argon@5.8";
  293. PasswordEncoder current = // ... see previous step
  294. PasswordEncoder upgraded = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
  295. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded));
  296. delegating.setDefaultPasswordEncoderForMatches(current);
  297. return delegating;
  298. }
  299. ----
  300. Kotlin::
  301. +
  302. [source,kotlin,role="secondary"]
  303. ----
  304. @Bean
  305. fun passwordEncoder(): PasswordEncoder {
  306. String prefix = "argon@5.8"
  307. PasswordEncoder current = // ... see previous step
  308. PasswordEncoder upgraded = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8()
  309. DelegatingPasswordEncoder delegating = new DelegatingPasswordEncoder(prefix, Map.of(prefix, upgraded))
  310. delegating.setDefaultPasswordEncoderForMatches(current)
  311. return delegating
  312. }
  313. ----
  314. ======
  315. == Stop using `Encryptors.queryableText`
  316. `Encryptors.queryableText(CharSequence,CharSequence)` is unsafe since https://tanzu.vmware.com/security/cve-2020-5408[the same input data will produce the same output].
  317. It was deprecated and will be removed in 6.0; Spring Security no longer supports encrypting data in this way.
  318. To upgrade, you will either need to re-encrypt with a supported mechanism or store it decrypted.
  319. Consider the following pseudocode for reading each encrypted entry from a table, decrypting it, and then re-encrypting it using a supported mechanism:
  320. [tabs]
  321. ======
  322. Java::
  323. +
  324. [source,java,role="primary"]
  325. ----
  326. TextEncryptor deprecated = Encryptors.queryableText(password, salt);
  327. BytesEncryptor aes = new AesBytesEncryptor(password, salt, KeyGenerators.secureRandom(12), CipherAlgorithm.GCM);
  328. TextEncryptor supported = new HexEncodingTextEncryptor(aes);
  329. for (MyEntry entry : entries) {
  330. String value = deprecated.decrypt(entry.getEncryptedValue()); <1>
  331. entry.setEncryptedValue(supported.encrypt(value)); <2>
  332. entryService.save(entry)
  333. }
  334. ----
  335. ======
  336. <1> - The above uses the deprecated `queryableText` to convert the value to plaintext.
  337. <2> - Then, the value is re-encrypted with a supported Spring Security mechanism.
  338. Please see the reference manual for more information on what xref:features/integrations/cryptography.adoc[encryption mechanisms Spring Security supports].
  339. == Perform Application-Specific Steps
  340. Next, there are steps you need to perform based on whether it is a xref:migration/servlet/index.adoc[Servlet] or xref:migration/reactive.adoc[Reactive] application.