Fix BlacklistPasswordPolicyDefaultPath Failures on Windows

Fixes #11967
This commit is contained in:
Martin Bartoš 2022-05-24 16:27:18 +02:00 committed by Pedro Igor
parent bb3b88963b
commit 86f31e8df5
3 changed files with 11 additions and 5 deletions

View file

@ -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;
/**
* <p>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;
}
}

View file

@ -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<String, FileBasedPasswordBlacklist> 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;
}
/**

View file

@ -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<PasswordPolicyProvider> 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));
});
}