From 571e7bf98f0bbef2ecdb443bf59e01e8dfa56b1b Mon Sep 17 00:00:00 2001 From: nicobo Date: Mon, 21 Sep 2015 23:51:45 +0200 Subject: [PATCH] + "Any" strategy is always available, even if no resolver is found at the time of the plugin setup --- .../script_realm/ScriptSecurityRealm.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/plugins/script_realm/ScriptSecurityRealm.java b/src/main/java/hudson/plugins/script_realm/ScriptSecurityRealm.java index 71b0871..d7a847c 100644 --- a/src/main/java/hudson/plugins/script_realm/ScriptSecurityRealm.java +++ b/src/main/java/hudson/plugins/script_realm/ScriptSecurityRealm.java @@ -71,12 +71,11 @@ public class ScriptSecurityRealm extends AbstractPasswordBasedSecurityRealm { private static final Logger LOGGER = Logger.getLogger(ScriptSecurityRealm.class.getName()); - /** Strategy : call the global resolve method (let Jenkins choose) */ + /** Strategy : call the global resolve method (use Jenkins's default behavior, i.e. calling all found resolvers) */ private static final String OPTION_RESOLVER_ANYSTRATEGY = "*"; - /** Strategy : don't resolve */ + /** Strategy : will disable resolving if selected */ private static final String OPTION_RESOLVER_NONESTRATEGY = ""; - public final String commandLine; public final String groupsCommandLine; public final String groupsDelimiter; @@ -158,32 +157,42 @@ public class ScriptSecurityRealm extends AbstractPasswordBasedSecurityRealm { } public ListBoxModel doFillEmailResolverItems() { + ListBoxModel items = new ListBoxModel(); + + // 1. The following 2 entries are always available, so this parameter doesn't have to be changed whenever resolvers are added or removed + items.add(new Option(Messages.ScriptSecurityRealm_EmailResolver_nonestrategy_label(),OPTION_RESOLVER_NONESTRATEGY)); + items.add(new Option(Messages.ScriptSecurityRealm_EmailResolver_anystrategy_label(),OPTION_RESOLVER_ANYSTRATEGY)); + + // 2. Adds all found e-mail resolvers as options so the user can select one of them ExtensionList mars = MailAddressResolver.all(); - items.add(new Option(Messages.ScriptSecurityRealm_EmailResolver_nonestrategy_label(),OPTION_RESOLVER_NONESTRATEGY)); // This entry will disable resolving if selected if ( ! mars.isEmpty() ) { - items.add(new Option(Messages.ScriptSecurityRealm_EmailResolver_anystrategy_label(),OPTION_RESOLVER_ANYSTRATEGY)); // This entry will use Jenkins's default behavior (calling all found resolvers) - // Adds all found e-mail resolvers as options so the user can select one of them for (MailAddressResolver mar : mars) { // class name is used both as label and value items.add(mar.getClass().getCanonicalName(),mar.getClass().getName()); } } + return items; } public ListBoxModel doFillNameResolverItems() { + ListBoxModel items = new ListBoxModel(); + + // 1. The following 2 entries are always available, so this parameter doesn't have to be changed whenever resolvers are added or removed + items.add(new Option(Messages.ScriptSecurityRealm_NameResolver_nonestrategy_label(),OPTION_RESOLVER_NONESTRATEGY)); + items.add(new Option(Messages.ScriptSecurityRealm_NameResolver_anystrategy_label(),OPTION_RESOLVER_ANYSTRATEGY)); + + // 2. Adds all found name resolvers as options so the user can select one of them ExtensionList unrs = UserNameResolver.all(); - items.add(new Option(Messages.ScriptSecurityRealm_NameResolver_nonestrategy_label(),OPTION_RESOLVER_NONESTRATEGY)); // This entry will disable resolving if selected if ( ! unrs.isEmpty() ) { - items.add(new Option(Messages.ScriptSecurityRealm_NameResolver_anystrategy_label(),OPTION_RESOLVER_ANYSTRATEGY)); // This entry will use Jenkins's default behavior (calling all found resolvers) - // Adds all found name resolvers as options so the user can select one of them for (UserNameResolver unr : unrs) { // class name is used both as label and value items.add(unr.getClass().getCanonicalName(),unr.getClass().getName()); } } + return items; } }