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: docs/modules/ROOT/pages/servlet/authorization/method-security.adoc
+18-8Lines changed: 18 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1070,7 +1070,7 @@ It also has access to the full Java language.
1070
1070
[[custom-authorization-managers]]
1071
1071
=== Using a Custom Authorization Manager
1072
1072
1073
-
The second way to authorize a method programmatically is two create a custom xref:servlet/authorization/architecture.adoc#_the_authorizationmanager[`AuthorizationManager`].
1073
+
The second way to authorize a method programmatically is to create a custom xref:servlet/authorization/architecture.adoc#_the_authorizationmanager[`AuthorizationManager`].
1074
1074
1075
1075
First, declare an authorization manager instance, perhaps like this one:
1076
1076
@@ -1081,20 +1081,30 @@ Java::
1081
1081
[source,java,role="primary"]
1082
1082
----
1083
1083
@Component
1084
-
public class MyAuthorizationManager implements AuthorizationManager<MethodInvocation> {
1084
+
public class MyAuthorizationManager implements AuthorizationManager<MethodInvocation>, AuthorizationManager<MethodInvocationResult> {
1085
+
@Override
1085
1086
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocation invocation) {
1086
1087
// ... authorization logic
1087
1088
}
1089
+
1090
+
@Override
1091
+
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocationResult invocation) {
1092
+
// ... authorization logic
1093
+
}
1088
1094
}
1089
1095
----
1090
1096
1091
1097
Kotlin::
1092
1098
+
1093
1099
[source,kotlin,role="secondary"]
1094
1100
----
1095
-
@Component("authz")
1096
-
open class MyAuthorizationManager: AuthorizationManager<MethodInvocation> {
1097
-
fun check(val authentication: Supplier<Authentication>, val invocation: MethodInvocation): AuthorizationDecision {
1101
+
@Component
1102
+
class MyAuthorizationManager : AuthorizationManager<MethodInvocation>, AuthorizationManager<MethodInvocationResult> {
1103
+
override fun check(authentication: Supplier<Authentication>, invocation: MethodInvocation): AuthorizationDecision {
1104
+
// ... authorization logic
1105
+
}
1106
+
1107
+
override fun check(authentication: Supplier<Authentication>, invocation: MethodInvocationResult): AuthorizationDecision {
1098
1108
// ... authorization logic
1099
1109
}
1100
1110
}
@@ -1104,7 +1114,7 @@ open class MyAuthorizationManager: AuthorizationManager<MethodInvocation> {
1104
1114
Then, publish the method interceptor with a pointcut that corresponds to when you want that `AuthorizationManager` to run.
1105
1115
For example, you could replace how `@PreAuthorize` and `@PostAuthorize` work like so:
1106
1116
1107
-
.Only @PostAuthorize Configuration
1117
+
.Only @PreAuthorize and @PostAuthorize Configuration
0 commit comments