From aeefa6eb99a2c54b30bbd40bb68212360717a4a2 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 29 Apr 2016 08:18:13 -0400 Subject: [PATCH] More informative error when refusing to copy. --- core/src/main/java/hudson/model/ItemGroupMixIn.java | 5 +++-- core/src/main/resources/hudson/model/Messages.properties | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/ItemGroupMixIn.java b/core/src/main/java/hudson/model/ItemGroupMixIn.java index f41616aff4..e973a52e69 100644 --- a/core/src/main/java/hudson/model/ItemGroupMixIn.java +++ b/core/src/main/java/hudson/model/ItemGroupMixIn.java @@ -27,7 +27,6 @@ import hudson.Util; import hudson.XmlFile; import hudson.model.listeners.ItemListener; import hudson.security.AccessControlled; -import hudson.security.AccessDeniedException2; import hudson.util.CopyOnWriteMap; import hudson.util.Function1; import hudson.util.Secret; @@ -51,6 +50,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import jenkins.security.NotReallyRoleSensitiveCallable; +import org.acegisecurity.AccessDeniedException; import org.xml.sax.SAXException; /** @@ -229,7 +229,8 @@ public abstract class ItemGroupMixIn { Matcher matcher = AbstractItem.SECRET_PATTERN.matcher(srcConfigFile.asString()); while (matcher.find()) { if (Secret.decrypt(matcher.group(1)) != null) { - throw new AccessDeniedException2(Jenkins.getAuthentication(), Item.CONFIGURE); + // AccessDeniedException2 does not permit a custom message, and anyway redirecting the user to the login screen is obviously pointless. + throw new AccessDeniedException(Messages.ItemGroupMixIn_may_not_copy_as_it_contains_secrets_and_(src.getFullName(), Jenkins.getAuthentication().getName(), Item.PERMISSIONS.title, Item.EXTENDED_READ.name, Item.CONFIGURE.name)); } } } diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index c9b024bca3..ed8f1e6be0 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -175,7 +175,7 @@ Item.CREATE.description=Create a new job. Item.DELETE.description=Delete a job. Item.CONFIGURE.description=Change the configuration of a job. Item.READ.description=See a job. (You may deny this permission but allow Discover to force an anonymous user to log in to see the job.) - +ItemGroupMixIn.may_not_copy_as_it_contains_secrets_and_=May not copy {0} as it contains secrets and {1} has {2}/{3} but not /{4} Job.AllRecentBuildFailed=All recent builds failed. Job.BuildStability=Build stability: {0} Job.NOfMFailed={0} out of the last {1} builds failed.