From b3f6db0289bdb5c2b25d1d463bf221b56b12082d Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Mon, 28 Oct 2024 14:00:03 +0200 Subject: [PATCH] minor fixes of deprecated methods --- .../main/java/com/erudika/para/core/utils/Para.java | 2 +- .../main/java/com/erudika/para/core/utils/Utils.java | 11 ++++++----- .../para/server/security/filters/SAMLAuthFilter.java | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/para-core/src/main/java/com/erudika/para/core/utils/Para.java b/para-core/src/main/java/com/erudika/para/core/utils/Para.java index 6e86091b..c01fa040 100644 --- a/para-core/src/main/java/com/erudika/para/core/utils/Para.java +++ b/para-core/src/main/java/com/erudika/para/core/utils/Para.java @@ -369,7 +369,7 @@ public static ClassLoader getParaClassLoader() { jars.add(file.toURI().toURL()); } } - paraClassLoader = new URLClassLoader(jars.toArray(new URL[0]), currentClassLoader); + paraClassLoader = new URLClassLoader(jars.toArray(URL[]::new), currentClassLoader); // Thread.currentThread().setContextClassLoader(paraClassLoader); } catch (Exception e) { logger.error(null, e); diff --git a/para-core/src/main/java/com/erudika/para/core/utils/Utils.java b/para-core/src/main/java/com/erudika/para/core/utils/Utils.java index 96e89598..9209cc47 100644 --- a/para-core/src/main/java/com/erudika/para/core/utils/Utils.java +++ b/para-core/src/main/java/com/erudika/para/core/utils/Utils.java @@ -39,6 +39,7 @@ import com.vladsch.flexmark.util.data.MutableDataHolder; import com.vladsch.flexmark.util.data.MutableDataSet; import com.vladsch.flexmark.util.html.MutableAttributes; +import jakarta.validation.constraints.NotNull; import java.io.IOException; import java.io.StringWriter; import java.io.UnsupportedEncodingException; @@ -48,6 +49,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; @@ -68,7 +70,6 @@ import java.util.regex.Pattern; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import jakarta.validation.constraints.NotNull; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.LocaleUtils; import org.apache.commons.lang3.StringUtils; @@ -561,9 +562,9 @@ public void setAttributes(@NotNull Node node, @NotNull AttributablePart part, @N private Boolean isIgnoredDomain(String value) { try { - var href = new URL(value); + var href = new URI(value).toURL(); return Arrays.binarySearch(Para.getConfig().markdownAllowFollowDomains(), href.getHost()) >= 0; - } catch (MalformedURLException e) { + } catch (MalformedURLException | URISyntaxException e) { return false; } } @@ -813,8 +814,8 @@ private static URL toURL(String url) { } URL u; try { - u = new URL(url); - } catch (MalformedURLException e) { + u = new URI(url).toURL(); + } catch (MalformedURLException | URISyntaxException e) { // the URL is not in a valid form u = null; } diff --git a/para-server/src/main/java/com/erudika/para/server/security/filters/SAMLAuthFilter.java b/para-server/src/main/java/com/erudika/para/server/security/filters/SAMLAuthFilter.java index 32a1e868..b56c15fa 100644 --- a/para-server/src/main/java/com/erudika/para/server/security/filters/SAMLAuthFilter.java +++ b/para-server/src/main/java/com/erudika/para/server/security/filters/SAMLAuthFilter.java @@ -53,7 +53,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.security.spec.InvalidKeySpecException; import java.util.Collections; import java.util.HashMap; @@ -124,7 +124,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ if (StringUtils.isBlank(idpMetaUrl)) { samlSettings = getSAMLSettings(app); } else { - samlSettings = parseRemoteXML(new URL(idpMetaUrl), request.getParameter("entityid")); + samlSettings = parseRemoteXML(new URI(idpMetaUrl).toURL(), request.getParameter("entityid")); samlSettings.putAll(getSAMLSettings(app)); // override IDP meta with config values }