Skip to content
Permalink
Browse files

Clearer diagnosis for JENKINS-12543 and similar issues.

  • Loading branch information
jglick committed Mar 19, 2014
1 parent 2b9cfe3 commit b261ab212270179fd286588534e9771dfb15f5fe
@@ -26,7 +26,11 @@

import hudson.model.Item;
import hudson.model.Items;
import hudson.security.ACL;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.acegisecurity.Authentication;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
@@ -43,17 +47,30 @@
*/
public abstract class GenericItemOptionHandler<T extends Item> extends OptionHandler<T> {

private static final Logger LOGGER = Logger.getLogger(GenericItemOptionHandler.class.getName());

protected GenericItemOptionHandler(CmdLineParser parser, OptionDef option, Setter<T> setter) {
super(parser, option, setter);
}

protected abstract Class<T> type();

@Override public int parseArguments(Parameters params) throws CmdLineException {
Jenkins j = Jenkins.getInstance();
String src = params.getParameter(0);
final Jenkins j = Jenkins.getInstance();
final String src = params.getParameter(0);
T s = j.getItemByFullName(src, type());
if (s == null) {
final Authentication who = Jenkins.getAuthentication();
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
Item actual = j.getItemByFullName(src);
if (actual == null) {
LOGGER.log(Level.FINE, "really no item exists named {0}", src);
} else {
LOGGER.log(Level.WARNING, "running as {0} could not find {1} of {2}", new Object[] {who.getPrincipal(), actual, type()});
}
}
});
T nearest = Items.findNearest(type(), src, j);
if (nearest != null) {
throw new CmdLineException(owner, "No such job '" + src + "'; perhaps you meant '" + nearest.getFullName() + "'?");
@@ -3392,7 +3392,7 @@ public void run() {
* Gets the {@link Authentication} object that represents the user
* associated with the current request.
*/
public static Authentication getAuthentication() {
public static @Nonnull Authentication getAuthentication() {
Authentication a = SecurityContextHolder.getContext().getAuthentication();
// on Tomcat while serving the login page, this is null despite the fact
// that we have filters. Looking at the stack trace, Tomcat doesn't seem to

0 comments on commit b261ab2

Please sign in to comment.
You can’t perform that action at this time.