mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
[FIXED JENKINS-36494] Switch to a try with resources form of impersonation
This commit is contained in:
1 parent
f9efe65249
commit
0203504a2c
12 files changed
+299
-226
No files matched your search
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
package hudson;
|
||||
|
||||
import hudson.security.ACLContext;
|
||||
import jenkins.util.SystemProperties;
|
||||
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
|
||||
import com.thoughtworks.xstream.core.JVM;
|
||||
@@ -59,7 +60,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Date;
|
||||
@@ -370,25 +370,20 @@ public class WebAppMain implements ServletContextListener {
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
try {
|
||||
ACL.impersonate(ACL.SYSTEM, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
terminated = true;
|
||||
Jenkins instance = Jenkins.getInstanceOrNull();
|
||||
if (instance != null)
|
||||
instance.cleanUp();
|
||||
Thread t = initThread;
|
||||
if (t != null && t.isAlive()) {
|
||||
LOGGER.log(Level.INFO, "Shutting down a Jenkins instance that was still starting up", new Throwable("reason"));
|
||||
t.interrupt();
|
||||
}
|
||||
try (ACLContext old = ACL.as(ACL.SYSTEM)) {
|
||||
terminated = true;
|
||||
Jenkins instance = Jenkins.getInstanceOrNull();
|
||||
if (instance != null)
|
||||
instance.cleanUp();
|
||||
Thread t = initThread;
|
||||
if (t != null && t.isAlive()) {
|
||||
LOGGER.log(Level.INFO, "Shutting down a Jenkins instance that was still starting up", new Throwable("reason"));
|
||||
t.interrupt();
|
||||
}
|
||||
|
||||
// Logger is in the system classloader, so if we don't do this
|
||||
// the whole web app will never be undepoyed.
|
||||
Logger.getLogger("").removeHandler(handler);
|
||||
}
|
||||
});
|
||||
// Logger is in the system classloader, so if we don't do this
|
||||
// the whole web app will never be undepoyed.
|
||||
Logger.getLogger("").removeHandler(handler);
|
||||
} finally {
|
||||
JenkinsJVMAccess._setJenkinsJVM(false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user