|
|
|
|
@ -1377,14 +1377,17 @@ Java::
@@ -1377,14 +1377,17 @@ Java::
|
|
|
|
|
[source,java,role="primary"] |
|
|
|
|
---- |
|
|
|
|
@Component |
|
|
|
|
public class MyAuthorizationManager implements AuthorizationManager<MethodInvocation>, AuthorizationManager<MethodInvocationResult> { |
|
|
|
|
public class MyPreAuthorizeAuthorizationManager implements AuthorizationManager<MethodInvocation> { |
|
|
|
|
@Override |
|
|
|
|
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocation invocation) { |
|
|
|
|
public AuthorizationResult authorize(Supplier<Authentication> authentication, MethodInvocation invocation) { |
|
|
|
|
// ... authorization logic |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
public class MyPostAuthorizeAuthorizationManager implements AuthorizationManager<MethodInvocationResult> { |
|
|
|
|
@Override |
|
|
|
|
public AuthorizationDecision check(Supplier<Authentication> authentication, MethodInvocationResult invocation) { |
|
|
|
|
public AuthorizationResult authorize(Supplier<Authentication> authentication, MethodInvocationResult invocation) { |
|
|
|
|
// ... authorization logic |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1395,12 +1398,15 @@ Kotlin::
@@ -1395,12 +1398,15 @@ Kotlin::
|
|
|
|
|
[source,kotlin,role="secondary"] |
|
|
|
|
---- |
|
|
|
|
@Component |
|
|
|
|
class MyAuthorizationManager : AuthorizationManager<MethodInvocation>, AuthorizationManager<MethodInvocationResult> { |
|
|
|
|
override fun check(authentication: Supplier<Authentication>, invocation: MethodInvocation): AuthorizationDecision { |
|
|
|
|
class MyPreAuthorizeAuthorizationManager : AuthorizationManager<MethodInvocation> { |
|
|
|
|
override fun authorize(authentication: Supplier<Authentication>, invocation: MethodInvocation): AuthorizationResult { |
|
|
|
|
// ... authorization logic |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun check(authentication: Supplier<Authentication>, invocation: MethodInvocationResult): AuthorizationDecision { |
|
|
|
|
@Component |
|
|
|
|
class MyPostAuthorizeAuthorizationManager : AuthorizationManager<MethodInvocationResult> { |
|
|
|
|
override fun authorize(authentication: Supplier<Authentication>, invocation: MethodInvocationResult): AuthorizationResult { |
|
|
|
|
// ... authorization logic |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1422,13 +1428,15 @@ Java::
@@ -1422,13 +1428,15 @@ Java::
|
|
|
|
|
class MethodSecurityConfig { |
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
Advisor preAuthorize(MyAuthorizationManager manager) { |
|
|
|
|
Advisor preAuthorize() { |
|
|
|
|
MyPreAuthorizeAuthorizationManager manager = new MyPreAuthorizeAuthorizationManager(); |
|
|
|
|
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
Advisor postAuthorize(MyAuthorizationManager manager) { |
|
|
|
|
Advisor postAuthorize() { |
|
|
|
|
MyPostAuthorizeAuthorizationManager manager = new MyPostAuthorizeAuthorizationManager(); |
|
|
|
|
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1441,17 +1449,19 @@ Kotlin::
@@ -1441,17 +1449,19 @@ Kotlin::
|
|
|
|
|
@Configuration |
|
|
|
|
@EnableMethodSecurity(prePostEnabled = false) |
|
|
|
|
class MethodSecurityConfig { |
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
fun preAuthorize(manager: MyAuthorizationManager) : Advisor { |
|
|
|
|
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager) |
|
|
|
|
} |
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
fun preAuthorize(): Advisor { |
|
|
|
|
val manager = MyPreAuthorizeAuthorizationManager() |
|
|
|
|
return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
fun postAuthorize(manager: MyAuthorizationManager) : Advisor { |
|
|
|
|
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager) |
|
|
|
|
} |
|
|
|
|
@Bean |
|
|
|
|
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
|
|
|
|
fun postAuthorize(): Advisor { |
|
|
|
|
val manager = MyPostAuthorizeAuthorizationManager() |
|
|
|
|
return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
@ -1466,13 +1476,11 @@ Xml::
@@ -1466,13 +1476,11 @@ Xml::
|
|
|
|
|
<bean id="preAuthorize" |
|
|
|
|
class="org.springframework.security.authorization.method.AuthorizationManagerBeforeMethodInterceptor" |
|
|
|
|
factory-method="preAuthorize"> |
|
|
|
|
<constructor-arg ref="myAuthorizationManager"/> |
|
|
|
|
</bean> |
|
|
|
|
|
|
|
|
|
<bean id="postAuthorize" |
|
|
|
|
class="org.springframework.security.authorization.method.AuthorizationManagerAfterMethodInterceptor" |
|
|
|
|
factory-method="postAuthorize"> |
|
|
|
|
<constructor-arg ref="myAuthorizationManager"/> |
|
|
|
|
</bean> |
|
|
|
|
---- |
|
|
|
|
====== |
|
|
|
|
@ -1482,6 +1490,8 @@ Xml::
@@ -1482,6 +1490,8 @@ Xml::
|
|
|
|
|
You can place your interceptor in between Spring Security method interceptors using the order constants specified in `AuthorizationInterceptorsOrder`. |
|
|
|
|
==== |
|
|
|
|
|
|
|
|
|
Additionally, you can also implement `MethodAuthorizationDeniedHandler` by the same manager, to override default exception handling behavior. |
|
|
|
|
|
|
|
|
|
[[customizing-expression-handling]] |
|
|
|
|
=== Customizing Expression Handling |
|
|
|
|
|
|
|
|
|
|