after invocation, restore pre-RunAs Authentication regardless of exception that may be thrown by method being intercepted

This commit is contained in:
Colin Sampaleanu 2004-04-21 21:09:39 +00:00
parent 302ae5a391
commit ab9e783f79

View File

@ -321,20 +321,23 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean {
+ runAs.toString()); + runAs.toString());
} }
context.setAuthentication(runAs); SecureContext origSecureContext = null;
ContextHolder.setContext((Context) context); try {
origSecureContext = (SecureContext) ContextHolder.getContext();
context.setAuthentication(runAs);
ContextHolder.setContext((Context) context);
Object ret = callback.proceedWithObject(object); return callback.proceedWithObject(object);
if (logger.isDebugEnabled()) {
logger.debug("Reverting to original Authentication: "
+ authenticated.toString());
} }
finally {
if (logger.isDebugEnabled()) {
logger.debug("Reverting to original Authentication: "
+ 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()) {