You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
== EnableReactiveMethodSecurity with AuthorizationManager
15
+
16
+
In Spring Security 5.8, we can enable annotation-based security using the `@EnableReactiveMethodSecurity(useAuthorizationManager=true)` annotation on any `@Configuration` instance.
17
+
18
+
This improves upon `@EnableReactiveMethodSecurity` in a number of ways. `@EnableReactiveMethodSecurity(useAuthorizationManager=true)`:
19
+
20
+
1. Uses the simplified `AuthorizationManager` API instead of metadata sources, config attributes, decision managers, and voters.
21
+
This simplifies reuse and customization.
22
+
2. Supports reactive return types. Note that we are waiting on https://github.com/spring-projects/spring-framework/issues/22462[additional coroutine support from the Spring Framework] before adding coroutine support.
23
+
3. Is built using native Spring AOP, removing abstractions and allowing you to use Spring AOP building blocks to customize
24
+
4. Checks for conflicting annotations to ensure an unambiguous security configuration
25
+
5. Complies with JSR-250
26
+
27
+
[NOTE]
28
+
====
29
+
For earlier versions, please read about similar support with <<jc-enable-reactive-method-security, @EnableReactiveMethodSecurity>>.
30
+
====
31
+
32
+
For example, the following would enable Spring Security's `@PreAuthorize` annotation:
Adding an annotation to a method (on a class or interface) would then limit the access to that method accordingly.
47
+
Spring Security's native annotation support defines a set of attributes for the method.
48
+
These will be passed to the various method interceptors, like `AuthorizationManagerBeforeReactiveMethodInterceptor`, for it to make the actual decision:
We expose `GrantedAuthorityDefaults` using a `static` method to ensure that Spring publishes it before it initializes Spring Security's method security `@Configuration` classes
Or, you may have a custom before-method `ReactiveAuthorizationManager` that you want to add to the list.
208
+
209
+
In this case, you will need to tell Spring Security both the `ReactiveAuthorizationManager` and to which methods and classes your authorization manager applies.
210
+
211
+
Thus, you can configure Spring Security to invoke your `ReactiveAuthorizationManager` in between `@PreAuthorize` and `@PostAuthorize` like so:
and it will be invoked after the `@PostAuthorize` interceptor.
284
+
285
+
== EnableReactiveMethodSecurity
286
+
13
287
[WARNING]
14
288
====
15
-
Method Security also supports Kotlin coroutines, though only to a limited degree.
289
+
`@EnableReactiveMethodSecurity` also supports Kotlin coroutines, though only to a limited degree.
16
290
When intercepting coroutines, only the first interceptor participates.
17
-
If any other interceptors are present and come after Spring Security's method security interceptor, they will be skipped.
291
+
If any other interceptors are present and come after Spring Security's method security interceptor, https://github.com/spring-projects/spring-framework/issues/22462[they will be skipped].
0 commit comments