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

@ -320,21 +320,24 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean {
logger.debug("Switching to RunAs Authentication: " logger.debug("Switching to RunAs Authentication: "
+ runAs.toString()); + runAs.toString());
} }
SecureContext origSecureContext = null;
try {
origSecureContext = (SecureContext) ContextHolder.getContext();
context.setAuthentication(runAs);
ContextHolder.setContext((Context) context);
context.setAuthentication(runAs); return callback.proceedWithObject(object);
ContextHolder.setContext((Context) context); }
finally {
Object ret = callback.proceedWithObject(object); if (logger.isDebugEnabled()) {
logger.debug("Reverting to original Authentication: "
if (logger.isDebugEnabled()) { + authenticated.toString());
logger.debug("Reverting to original Authentication: " }
+ authenticated.toString());
origSecureContext.setAuthentication(authenticated);
ContextHolder.setContext(origSecureContext);
} }
context.setAuthentication(authenticated);
ContextHolder.setContext((Context) context);
return ret;
} }
} else { } else {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {