migration.adoc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. [[migration]]
  2. = Migrating to 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
  5. ifdef::spring-security-version[]
  6. xref:5.8.0@migration.adoc[its preparation steps]
  7. endif::[]
  8. ifndef::spring-security-version[]
  9. its preparation steps
  10. endif::[]
  11. to simplify updating to 6.0
  12. After updating to 5.8, follow this guide to perform any needed migration steps.
  13. Also, this guide includes ways to <<revert,revert to 5.x>> behaviors and its defaults, should you run into trouble.
  14. == Servlet
  15. [[requestcache-query-optimization]]
  16. === Optimize Querying of `RequestCache`
  17. In Spring Security 5, the default behavior is to query the xref:servlet/architecture.adoc#savedrequests[saved request] on every request.
  18. This means that in a typical setup, that in order to use the xref:servlet/architecture.adoc#requestcache[`RequestCache`] the `HttpSession` is queried on every request.
  19. In Spring Security 6, the default is that `RequestCache` will only be queried for a cached request if the HTTP parameter `continue` is defined.
  20. This allows Spring Security to avoid unnecessarily reading the `HttpSession` with the `RequestCache`.
  21. In Spring Security 5 the default is to use `HttpSessionRequestCache` which will be queried for a cached request on every request.
  22. If you are not overriding the defaults (i.e. using `NullRequestCache`), then the following configuration can be used to explicitly opt into the Spring Security 6 behavior in Spring Security 5.8:
  23. include::partial$servlet/architecture/request-cache-continue.adoc[]
  24. === Use `AuthorizationManager` for Method Security
  25. There are no further migration steps for this feature.
  26. However, if you run into trouble with this enhancement, you can instead <<servlet-replace-methodsecurity-with-globalmethodsecurity,revert the behavior>>.
  27. == Reactive
  28. === Use `AuthorizationManager` for Method Security
  29. If you run into trouble with this enhancement, you can instead <<reactive-change-to-useauthorizationmanager-false,revert the behavior>>.
  30. In 6.0, `@EnableReactiveMethodSecurity` defaults `useAuthorizationManager` to `true`.
  31. So, to complete migration, {security-api-url}org/springframework/security/config/annotation/method/configuration/EnableReactiveMethodSecurity.html[`@EnableReactiveMethodSecurity`] remove the `useAuthorizationManager` attribute:
  32. ====
  33. .Java
  34. [source,java,role="primary"]
  35. ----
  36. @EnableReactiveMethodSecurity(useAuthorizationManager = true)
  37. ----
  38. .Kotlin
  39. [source,kotlin,role="secondary"]
  40. ----
  41. @EnableReactiveMethodSecurity(useAuthorizationManager = true)
  42. ----
  43. ====
  44. changes to:
  45. ====
  46. .Java
  47. [source,java,role="primary"]
  48. ----
  49. @EnableReactiveMethodSecurity
  50. ----
  51. .Kotlin
  52. [source,kotlin,role="secondary"]
  53. ----
  54. @EnableReactiveMethodSecurity
  55. ----
  56. ====
  57. '''
  58. [[revert]]
  59. If you are running into trouble with any of the 6.0 changes, please first try to apply the following changes to get you up and running.
  60. It's more important to stay on 6.0 and get the security improvements.
  61. == Revert Servlet
  62. [[servlet-replace-methodsecurity-with-globalmethodsecurity]]
  63. === Don't Use `AuthorizationManager` in Method Security
  64. To opt out of `AuthorizationManager` for Method Security, replace xref:servlet/authorization/method-security.adoc#jc-enable-method-security[method security] with xref:servlet/authorization/method-security.adoc#jc-enable-global-method-security[global method security]
  65. For applications using xref:servlet/authorization/method-security.adoc#jc-enable-method-security[pre-post annotations], make sure to turn it on to reactivate the behavior.
  66. For example, change:
  67. ====
  68. .Java
  69. [source,java,role="primary"]
  70. ----
  71. @EnableMethodSecurity
  72. ----
  73. .Kotlin
  74. [source,kotlin,role="secondary"]
  75. ----
  76. @EnableMethodSecurity
  77. ----
  78. .Xml
  79. [source,xml,role="secondary"]
  80. ----
  81. <method-security/>
  82. ----
  83. ====
  84. to:
  85. ====
  86. .Java
  87. [source,java,role="primary"]
  88. ----
  89. @EnableGlobalMethodSecurity(prePostEnabled = true)
  90. ----
  91. .Kotlin
  92. [source,kotlin,role="secondary"]
  93. ----
  94. @EnableGlobalMethodSecurity(prePostEnabled = true)
  95. ----
  96. .Xml
  97. [source,xml,role="secondary"]
  98. ----
  99. <global-method-security pre-post-enabled="true"/>
  100. ----
  101. ====
  102. Other usages can simply change {security-api-url}org/springframework/security/config/annotation/method/configuration/EnableMethodSecurity.html[`@EnableMethodSecurity`] and xref:servlet/appendix/namespace/method-security.adoc#nsa-method-security[`<method-security>`] to {security-api-url}org/springframework/security/config/annotation/method/configuration/EnableGlobalMethodSecurity.html[`@EnableGlobalMethodSecurity`] and xref:servlet/appendix/namespace/method-security.adoc#nsa-global-method-security[`<global-method-security>`], like so:
  103. ====
  104. .Java
  105. [source,java,role="primary"]
  106. ----
  107. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  108. ----
  109. .Kotlin
  110. [source,kotlin,role="secondary"]
  111. ----
  112. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  113. ----
  114. .Xml
  115. [source,xml,role="secondary"]
  116. ----
  117. <method-security secured-enabled="true" pre-post-enabled="false"/>
  118. ----
  119. ====
  120. should change to:
  121. ====
  122. .Java
  123. [source,java,role="primary"]
  124. ----
  125. @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = false)
  126. ----
  127. .Kotlin
  128. [source,kotlin,role="secondary"]
  129. ----
  130. @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = false)
  131. ----
  132. .Xml
  133. [source,xml,role="secondary"]
  134. ----
  135. <global-method-security secured-enabled="true" pre-post-enabled="false"/>
  136. ----
  137. ====
  138. == Revert Reactive
  139. [[reactive-change-to-useauthorizationmanager-false]]
  140. === Don't Use `AuthorizationManager` in Method Security
  141. To opt-out of {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] for reactive method security, add `useAuthorizationManager = false`:
  142. ====
  143. .Java
  144. [source,java,role="primary"]
  145. ----
  146. @EnableReactiveMethodSecurity
  147. ----
  148. .Kotlin
  149. [source,kotlin,role="secondary"]
  150. ----
  151. @EnableReactiveMethodSecurity
  152. ----
  153. ====
  154. changes to:
  155. ====
  156. .Java
  157. [source,java,role="primary"]
  158. ----
  159. @EnableReactiveMethodSecurity(useAuthorizationManager = false)
  160. ----
  161. .Kotlin
  162. [source,kotlin,role="secondary"]
  163. ----
  164. @EnableReactiveMethodSecurity(useAuthorizationManager = false)
  165. ----
  166. ====