index.adoc 10 KB

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