oscerd commented on code in PR #28522:
URL: https://github.com/apache/camel/pull/28522#discussion_r4377346240
##########
components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityProcessor.java:
##########
@@ -124,9 +126,39 @@ private void applySecurityPolicy(Exchange exchange) throws
Exception {
authorizeUser(currentUser, exchange);
} finally {
if (policy.isAlwaysReauthenticate()) {
- currentUser.logout();
+ try {
+ currentUser.logout();
+ } finally {
+ ThreadContext.unbindSubject();
+ ThreadContext.unbindSecurityManager();
Review Comment:
Good catch. Added a `boolean success` check to ensure `currentUser.logout()`
and `ThreadContext.unbindSubject()` / `unbindSecurityManager()` are always
executed if an exception is thrown, preventing stale bindings from persisting
on returned threads when `alwaysReauthenticate=false`. Added a dedicated test
`testThreadContextCleanupOnFailureWithReauthenticateFalse` asserting thread
cleanup.
##########
components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityProcessor.java:
##########
@@ -124,9 +126,39 @@ private void applySecurityPolicy(Exchange exchange) throws
Exception {
authorizeUser(currentUser, exchange);
} finally {
if (policy.isAlwaysReauthenticate()) {
- currentUser.logout();
+ try {
+ currentUser.logout();
+ } finally {
+ ThreadContext.unbindSubject();
+ ThreadContext.unbindSecurityManager();
+ }
+ }
+ }
+ }
+
+ private Subject resolveSubject() {
+ Subject currentUser = null;
+ Subject threadSubject = ThreadContext.getSubject();
+ if (threadSubject instanceof DelegatingSubject) {
+ DelegatingSubject delegatingSubject = (DelegatingSubject)
threadSubject;
Review Comment:
Updated to use pattern matching for `instanceof`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]