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
Copy file name to clipboardExpand all lines: config/src/main/java/org/springframework/security/config/annotation/method/configuration/PrePostMethodSecurityConfiguration.java
Copy file name to clipboardExpand all lines: core/src/main/java/org/springframework/security/aot/hint/PrePostAuthorizeExpressionBeanHintsRegistrar.java
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/method-security.adoc
+66-1
Original file line number
Diff line number
Diff line change
@@ -1536,7 +1536,6 @@ If it finds a method that uses `@AuthorizeReturnObject`, it will recursively sea
1536
1536
1537
1537
For example, consider the following Spring Boot application:
1538
1538
1539
-
.Custom MethodSecurityExpressionHandler
1540
1539
[tabs]
1541
1540
======
1542
1541
Java::
@@ -1633,6 +1632,72 @@ class User(private val fullName: String) {
1633
1632
<5> Finding another `@AuthorizeReturnObject` it will look again into the method's return type
1634
1633
<6> Now, a `@PostAuthorize` is found with yet another bean name used: `myOtherAuthz`; the runtime hints are registered for the bean class as well
1635
1634
1635
+
There will be many times when Spring Security cannot determine the actual return type of the method ahead of time since it may be hidden in an erased generic type.
1636
+
1637
+
Consider the following service:
1638
+
1639
+
[tabs]
1640
+
======
1641
+
Java::
1642
+
+
1643
+
[source,java,role="primary"]
1644
+
----
1645
+
@Service
1646
+
public class AccountService {
1647
+
1648
+
@AuthorizeReturnObject
1649
+
public List<Account> getAllAccounts() {
1650
+
// ...
1651
+
}
1652
+
1653
+
}
1654
+
----
1655
+
1656
+
Kotlin::
1657
+
+
1658
+
[source,kotlin,role="secondary"]
1659
+
----
1660
+
@Service
1661
+
class AccountService {
1662
+
1663
+
@AuthorizeReturnObject
1664
+
fun getAllAccounts(): List<Account> {
1665
+
// ...
1666
+
}
1667
+
1668
+
}
1669
+
----
1670
+
======
1671
+
1672
+
In this case, the generic type is erased and so it isn’t apparent to Spring Security ahead-of-time that `Account` needs to be visited in order to check for `@PreAuthorize` and `@PostAuthorize`.
1673
+
1674
+
To address this, you can publish a javadoc:org.springframework.security.aot.hint.PrePostAuthorizeExpressionBeanHintsRegistrar[`PrePostAuthorizeExpressionBeanHintsRegistrar`] like so:
0 commit comments