@Override public <T> T runAsUser( final String principalName, final IParameterProvider paramProvider, final Callable<T> callable ) throws Exception { IPentahoSession origSession = PentahoSessionHolder.getSession(); Authentication origAuth = SecurityContextHolder.getContext().getAuthentication(); try { becomeUser( principalName ); return callable.call(); } finally { IPentahoSession sessionToDestroy = PentahoSessionHolder.getSession(); if ( sessionToDestroy != null && sessionToDestroy != origSession ) { try { sessionToDestroy.destroy(); } catch ( Exception e ) { e.printStackTrace(); } } PentahoSessionHolder.setSession( origSession ); SecurityContextHolder.getContext().setAuthentication( origAuth ); } }
if ( sessionToDestroy != null && sessionToDestroy != origSession ) { try { sessionToDestroy.destroy(); } catch ( Exception e ) { e.printStackTrace();
} finally { if ( pentahoSession != null ) { pentahoSession.destroy();