mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-14 06:13:30 +00:00
after invocation, restore pre-RunAs Authentication regardless of exception that may be thrown by method being intercepted
This commit is contained in:
parent
302ae5a391
commit
ab9e783f79
@ -321,20 +321,23 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean {
|
|||||||
+ runAs.toString());
|
+ runAs.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SecureContext origSecureContext = null;
|
||||||
|
try {
|
||||||
|
origSecureContext = (SecureContext) ContextHolder.getContext();
|
||||||
context.setAuthentication(runAs);
|
context.setAuthentication(runAs);
|
||||||
ContextHolder.setContext((Context) context);
|
ContextHolder.setContext((Context) context);
|
||||||
|
|
||||||
Object ret = callback.proceedWithObject(object);
|
return callback.proceedWithObject(object);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Reverting to original Authentication: "
|
logger.debug("Reverting to original Authentication: "
|
||||||
+ authenticated.toString());
|
+ authenticated.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setAuthentication(authenticated);
|
origSecureContext.setAuthentication(authenticated);
|
||||||
ContextHolder.setContext((Context) context);
|
ContextHolder.setContext(origSecureContext);
|
||||||
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user