KEYCLOAK-5244 Add BlacklistPasswordPolicyProvider (#4370)
* KEYCLOAK-5244 Add BlacklistPasswordPolicyProvider This introduces a new PasswordPolicy which can refer to a named predefined password-blacklist to avoid users choosing too easy to guess passwords. The BlacklistPasswordPolicyProvider supports built-in as well as custom blacklists. built-in blacklists use the form `default/filename` and custom ones `custom/filename`, where filename is the name of the found blacklist-filename. I'd propose to use some of the freely available password blacklists from the [SecLists](https://github.com/danielmiessler/SecLists/tree/master/Passwords) project. For testing purposes one can download the password blacklist ``` wget -O 10_million_password_list_top_1000000.txt https://github.com/danielmiessler/SecLists/blob/master/Passwords/10_million_password_list_top_1000000.txt?raw=true ``` to /data/keycloak/blacklists/ Custom password policies can be configured with the SPI configuration mechanism via jboss-cli: ``` /subsystem=keycloak-server/spi=password-policy:add() /subsystem=keycloak-server/spi=password-policy/provider=passwordBlacklist:add(enabled=true) /subsystem=keycloak-server/spi=password-policy/provider=passwordBlacklist:write-attribute(name=properties.blacklistsFolderUri, value=file:///data/keycloak/blacklists/) ``` Password blacklist is stored in a TreeSet. * KEYCLOAK-5244 Encode PasswordBlacklist as a BloomFilter We now use a dynamically sized BloomFilter with a false positive probability of 1% as a backing store for PasswordBlacklists. BloomFilter implementation is provided by google-guava which is available in wildfly. Password blacklist files are now resolved against the ${jboss.server.data.dir}/password-blacklists. This can be overridden via system property, or SPI config. See JavaDoc of BlacklistPasswordPolicyProviderFactory for details. Revised implementation to be more extensible, e.g. it could be possible to use other stores like databases etc. Moved FileSystem specific methods to FileBasesPasswordBlacklistPolicy. The PasswordBlacklistProvider uses the guava version 20.0 shipped with wildfly. Unfortunately the arquillian testsuite transitively depends on guava 23.0 via the selenium-3.5.1 dependency. Hence we need to use version 23.0 for tests but 20.0 for the policy provider to avoid NoClassDefFoundErrors in the server-dist. Configure password blacklist folder for tests * KEYCLOAK-5244 Configure jboss.server.data.dir for test servers * KEYCLOAK-5244 Translate blacklisted message in base/login
This commit is contained in:
1 parent
fe76b2428b
commit
3103e0fd0a
17 files changed
+515
-9
No files matched your search
@@ -40,17 +40,18 @@ import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.testsuite.util.cli.TestsuiteCLI;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.servlet.DispatcherType;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
@@ -58,6 +59,7 @@ import javax.net.ssl.SSLContext;
|
||||
public class KeycloakServer {
|
||||
|
||||
private static final Logger log = Logger.getLogger(KeycloakServer.class);
|
||||
public static final String JBOSS_SERVER_DATA_DIR = "jboss.server.data.dir";
|
||||
|
||||
private boolean sysout = false;
|
||||
|
||||
@@ -211,6 +213,8 @@ public class KeycloakServer {
|
||||
config.setWorkerThreads(undertowWorkerThreads);
|
||||
}
|
||||
|
||||
configureDataDirectory();
|
||||
|
||||
detectNodeName(config);
|
||||
|
||||
final KeycloakServer keycloak = new KeycloakServer(config);
|
||||
@@ -241,6 +245,52 @@ public class KeycloakServer {
|
||||
return keycloak;
|
||||
}
|
||||
|
||||
public static void configureDataDirectory() {
|
||||
String dataPath = detectDataDirectory();
|
||||
System.setProperty(JBOSS_SERVER_DATA_DIR, dataPath);
|
||||
log.infof("Using %s %s", JBOSS_SERVER_DATA_DIR, dataPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects the {@code jboss.server.data.dir} to use.
|
||||
* If the System property {@code jboss.server.data.dir} is already set then the property value is used,
|
||||
* otherwise a temporary data dir is created that will be deleted on JVM exit.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String detectDataDirectory() {
|
||||
|
||||
String dataPath = System.getProperty(JBOSS_SERVER_DATA_DIR);
|
||||
|
||||
if (dataPath != null){
|
||||
// we assume jboss.server.data.dir is managed externally so just use it as is.
|
||||
File dataDir = new File(dataPath);
|
||||
if (!dataDir.exists() || !dataDir.isDirectory()) {
|
||||
throw new RuntimeException("Invalid " + JBOSS_SERVER_DATA_DIR + " resources directory: " + dataPath);
|
||||
}
|
||||
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
// we generate a dynamic jboss.server.data.dir and remove it at the end.
|
||||
try {
|
||||
File tempKeycloakFolder = Files.createTempDirectory("keycloak-server-").toFile();
|
||||
File tmpDataDir = new File(tempKeycloakFolder, "/data");
|
||||
|
||||
if (tmpDataDir.mkdirs()) {
|
||||
tmpDataDir.deleteOnExit();
|
||||
} else {
|
||||
throw new IOException("Could not create directory " + tmpDataDir);
|
||||
}
|
||||
|
||||
dataPath = tmpDataDir.getAbsolutePath();
|
||||
} catch (IOException ioe){
|
||||
throw new RuntimeException("Could not create temporary " + JBOSS_SERVER_DATA_DIR, ioe);
|
||||
}
|
||||
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
private KeycloakServerConfig config;
|
||||
|
||||
private KeycloakSessionFactory sessionFactory;
|
||||
|
||||
Reference in new issue
Block a user