migration.adoc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. === Don't Use `AuthorizationManager` in Method Security
  63. 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]
  64. 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.
  65. For example, change:
  66. ====
  67. .Java
  68. [source,java,role="primary"]
  69. ----
  70. @EnableMethodSecurity
  71. ----
  72. .Kotlin
  73. [source,kotlin,role="secondary"]
  74. ----
  75. @EnableMethodSecurity
  76. ----
  77. .Xml
  78. [source,xml,role="secondary"]
  79. ----
  80. <method-security/>
  81. ----
  82. ====
  83. to:
  84. ====
  85. .Java
  86. [source,java,role="primary"]
  87. ----
  88. @EnableGlobalMethodSecurity(prePostEnabled = true)
  89. ----
  90. .Kotlin
  91. [source,kotlin,role="secondary"]
  92. ----
  93. @EnableGlobalMethodSecurity(prePostEnabled = true)
  94. ----
  95. .Xml
  96. [source,xml,role="secondary"]
  97. ----
  98. <global-method-security pre-post-enabled="true"/>
  99. ----
  100. ====
  101. 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:
  102. ====
  103. .Java
  104. [source,java,role="primary"]
  105. ----
  106. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  107. ----
  108. .Kotlin
  109. [source,kotlin,role="secondary"]
  110. ----
  111. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  112. ----
  113. .Xml
  114. [source,xml,role="secondary"]
  115. ----
  116. <method-security secured-enabled="true" pre-post-enabled="false"/>
  117. ----
  118. ====
  119. should change to:
  120. ====
  121. .Java
  122. [source,java,role="primary"]
  123. ----
  124. @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = false)
  125. ----
  126. .Kotlin
  127. [source,kotlin,role="secondary"]
  128. ----
  129. @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = false)
  130. ----
  131. .Xml
  132. [source,xml,role="secondary"]
  133. ----
  134. <global-method-security secured-enabled="true" pre-post-enabled="false"/>
  135. ----
  136. ====
  137. == Revert Reactive
  138. === Don't Use `AuthorizationManager` in Method Security
  139. To opt-out of {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[`AuthorizationManager`] for reactive method security, add `useAuthorizationManager = false`:
  140. ====
  141. .Java
  142. [source,java,role="primary"]
  143. ----
  144. @EnableReactiveMethodSecurity
  145. ----
  146. .Kotlin
  147. [source,kotlin,role="secondary"]
  148. ----
  149. @EnableReactiveMethodSecurity
  150. ----
  151. ====
  152. changes to:
  153. ====
  154. .Java
  155. [source,java,role="primary"]
  156. ----
  157. @EnableReactiveMethodSecurity(useAuthorizationManager = false)
  158. ----
  159. .Kotlin
  160. [source,kotlin,role="secondary"]
  161. ----
  162. @EnableReactiveMethodSecurity(useAuthorizationManager = false)
  163. ----
  164. ====