Skip to content

Commit 22b38ce

Browse files
skjolberonobc
authored andcommitted
Allow ordering of exception handlers
Adds `@Order` to the security access exception handler which allows user-defined exception handlers to be ordered around the access exception handler. Closes #371 Signed-off-by: Thomas Skjølberg <thomas.skjolberg@gmail.com>
1 parent eb5351d commit 22b38ce

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

spring-grpc-core/src/main/java/org/springframework/grpc/server/security/SecurityGrpcExceptionHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@
2020
import org.apache.commons.logging.LogFactory;
2121
import org.jspecify.annotations.Nullable;
2222

23+
import org.springframework.core.Ordered;
2324
import org.springframework.grpc.server.exception.GrpcExceptionHandler;
2425
import org.springframework.security.access.AccessDeniedException;
2526
import org.springframework.security.core.AuthenticationException;
2627

2728
import io.grpc.Status;
2829
import io.grpc.StatusException;
2930

30-
public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler {
31+
public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler, Ordered {
3132

3233
private static final Log logger = LogFactory.getLog(SecurityGrpcExceptionHandler.class);
3334

35+
private final int order;
36+
37+
public SecurityGrpcExceptionHandler(int order) {
38+
this.order = order;
39+
}
40+
3441
@Override
3542
public @Nullable StatusException handleException(Throwable exception) {
3643
if (exception instanceof AuthenticationException) {
@@ -48,4 +55,9 @@ public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler {
4855
return null;
4956
}
5057

58+
@Override
59+
public int getOrder() {
60+
return this.order;
61+
}
62+
5163
}

spring-grpc-server-spring-boot-autoconfigure/src/main/java/org/springframework/boot/grpc/server/autoconfigure/security/GrpcSecurityAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static class ExceptionHandlerConfiguration {
7272

7373
@Bean
7474
GrpcExceptionHandler accessExceptionHandler() {
75-
return new SecurityGrpcExceptionHandler();
75+
return new SecurityGrpcExceptionHandler(0);
7676
}
7777

7878
}

0 commit comments

Comments
 (0)