From 86f31e8df536ce3bc7c26c5af98b6c398282337c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Barto=C5=A1?= Date: Tue, 24 May 2022 16:27:18 +0200 Subject: [PATCH] Fix BlacklistPasswordPolicyDefaultPath Failures on Windows Fixes #11967 --- .../QuarkusBlacklistPasswordPolicyProviderFactory.java | 4 +++- .../policy/BlacklistPasswordPolicyProviderFactory.java | 5 +++-- .../org/keycloak/testsuite/policy/PasswordPolicyTest.java | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/policy/QuarkusBlacklistPasswordPolicyProviderFactory.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/policy/QuarkusBlacklistPasswordPolicyProviderFactory.java index 02f80f1551..f271290867 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/policy/QuarkusBlacklistPasswordPolicyProviderFactory.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/policy/QuarkusBlacklistPasswordPolicyProviderFactory.java @@ -20,6 +20,8 @@ package org.keycloak.quarkus.runtime.policy; import org.keycloak.policy.BlacklistPasswordPolicyProviderFactory; import org.keycloak.quarkus.runtime.Environment; +import java.io.File; + /** *

Quarkus implementation of the BlacklistPasswordPolicyProviderFactory. The * default path for the list files is calculated using the quarkus environment @@ -31,6 +33,6 @@ public class QuarkusBlacklistPasswordPolicyProviderFactory extends BlacklistPass @Override public String getDefaultBlacklistsBasePath() { - return Environment.getDataDir() + "/" + PASSWORD_BLACKLISTS_FOLDER; + return Environment.getDataDir() + File.separator + PASSWORD_BLACKLISTS_FOLDER; } } diff --git a/server-spi-private/src/main/java/org/keycloak/policy/BlacklistPasswordPolicyProviderFactory.java b/server-spi-private/src/main/java/org/keycloak/policy/BlacklistPasswordPolicyProviderFactory.java index f37531375e..31c9ba87a1 100644 --- a/server-spi-private/src/main/java/org/keycloak/policy/BlacklistPasswordPolicyProviderFactory.java +++ b/server-spi-private/src/main/java/org/keycloak/policy/BlacklistPasswordPolicyProviderFactory.java @@ -25,6 +25,7 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -75,7 +76,7 @@ public class BlacklistPasswordPolicyProviderFactory implements PasswordPolicyPro public static final String JBOSS_SERVER_DATA_DIR = "jboss.server.data.dir"; - public static final String PASSWORD_BLACKLISTS_FOLDER = "password-blacklists/"; + public static final String PASSWORD_BLACKLISTS_FOLDER = "password-blacklists" + File.separator; private ConcurrentMap blacklistRegistry = new ConcurrentHashMap<>(); @@ -142,7 +143,7 @@ public class BlacklistPasswordPolicyProviderFactory implements PasswordPolicyPro * when no other configuration is in place. */ public String getDefaultBlacklistsBasePath() { - return System.getProperty(JBOSS_SERVER_DATA_DIR) + "/" + PASSWORD_BLACKLISTS_FOLDER; + return System.getProperty(JBOSS_SERVER_DATA_DIR) + File.separator + PASSWORD_BLACKLISTS_FOLDER; } /** diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/policy/PasswordPolicyTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/policy/PasswordPolicyTest.java index 869ef4ce4c..69df1630c7 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/policy/PasswordPolicyTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/policy/PasswordPolicyTest.java @@ -35,6 +35,7 @@ import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.A import org.keycloak.testsuite.util.ContainerAssume; import org.keycloak.testsuite.util.RealmBuilder; +import java.io.File; import java.util.List; import static org.hamcrest.CoreMatchers.instanceOf; @@ -192,12 +193,14 @@ public class PasswordPolicyTest extends AbstractKeycloakTest { @Test public void testBlacklistPasswordPolicyDefaultPath() throws Exception { + final String SEPARATOR = File.separator; + testingClient.server("passwordPolicy").run(session -> { ProviderFactory passPolicyFact = session.getKeycloakSessionFactory().getProviderFactory( PasswordPolicyProvider.class, BlacklistPasswordPolicyProviderFactory.ID); assertThat(passPolicyFact, instanceOf(BlacklistPasswordPolicyProviderFactory.class)); - assertThat(((BlacklistPasswordPolicyProviderFactory)passPolicyFact).getDefaultBlacklistsBasePath(), - endsWith("/data/password-blacklists/")); + assertThat(((BlacklistPasswordPolicyProviderFactory) passPolicyFact).getDefaultBlacklistsBasePath(), + endsWith(SEPARATOR + "data" + SEPARATOR + "password-blacklists" + SEPARATOR)); }); }