migration.adoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 the steps below to minimize changes when updating to 6.0.
  5. == Servlet
  6. === Use `AuthorizationManager` for Method Security
  7. xref:servlet/authorization/method-security.adoc[Method Security] has been xref:servlet/authorization/method-security.adoc#jc-enable-method-security[simplified] through {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[the `AuthorizationManager` API] and direct use of Spring AOP.
  8. '''
  9. [[servlet-replace-globalmethodsecurity-with-methodsecurity]]
  10. [%interactive]
  11. * [ ] Replace xref:servlet/authorization/method-security.adoc#jc-enable-global-method-security[global method security] with xref:servlet/authorization/method-security.adoc#jc-enable-method-security[method security]
  12. {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>`] are deprecated in favor of {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>`], respectively.
  13. The new annotation and XML element activate Spring's xref:servlet/authorization/method-security.adoc#jc-enable-method-security[pre-post annotations] by default and use `AuthorizationManager` internally.
  14. This means that the following two listings are functionally equivalent:
  15. ====
  16. .Java
  17. [source,java,role="primary"]
  18. ----
  19. @EnableGlobalMethodSecurity(prePostEnabled = true)
  20. ----
  21. .Kotlin
  22. [source,kotlin,role="secondary"]
  23. ----
  24. @EnableGlobalMethodSecurity(prePostEnabled = true)
  25. ----
  26. .Xml
  27. [source,xml,role="secondary"]
  28. ----
  29. <global-method-security pre-post-enabled="true"/>
  30. ----
  31. ====
  32. and:
  33. ====
  34. .Java
  35. [source,java,role="primary"]
  36. ----
  37. @EnableMethodSecurity
  38. ----
  39. .Kotlin
  40. [source,kotlin,role="secondary"]
  41. ----
  42. @EnableMethodSecurity
  43. ----
  44. .Xml
  45. [source,xml,role="secondary"]
  46. ----
  47. <method-security/>
  48. ----
  49. ====
  50. For applications not using the pre-post annotations, make sure to turn it off to avoid activating unwanted behavior.
  51. For example, a listing like:
  52. ====
  53. .Java
  54. [source,java,role="primary"]
  55. ----
  56. @EnableGlobalMethodSecurity(securedEnabled = true)
  57. ----
  58. .Kotlin
  59. [source,kotlin,role="secondary"]
  60. ----
  61. @EnableGlobalMethodSecurity(securedEnabled = true)
  62. ----
  63. .Xml
  64. [source,xml,role="secondary"]
  65. ----
  66. <global-method-security secured-enabled="true"/>
  67. ----
  68. ====
  69. should change to:
  70. ====
  71. .Java
  72. [source,java,role="primary"]
  73. ----
  74. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  75. ----
  76. .Kotlin
  77. [source,kotlin,role="secondary"]
  78. ----
  79. @EnableMethodSecurity(securedEnabled = true, prePostEnabled = false)
  80. ----
  81. .Xml
  82. [source,xml,role="secondary"]
  83. ----
  84. <method-security secured-enabled="true" pre-post-enabled="false"/>
  85. ----
  86. ====
  87. '''
  88. [[servlet-replace-permissionevaluator-bean-with-methodsecurityexpression-handler]]
  89. [%interactive]
  90. * [ ] Publish a `MethodSecurityExpressionHandler` instead of a `PermissionEvaluator`
  91. `@EnableMethodSecurity` does not pick up a `PermissionEvaluator`.
  92. This helps keep its API simple.
  93. If you have a custom {security-api-url}org/springframework/security/access/PermissionEvaluator.html[`PermissionEvaluator`] `@Bean`, please change it from:
  94. ====
  95. .Java
  96. [source,java,role="primary"]
  97. ----
  98. @Bean
  99. static PermissionEvaluator permissionEvaluator() {
  100. // ... your evaluator
  101. }
  102. ----
  103. .Kotlin
  104. [source,kotlin,role="secondary"]
  105. ----
  106. companion object {
  107. @Bean
  108. fun permissionEvaluator(): PermissionEvaluator {
  109. // ... your evaluator
  110. }
  111. }
  112. ----
  113. ====
  114. to:
  115. ====
  116. .Java
  117. [source,java,role="primary"]
  118. ----
  119. @Bean
  120. static MethodSecurityExpressionHandler expressionHandler() {
  121. var expressionHandler = new DefaultMethodSecurityExpressionHandler();
  122. expressionHandler.setPermissionEvaluator(myPermissionEvaluator);
  123. return expressionHandler;
  124. }
  125. ----
  126. .Kotlin
  127. [source,kotlin,role="secondary"]
  128. ----
  129. companion object {
  130. @Bean
  131. fun expressionHandler(): MethodSecurityExpressionHandler {
  132. val expressionHandler = DefaultMethodSecurityExpressionHandler
  133. expressionHandler.setPermissionEvaluator(myPermissionEvaluator)
  134. return expressionHandler
  135. }
  136. }
  137. ----
  138. ====
  139. '''
  140. [[servlet-check-for-annotationconfigurationexceptions]]
  141. [%interactive]
  142. * [ ] Check for ``AnnotationConfigurationException``s
  143. `@EnableMethodSecurity` and `<method-security>` activate stricter enforcement of Spring Security's non-repeatable or otherwise incompatible annotations.
  144. If after moving to either you see ``AnnotationConfigurationException``s in your logs, follow the instructions in the exception message to clean up your application's method security annotation usage.
  145. == Reactive
  146. === Use `AuthorizationManager` for Method Security
  147. xref:reactive/authorization/method.adoc[Method Security] has been xref:reactive/authorization/method.adoc#jc-enable-reactive-method-security-authorization-manager[improved] through {security-api-url}org/springframework/security/authorization/AuthorizationManager.html[the `AuthorizationManager` API] and direct use of Spring AOP.
  148. '''
  149. [[reactive-change-to-useauthorizationmanager]]
  150. [%interactive]
  151. * [ ] Change `useAuthorizationManager` to `true`
  152. In Spring Security 5.8, `useAuthorizationManager` was added to {security-api-url}org/springframework/security/config/annotation/method/configuration/EnableReactiveMethodSecurity.html[`@EnableReactiveMethodSecurity`] to allow applications to opt-in to ``AuthorizationManager``'s features.
  153. To opt in, change `useAuthorizationManager` to `true` like so:
  154. ====
  155. .Java
  156. [source,java,role="primary"]
  157. ----
  158. @EnableReactiveMethodSecurity
  159. ----
  160. .Kotlin
  161. [source,kotlin,role="secondary"]
  162. ----
  163. @EnableReactiveMethodSecurity
  164. ----
  165. ====
  166. changes to:
  167. ====
  168. .Java
  169. [source,java,role="primary"]
  170. ----
  171. @EnableReactiveMethodSecurity(useAuthorizationManager = true)
  172. ----
  173. .Kotlin
  174. [source,kotlin,role="secondary"]
  175. ----
  176. @EnableReactiveMethodSecurity(useAuthorizationManager = true)
  177. ----
  178. ====
  179. [NOTE]
  180. =====
  181. In 6.0, `useAuthorizationManager` defaults to `true`.
  182. =====
  183. '''
  184. [[reactive-check-for-annotationconfigurationexceptions]]
  185. [%interactive]
  186. * [ ] Check for ``AnnotationConfigurationException``s
  187. `useAuthorizationManager` activates stricter enforcement of Spring Security's non-repeatable or otherwise incompatible annotations.
  188. If after turning on `useAuthorizationManager` you see ``AnnotationConfigurationException``s in your logs, follow the instructions in the exception message to clean up your application's method security annotation usage.