Skip to content

Commit 7a8faf8

Browse files
pbborisov18marcusdacoregio
authored andcommitted
Docs custom AuthorizationManager fix
Issue gh-13967
1 parent 4661b22 commit 7a8faf8

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

docs/modules/ROOT/pages/servlet/authorization/method-security.adoc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ It also has access to the full Java language.
10701070
[[custom-authorization-managers]]
10711071
=== Using a Custom Authorization Manager
10721072

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`].
10741074

10751075
First, declare an authorization manager instance, perhaps like this one:
10761076

@@ -1081,20 +1081,30 @@ Java::
10811081
[source,java,role="primary"]
10821082
----
10831083
@Component
1084-
public class MyAuthorizationManager implements AuthorizationManager<MethodInvocation> {
1084+
public class MyAuthorizationManager implements AuthorizationManager<MethodInvocation>, AuthorizationManager<MethodInvocationResult> {
1085+
@Override
10851086
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocation invocation) {
10861087
// ... authorization logic
10871088
}
1089+
1090+
@Override
1091+
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocationResult invocation) {
1092+
// ... authorization logic
1093+
}
10881094
}
10891095
----
10901096
10911097
Kotlin::
10921098
+
10931099
[source,kotlin,role="secondary"]
10941100
----
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 {
10981108
// ... authorization logic
10991109
}
11001110
}
@@ -1104,7 +1114,7 @@ open class MyAuthorizationManager: AuthorizationManager<MethodInvocation> {
11041114
Then, publish the method interceptor with a pointcut that corresponds to when you want that `AuthorizationManager` to run.
11051115
For example, you could replace how `@PreAuthorize` and `@PostAuthorize` work like so:
11061116

1107-
.Only @PostAuthorize Configuration
1117+
.Only @PreAuthorize and @PostAuthorize Configuration
11081118
[tabs]
11091119
======
11101120
Java::
@@ -1116,7 +1126,7 @@ Java::
11161126
class MethodSecurityConfig {
11171127
@Bean
11181128
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
1119-
Advisor postAuthorize(MyAuthorizationManager manager) {
1129+
Advisor preAuthorize(MyAuthorizationManager manager) {
11201130
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager);
11211131
}
11221132
@@ -1157,7 +1167,7 @@ Xml::
11571167
11581168
<aop:config/>
11591169
1160-
<bean id="postAuthorize"
1170+
<bean id="preAuthorize"
11611171
class="org.springframework.security.authorization.method.AuthorizationManagerBeforeMethodInterceptor"
11621172
factory-method="preAuthorize">
11631173
<constructor-arg ref="myAuthorizationManager"/>

0 commit comments

Comments
 (0)