提交 a6a3d5e1 编写于 作者: J Jesse Glick

[FIXED JENKINS-25400] Rework fix of JENKINS-22769 (c04cdcd9) to put the burden...

[FIXED JENKINS-25400] Rework fix of JENKINS-22769 (c04cdcd9) to put the burden on each listener to impersonate ACL.SYSTEM if it needs to.
上级 b486e46c
...@@ -55,6 +55,9 @@ Upcoming changes</a> ...@@ -55,6 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. --> <!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=--> <div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image> <ul class=image>
<li class=bug>
Some plugins broken since 1.584 if they expected certain events to be fired under a specific user ID.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-25400">issue 25400</a>)
<li class=bug> <li class=bug>
Fixed various real or potential resource leaks. Fixed various real or potential resource leaks.
(<a href="https://github.com/jenkinsci/jenkins/pull/1434">pull request 1434</a>) (<a href="https://github.com/jenkinsci/jenkins/pull/1434">pull request 1434</a>)
......
...@@ -39,6 +39,7 @@ import hudson.BulkChange; ...@@ -39,6 +39,7 @@ import hudson.BulkChange;
import hudson.Extension; import hudson.Extension;
import hudson.model.listeners.ItemListener; import hudson.model.listeners.ItemListener;
import hudson.model.listeners.SaveableListener; import hudson.model.listeners.SaveableListener;
import hudson.security.ACL;
import hudson.util.AtomicFileWriter; import hudson.util.AtomicFileWriter;
import hudson.util.HexBinaryConverter; import hudson.util.HexBinaryConverter;
import hudson.util.Iterators; import hudson.util.Iterators;
...@@ -729,7 +730,14 @@ public class Fingerprint implements ModelObject, Saveable { ...@@ -729,7 +730,14 @@ public class Fingerprint implements ModelObject, Saveable {
@Extension @Extension
public static final class ProjectRenameListener extends ItemListener { public static final class ProjectRenameListener extends ItemListener {
@Override @Override
public void onLocationChanged(Item item, String oldName, String newName) { public void onLocationChanged(final Item item, final String oldName, final String newName) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
locationChanged(item, oldName, newName);
}
});
}
private void locationChanged(Item item, String oldName, String newName) {
if (item instanceof AbstractProject) { if (item instanceof AbstractProject) {
AbstractProject p = Jenkins.getInstance().getItemByFullName(newName, AbstractProject.class); AbstractProject p = Jenkins.getInstance().getItemByFullName(newName, AbstractProject.class);
if (p != null) { if (p != null) {
......
...@@ -29,6 +29,7 @@ import hudson.Util; ...@@ -29,6 +29,7 @@ import hudson.Util;
import hudson.diagnosis.OldDataMonitor; import hudson.diagnosis.OldDataMonitor;
import hudson.model.Descriptor.FormException; import hudson.model.Descriptor.FormException;
import hudson.model.listeners.ItemListener; import hudson.model.listeners.ItemListener;
import hudson.security.ACL;
import hudson.util.CaseInsensitiveComparator; import hudson.util.CaseInsensitiveComparator;
import hudson.util.DescribableList; import hudson.util.DescribableList;
import hudson.util.FormValidation; import hudson.util.FormValidation;
...@@ -431,7 +432,14 @@ public class ListView extends View implements DirectlyModifiableView { ...@@ -431,7 +432,14 @@ public class ListView extends View implements DirectlyModifiableView {
@Restricted(NoExternalUse.class) @Restricted(NoExternalUse.class)
@Extension public static final class Listener extends ItemListener { @Extension public static final class Listener extends ItemListener {
@Override public void onLocationChanged(Item item, String oldFullName, String newFullName) { @Override public void onLocationChanged(final Item item, final String oldFullName, final String newFullName) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
locationChanged(item, oldFullName, newFullName);
}
});
}
private void locationChanged(Item item, String oldFullName, String newFullName) {
final Jenkins jenkins = Jenkins.getInstance(); final Jenkins jenkins = Jenkins.getInstance();
for (View view: jenkins.getViews()) { for (View view: jenkins.getViews()) {
if (view instanceof ListView) { if (view instanceof ListView) {
...@@ -469,7 +477,14 @@ public class ListView extends View implements DirectlyModifiableView { ...@@ -469,7 +477,14 @@ public class ListView extends View implements DirectlyModifiableView {
} }
} }
@Override public void onDeleted(Item item) { @Override public void onDeleted(final Item item) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
deleted(item);
}
});
}
private void deleted(Item item) {
final Jenkins jenkins = Jenkins.getInstance(); final Jenkins jenkins = Jenkins.getInstance();
for (View view: jenkins.getViews()) { for (View view: jenkins.getViews()) {
if (view instanceof ListView) { if (view instanceof ListView) {
......
...@@ -31,8 +31,10 @@ import hudson.model.Item; ...@@ -31,8 +31,10 @@ import hudson.model.Item;
import hudson.model.ItemGroup; import hudson.model.ItemGroup;
import hudson.model.Items; import hudson.model.Items;
import hudson.security.ACL; import hudson.security.ACL;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import jenkins.security.NotReallyRoleSensitiveCallable;
/** /**
* Receives notifications about CRUD operations of {@link Item}. * Receives notifications about CRUD operations of {@link Item}.
...@@ -158,9 +160,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -158,9 +160,7 @@ public class ItemListener implements ExtensionPoint {
} }
// TODO JENKINS-21224 generalize this to a method perhaps in ExtensionList and use consistently from all listeners // TODO JENKINS-21224 generalize this to a method perhaps in ExtensionList and use consistently from all listeners
private static void forAll(final /* java.util.function.Consumer<ItemListener> */Function<ItemListener,Void> consumer, boolean asSystem) { private static void forAll(final /* java.util.function.Consumer<ItemListener> */Function<ItemListener,Void> consumer) {
Runnable r = new Runnable() {
@Override public void run() {
for (ItemListener l : all()) { for (ItemListener l : all()) {
try { try {
consumer.apply(l); consumer.apply(l);
...@@ -169,13 +169,6 @@ public class ItemListener implements ExtensionPoint { ...@@ -169,13 +169,6 @@ public class ItemListener implements ExtensionPoint {
} }
} }
} }
};
if (asSystem) {
ACL.impersonate(ACL.SYSTEM, r);
} else {
r.run();
}
}
public static void fireOnCopied(final Item src, final Item result) { public static void fireOnCopied(final Item src, final Item result) {
forAll(new Function<ItemListener,Void>() { forAll(new Function<ItemListener,Void>() {
...@@ -183,7 +176,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -183,7 +176,7 @@ public class ItemListener implements ExtensionPoint {
l.onCopied(src, result); l.onCopied(src, result);
return null; return null;
} }
}, true); });
} }
public static void fireOnCreated(final Item item) { public static void fireOnCreated(final Item item) {
...@@ -192,7 +185,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -192,7 +185,7 @@ public class ItemListener implements ExtensionPoint {
l.onCreated(item); l.onCreated(item);
return null; return null;
} }
}, true); });
} }
public static void fireOnUpdated(final Item item) { public static void fireOnUpdated(final Item item) {
...@@ -201,7 +194,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -201,7 +194,7 @@ public class ItemListener implements ExtensionPoint {
l.onUpdated(item); l.onUpdated(item);
return null; return null;
} }
}, true); });
} }
/** @since 1.548 */ /** @since 1.548 */
...@@ -211,7 +204,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -211,7 +204,7 @@ public class ItemListener implements ExtensionPoint {
l.onDeleted(item); l.onDeleted(item);
return null; return null;
} }
}, true); });
} }
/** /**
...@@ -221,13 +214,6 @@ public class ItemListener implements ExtensionPoint { ...@@ -221,13 +214,6 @@ public class ItemListener implements ExtensionPoint {
* @since 1.548 * @since 1.548
*/ */
public static void fireLocationChange(final Item rootItem, final String oldFullName) { public static void fireLocationChange(final Item rootItem, final String oldFullName) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
doFireLocationChange(rootItem, oldFullName);
}
});
}
private static void doFireLocationChange(final Item rootItem, final String oldFullName) {
String prefix = rootItem.getParent().getFullName(); String prefix = rootItem.getParent().getFullName();
if (!prefix.isEmpty()) { if (!prefix.isEmpty()) {
prefix += '/'; prefix += '/';
...@@ -244,16 +230,20 @@ public class ItemListener implements ExtensionPoint { ...@@ -244,16 +230,20 @@ public class ItemListener implements ExtensionPoint {
l.onRenamed(rootItem, oldName, newName); l.onRenamed(rootItem, oldName, newName);
return null; return null;
} }
}, false); });
} }
forAll(new Function<ItemListener, Void>() { forAll(new Function<ItemListener, Void>() {
@Override public Void apply(ItemListener l) { @Override public Void apply(ItemListener l) {
l.onLocationChanged(rootItem, oldFullName, newFullName); l.onLocationChanged(rootItem, oldFullName, newFullName);
return null; return null;
} }
}, false); });
if (rootItem instanceof ItemGroup) { if (rootItem instanceof ItemGroup) {
for (final Item child : Items.getAllItems((ItemGroup) rootItem, Item.class)) { for (final Item child : ACL.impersonate(ACL.SYSTEM, new NotReallyRoleSensitiveCallable<List<Item>,RuntimeException>() {
@Override public List<Item> call() {
return Items.getAllItems((ItemGroup) rootItem, Item.class);
}
})) {
final String childNew = child.getFullName(); final String childNew = child.getFullName();
assert childNew.startsWith(newFullName); assert childNew.startsWith(newFullName);
assert childNew.charAt(newFullName.length()) == '/'; assert childNew.charAt(newFullName.length()) == '/';
...@@ -263,7 +253,7 @@ public class ItemListener implements ExtensionPoint { ...@@ -263,7 +253,7 @@ public class ItemListener implements ExtensionPoint {
l.onLocationChanged(child, childOld, childNew); l.onLocationChanged(child, childOld, childNew);
return null; return null;
} }
}, false); });
} }
} }
} }
......
...@@ -406,7 +406,14 @@ public class BuildTrigger extends Recorder implements DependencyDeclarer { ...@@ -406,7 +406,14 @@ public class BuildTrigger extends Recorder implements DependencyDeclarer {
@Extension @Extension
public static class ItemListenerImpl extends ItemListener { public static class ItemListenerImpl extends ItemListener {
@Override @Override
public void onLocationChanged(Item item, String oldFullName, String newFullName) { public void onLocationChanged(final Item item, final String oldFullName, final String newFullName) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
locationChanged(item, oldFullName, newFullName);
}
});
}
private void locationChanged(Item item, String oldFullName, String newFullName) {
// update BuildTrigger of other projects that point to this object. // update BuildTrigger of other projects that point to this object.
// can't we generalize this? // can't we generalize this?
for( Project<?,?> p : Jenkins.getInstance().getAllItems(Project.class) ) { for( Project<?,?> p : Jenkins.getInstance().getAllItems(Project.class) ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册