Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clearer diagnosis for JENKINS-12543 and similar issues.
  • Loading branch information
jglick committed Mar 19, 2014
1 parent 2b9cfe3 commit b261ab2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -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;
Expand All @@ -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() + "'?");
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -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
Expand Down

0 comments on commit b261ab2

Please sign in to comment.