Skip to content

Commit 211b1b7

Browse files
committed
Update Method Security Migration Steps
1 parent 84db5bb commit 211b1b7

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

docs/modules/ROOT/pages/migration-7/authorization.adoc

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,82 @@ public void doSomething(Long id) {
2222

2323
You must compile with `-parameters` to ensure that the parameter names are available at runtime.
2424
For more information about this, please visit the https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#core-container[Upgrading to Spring Framework 6.1 page].
25+
26+
=== Favor `AnnotationTemplateExpressionDefaults` over `PrePostTemplateDefaults`
27+
28+
In Spring Security 7, `AnnotationTemplateExpressionDefaults` will be included by default.
29+
30+
If you are customizing `PrePostTemplateDefaults` or simply want to see how your application responds to `AnnotationTemplateExpressionDefaults`, you can publish an `AnnotationTemplateExpressionDefaults` bean instead of a `PrePostTemplateDefaults` method:
31+
32+
[tabs]
33+
======
34+
Java::
35+
+
36+
[source,java,role="primary"]
37+
----
38+
@Bean
39+
static AnnotationTemplateExpressionDefaults templateExpressionDefaults() {
40+
return new AnnotationTemplateExpressionDefaults();
41+
}
42+
----
43+
44+
Kotlin::
45+
+
46+
[source,kotlin,role="secondary"]
47+
----
48+
companion object {
49+
@Bean
50+
fun templateExpressionDefaults() = AnnotationTemplateExpressionDefaults()
51+
}
52+
----
53+
54+
Xml::
55+
+
56+
[source,xml,role="secondary"]
57+
----
58+
<b:bean id="templateExpressionDefaults" class="org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults"/>
59+
----
60+
======
61+
62+
==== I Am Publishing an AuthorizationAdvisor Bean
63+
64+
If you are publishing an `AuthorizationAdvisor` bean, like `AuthorizationManagerBeforeMethodInterceptor`, `AuthorizationManagerAfterMethodInterceptor`, `PreFilterAuthorizationMethodInterceptor`, or `PostFilterAuthorizationMethodInterceptor`, you can do the same by calling `setTemplateDefaults` with an `AnnotationTemplateExpressionDefaults` instance instead:
65+
66+
[tabs]
67+
======
68+
Java::
69+
+
70+
[source,java,role="primary"]
71+
----
72+
@Bean
73+
@Role(BeanDescription.ROLE_INFRASTRUCTURE)
74+
static Advisor preFilter() {
75+
PreFilterAuthorizationMethodInterceptor interceptor = new PreFilterAuthorizationMethodInterceptor();
76+
interceptor.setTemplateDefaults(new AnnotationTemplateExpressionDefaults());
77+
return interceptor;
78+
}
79+
----
80+
81+
Kotlin::
82+
+
83+
[source,kotlin,role="secondary"]
84+
----
85+
companion object {
86+
@Bean
87+
@Role(BeanDescription.ROLE_INFRASTRUCTURE)
88+
fun preFilter(): Advisor {
89+
val interceptor = PreFilterAuthorizationMethodInterceptor()
90+
interceptor.setTemplateDefaults(AnnotationTemplateExpressionDefaults)
91+
return interceptor
92+
}
93+
}
94+
----
95+
======
96+
97+
=== Publish `AuthorizationAdvisor` instances instead of adding them in a `Customizer<AuthorizationAdvisorProxyFactory>`
98+
99+
While the ability to customize the `AuthorizationAdvisorProxyFactory` instance will remain in Spring Security 7, the ability to add advisors will be removed in favor of picking up published `AuthorizationAdvisor` beans.
100+
101+
If you are not calling `AuthorizationAdvisorProxyFactory#setAdvisors` or `AuthorizationAdvisorProxyFactory#addAdvisor`, you need do nothing.
102+
103+
If you are, publish the `AuthorizationAdvisor` bean instead and Spring Security will pick it up and apply it automatically.

0 commit comments

Comments
 (0)