From 57d541156f0021540c491a9f1ebf875dce7d3a65 Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:52:19 +0000 Subject: [PATCH] Merge branch 'master' into command-palette --- core/src/main/java/hudson/Functions.java | 22 ++ .../main/java/hudson/model/Descriptor.java | 6 + .../main/java/hudson/model/UpdateSite.java | 2 +- .../security/HudsonPrivateSecurityRealm.java | 4 + .../lib/layout/header/searchbox.jelly | 13 +- .../lib/layout/keyboard-shortcut.jelly | 70 +++++ .../resources/lib/layout/search-bar.jelly | 4 +- .../lib/layout/search-bar.properties | 23 ++ .../lib/layout/search-bar_pl.properties | 2 +- .../lib/layout/search-bar_pt_BR.properties | 2 +- eslint.config.cjs | 2 + package.json | 14 +- pom.xml | 6 +- .../js/components/dropdowns/autocomplete.js | 27 +- src/main/scss/components/_tooltips.scss | 67 +++++ src/main/scss/form/_search-bar.scss | 43 +-- test/pom.xml | 2 +- .../HudsonPrivateSecurityRealmFIPSTest.java | 84 ++++++ yarn.lock | 262 +++++++++--------- 19 files changed, 472 insertions(+), 183 deletions(-) create mode 100644 core/src/main/resources/lib/layout/keyboard-shortcut.jelly create mode 100644 core/src/main/resources/lib/layout/search-bar.properties diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 510d4b9b0ec4..668444b14bd5 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -125,6 +125,7 @@ import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.DecimalFormat; +import java.text.MessageFormat; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; @@ -2582,4 +2583,25 @@ public static String generateItemId() { public static ExtensionList getSearchFactories() { return SearchFactory.all(); } + + /** + * @param keyboardShortcut the shortcut to be translated + * @return the translated shortcut, e.g. CMD+K to ⌘+K for macOS, CTRL+K for Windows + */ + @Restricted(NoExternalUse.class) + public static String translateModifierKeysForUsersPlatform(String keyboardShortcut) { + StaplerRequest2 currentRequest = Stapler.getCurrentRequest2(); + currentRequest.getWebApp().getDispatchValidator().allowDispatch(currentRequest, Stapler.getCurrentResponse2()); + String userAgent = currentRequest.getHeader("User-Agent"); + + List platformsThatUseCommand = List.of("MAC", "IPHONE", "IPAD"); + boolean useCmdKey = platformsThatUseCommand.stream().anyMatch(e -> userAgent.toUpperCase().contains(e)); + + return keyboardShortcut.replace("CMD", useCmdKey ? "⌘" : "CTRL"); + } + + @Restricted(NoExternalUse.class) + public static String formatMessage(String format, Object args) { + return MessageFormat.format(format, args); + } } diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 33c981d657f5..c55b7982695e 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -474,6 +474,12 @@ public void calcAutoCompleteSettings(String field, Map attribute if (method == null) return; // no auto-completion + // build query parameter line by figuring out what should be submitted + List depends = buildFillDependencies(method, new ArrayList<>()); + if (!depends.isEmpty()) { + attributes.put("fillDependsOn", String.join(" ", depends)); + } + attributes.put("autoCompleteUrl", String.format("%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName)); } diff --git a/core/src/main/java/hudson/model/UpdateSite.java b/core/src/main/java/hudson/model/UpdateSite.java index 0e3cc894148a..22764fd403d0 100644 --- a/core/src/main/java/hudson/model/UpdateSite.java +++ b/core/src/main/java/hudson/model/UpdateSite.java @@ -217,7 +217,7 @@ public long getDataTimestamp() { return updateData(DownloadService.loadJSON(new URL(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8))), signatureCheck); } - private FormValidation updateData(String json, boolean signatureCheck) + protected FormValidation updateData(String json, boolean signatureCheck) throws IOException { dataTimestamp = System.currentTimeMillis(); diff --git a/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java b/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java index 1a6ebe66f749..f55576dec4d6 100644 --- a/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java +++ b/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java @@ -839,6 +839,10 @@ public Details newInstance(StaplerRequest2 req, JSONObject formData) throws Form throw new FormException("Please confirm the password by typing it twice", "user.password2"); } + if (FIPS140.useCompliantAlgorithms() && pwd.length() < FIPS_PASSWORD_LENGTH) { + throw new FormException(Messages.HudsonPrivateSecurityRealm_CreateAccount_FIPS_PasswordLengthInvalid(), "user.password"); + } + // will be null if it wasn't encrypted String data = Protector.unprotect(pwd); String data2 = Protector.unprotect(pwd2); diff --git a/core/src/main/resources/lib/layout/header/searchbox.jelly b/core/src/main/resources/lib/layout/header/searchbox.jelly index e1112bbb90c4..033dc2ab0407 100644 --- a/core/src/main/resources/lib/layout/header/searchbox.jelly +++ b/core/src/main/resources/lib/layout/header/searchbox.jelly @@ -5,7 +5,18 @@ -