|
58 | 58 | import java.security.MessageDigest; |
59 | 59 | import java.security.NoSuchAlgorithmException; |
60 | 60 | import java.util.ArrayList; |
61 | | -import java.util.Collections; |
62 | 61 | import java.util.Comparator; |
63 | 62 | import java.util.HashMap; |
64 | 63 | import java.util.Iterator; |
|
76 | 75 |
|
77 | 76 | import edu.umd.cs.findbugs.annotations.CheckForNull; |
78 | 77 | import edu.umd.cs.findbugs.annotations.NonNull; |
79 | | -import java.util.concurrent.atomic.AtomicBoolean; |
80 | 78 | import jenkins.model.Jenkins; |
81 | 79 | import net.sf.json.JSON; |
82 | 80 | import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist; |
@@ -533,7 +531,11 @@ public synchronized void load() { |
533 | 531 | if (changed) { |
534 | 532 | save(); |
535 | 533 | } |
536 | | - ApprovedWhitelist.configurationChanged(); |
| 534 | + try { |
| 535 | + configurationChanged(); |
| 536 | + } catch (IOException x) { |
| 537 | + LOG.log(Level.SEVERE, "Malformed signature entry in scriptApproval.xml: '" + x.getMessage() + "'"); |
| 538 | + } |
537 | 539 | } |
538 | 540 |
|
539 | 541 | private void clear() { |
@@ -967,32 +969,30 @@ public synchronized String[] getApprovedScriptHashes() { |
967 | 969 | return approvedScriptHashes.toArray(new String[approvedScriptHashes.size()]); |
968 | 970 | } |
969 | 971 |
|
| 972 | + private synchronized void configurationChanged() throws IOException { |
| 973 | + // Do not use lookupSingleton: ScriptApprovalLoadingTest.dynamicLoading |
| 974 | + ApprovedWhitelist instance = ExtensionList.lookup(Whitelist.class).get(ApprovedWhitelist.class); |
| 975 | + if (instance == null) { |
| 976 | + throw new IllegalStateException("Failed to find ApprovedWhitelist"); |
| 977 | + } |
| 978 | + LOG.fine("resetting"); |
| 979 | + synchronized (instance) { |
| 980 | + instance.pendingDelegate = new AclAwareWhitelist(new StaticWhitelist(approvedSignatures), new StaticWhitelist(aclApprovedSignatures)); |
| 981 | + } |
| 982 | + } |
| 983 | + |
970 | 984 | @Restricted(NoExternalUse.class) // implementation |
971 | 985 | @Extension public static final class ApprovedWhitelist extends ProxyWhitelist { |
972 | 986 |
|
973 | | - static void configurationChanged() { |
974 | | - // Do not use lookupSingleton: ScriptApprovalLoadingTest.dynamicLoading |
975 | | - ApprovedWhitelist instance = ExtensionList.lookup(Whitelist.class).get(ApprovedWhitelist.class); |
976 | | - if (instance == null) { |
977 | | - throw new IllegalStateException("Failed to find ApprovedWhitelist"); |
978 | | - } |
979 | | - instance.initialized.set(false); |
980 | | - } |
981 | | - |
982 | | - private final AtomicBoolean initialized = new AtomicBoolean(); |
| 987 | + private @CheckForNull Whitelist pendingDelegate; |
983 | 988 |
|
984 | | - @Override protected void beforePermits() { |
985 | | - if (initialized.compareAndSet(false, true)) { |
986 | | - try { |
987 | | - ScriptApproval instance = ScriptApproval.get(); |
988 | | - Whitelist delegate; |
989 | | - synchronized (instance) { |
990 | | - delegate = new AclAwareWhitelist(new StaticWhitelist(instance.approvedSignatures), new StaticWhitelist(instance.aclApprovedSignatures)); |
991 | | - } |
992 | | - reset(Set.of(delegate)); |
993 | | - } catch (IOException e) { |
994 | | - LOG.log(Level.SEVERE, "Malformed signature entry in scriptApproval.xml: '" + e.getMessage() + "'"); |
995 | | - } |
| 989 | + @Override protected synchronized void beforePermits() { |
| 990 | + if (pendingDelegate != null) { |
| 991 | + LOG.fine("refreshing"); |
| 992 | + reset(Set.of(pendingDelegate)); |
| 993 | + pendingDelegate = null; |
| 994 | + } else { |
| 995 | + LOG.finer("no need to refresh"); |
996 | 996 | } |
997 | 997 | } |
998 | 998 |
|
@@ -1136,8 +1136,8 @@ public Set<PendingSignature> getPendingSignatures() { |
1136 | 1136 | return pendingSignatures; |
1137 | 1137 | } |
1138 | 1138 |
|
1139 | | - private String[][] reconfigure() throws IOException { |
1140 | | - ApprovedWhitelist.configurationChanged(); |
| 1139 | + private synchronized String[][] reconfigure() throws IOException { |
| 1140 | + configurationChanged(); |
1141 | 1141 | return new String[][] {getApprovedSignatures(), getAclApprovedSignatures(), getDangerousApprovedSignatures()}; |
1142 | 1142 | } |
1143 | 1143 |
|
|
0 commit comments