This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-jbang-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 6827eea Improved Error Handling in keycloak security rest example
6827eea is described below
commit 6827eea8c222254bcc23a167feb643a16556ea76
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Oct 21 12:08:31 2025 +0200
Improved Error Handling in keycloak security rest example
Signed-off-by: Andrea Cosentino <[email protected]>
---
edi-x12-as2/camel/edi-x12-as2.camel.yaml | 2 +-
keycloak-security-rest/rest-api.camel.yaml | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/edi-x12-as2/camel/edi-x12-as2.camel.yaml
b/edi-x12-as2/camel/edi-x12-as2.camel.yaml
index 36a4eaa..5dce04d 100644
--- a/edi-x12-as2/camel/edi-x12-as2.camel.yaml
+++ b/edi-x12-as2/camel/edi-x12-as2.camel.yaml
@@ -112,4 +112,4 @@
- to:
uri: "http://{{tracker.address}}"
parameters:
- httpMethod: POST
\ No newline at end of file
+ httpMethod: POST
diff --git a/keycloak-security-rest/rest-api.camel.yaml
b/keycloak-security-rest/rest-api.camel.yaml
index 83a05a0..55c1714 100644
--- a/keycloak-security-rest/rest-api.camel.yaml
+++ b/keycloak-security-rest/rest-api.camel.yaml
@@ -17,6 +17,31 @@
# camel-k: dependency=camel:keycloak
+# Global exception handler for authorization failures
+# Handles CamelAuthorizationException to return proper HTTP status codes
+- onException:
+ exception:
+ - "org.apache.camel.CamelAuthorizationException"
+ handled:
+ constant: true
+ steps:
+ - setHeader:
+ name: CamelHttpResponseCode
+ constant: 403
+ - setHeader:
+ name: Content-Type
+ constant: application/json
+ - setBody:
+ simple: |
+ {
+ "error": "Forbidden",
+ "message": "Access denied. ${exception.message}",
+ "timestamp": "${date:now:yyyy-MM-dd'T'HH:mm:ss}",
+ "status": 403
+ }
+ - log:
+ message: "Authorization failed: ${exception.message}"
+
# Bean definition for Keycloak security policy
- beans:
- name: keycloakPolicy