Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.core.Ordered;
import org.springframework.grpc.server.exception.GrpcExceptionHandler;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;

import io.grpc.Status;
import io.grpc.StatusException;

public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler {
public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler, Ordered {

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

private final int order;

public SecurityGrpcExceptionHandler(int order) {
this.order = order;
}

@Override
public @Nullable StatusException handleException(Throwable exception) {
if (exception instanceof AuthenticationException) {
Expand All @@ -48,4 +55,9 @@ public class SecurityGrpcExceptionHandler implements GrpcExceptionHandler {
return null;
}

@Override
public int getOrder() {
return this.order;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static class ExceptionHandlerConfiguration {

@Bean
GrpcExceptionHandler accessExceptionHandler() {
return new SecurityGrpcExceptionHandler();
return new SecurityGrpcExceptionHandler(0);
}

}
Expand Down
Loading