migration.adoc 5.8 KB

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