Search in sources :

Example 11 with PasswordPolicyManagerProvider

use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.

the class PasswordPolicyTest method testBlacklistPasswordPolicyWithTestBlacklist.

/**
 * KEYCLOAK-5244
 */
@Test
public void testBlacklistPasswordPolicyWithTestBlacklist() throws Exception {
    ContainerAssume.assumeNotAuthServerRemote();
    testingClient.server("passwordPolicy").run(session -> {
        RealmModel realmModel = session.getContext().getRealm();
        PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
        realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "passwordBlacklist(test-password-blacklist.txt)"));
        Assert.assertEquals(BlacklistPasswordPolicyProvider.ERROR_MESSAGE, policyManager.validate("jdoe", "blacklisted1").getMessage());
        Assert.assertEquals(BlacklistPasswordPolicyProvider.ERROR_MESSAGE, policyManager.validate("jdoe", "blacklisted2").getMessage());
        Assert.assertEquals(BlacklistPasswordPolicyProvider.ERROR_MESSAGE, policyManager.validate("jdoe", "bLaCkLiSteD2").getMessage());
        assertNull(policyManager.validate("jdoe", "notblacklisted"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Aggregations

Test (org.junit.Test)11 RealmModel (org.keycloak.models.RealmModel)11 PasswordPolicyManagerProvider (org.keycloak.policy.PasswordPolicyManagerProvider)11 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)11 ModelException (org.keycloak.models.ModelException)2 PasswordPolicy (org.keycloak.models.PasswordPolicy)1