8000 Brute Force Detection is disabled when updating frontenUrl via admin client by douglaspalmer · Pull Request #26718 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.keycloak.models.utils.DefaultKeyProviders;
import org.keycloak.models.utils.DefaultRequiredActions;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.models.utils.RepresentationToModel;
import org.keycloak.partialimport.PartialImportResults;
import org.keycloak.protocol.oidc.OIDCConfigAttributes;
Expand Down Expand Up @@ -714,6 +715,7 @@ public void updateRealm(RealmRepresentation rep, RealmModel realm) {
if (rep.getAttributes() != null) {
Set<String> attrsToRemove = new HashSet<>(realm.getAttributes().keySet());
attrsToRemove.removeAll(rep.getAttributes().keySet());
attrsToRemove.removeAll(ModelToRepresentation.REALM_EXCLUDED_ATTRIBUTES);

for (Map.Entry<String, String> entry : rep.getAttributes().entrySet()) {
realm.setAttribute(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -813,11 +815,15 @@ public void updateRealm(RealmRepresentation rep, RealmModel realm) {
realm.setPasswordPolicy(PasswordPolicy.parse(session, rep.getPasswordPolicy()));
if (rep.getOtpPolicyType() != null) realm.setOTPPolicy(toPolicy(rep));

WebAuthnPolicy webAuthnPolicy = getWebAuthnPolicyTwoFactor(rep);
realm.setWebAuthnPolicy(webAuthnPolicy);
if (rep.getWebAuthnPolicyRpEntityName() != null && !rep.getWebAuthnPolicyRpEntityName().isEmpty()) {
Comment thread
pedroigor marked this conversation as resolved.
Resolved
WebAuthnPolicy webAuthnPolicy = getWebAuthnPolicyTwoFactor(rep);
realm.setWebAuthnPolicy(webAuthnPolicy);
}

webAuthnPolicy = getWebAuthnPolicyPasswordless(rep);
realm.setWebAuthnPolicyPasswordless(webAuthnPolicy);
if (rep.getWebAuthnPolicyPasswordlessRpEntityName() != null && !rep.getWebAuthnPolicyPasswordlessRpEntityName().isEmpty()) {
WebAuthnPolicy webAuthnPolicy = getWebAuthnPolicyPasswordless(rep);
realm.setWebAuthnPolicyPasswordless(webAuthnPolicy);
}

updateCibaSettings(rep, realm);
updateParSettings(rep, realm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,101 @@ public void excludesFieldsFromAttributes() {
assertThat(attributesKeys, CoreMatchers.is(expectedAttributes));
}

/**
* Checks attributes exposed as fields are not deleted on update realm
*/
@Test
public void testFieldNotErased() {
Long dummyLong = Long.valueOf(999);
Integer dummyInt = Integer.valueOf(999);

RealmRepresentation rep = new RealmRepresentation();
rep.setRealm("attributes");
rep.setDisplayName("DISPLAY_NAME");
rep.setDisplayNameHtml("DISPLAY_NAME_HTML");
rep.setDefaultSignatureAlgorithm("RS256");
rep.setBruteForcePr 10BC8 otected(true);
rep.setPermanentLockout(true);
rep.setMaxFailureWaitSeconds(dummyInt);
rep.setWaitIncrementSeconds(dummyInt);
rep.setQuickLoginCheckMilliSeconds(dummyLong);
rep.setMinimumQuickLoginWaitSeconds(dummyInt);
rep.setMaxDeltaTimeSeconds(dummyInt);
rep.setFailureFactor(dummyInt);
rep.setActionTokenGeneratedByAdminLifespan(dummyInt);
rep.setActionTokenGeneratedByUserLifespan(dummyInt);
rep.setOfflineSessionMaxLifespanEnabled(true);
rep.setOfflineSessionMaxLifespan(dummyInt);

rep.setWebAuthnPolicyRpEntityName("RP_ENTITY_NAME");
rep.setWebAuthnPolicySignatureAlgorithms(Collections.singletonList("RS256"));
rep.setWebAuthnPolicyRpId("localhost");
rep.setWebAuthnPolicyAttestationConveyancePreference("Direct");
rep.setWebAuthnPolicyAuthenticatorAttachment("Platform");
rep.setWebAuthnPolicyRequireResidentKey("Yes");
rep.setWebAuthnPolicyUserVerificationRequirement("Required");
rep.setWebAuthnPolicyCreateTimeout(dummyInt);
rep.setWebAuthnPolicyAvoidSameAuthenticatorRegister(true);
rep.setWebAuthnPolicyAcceptableAaguids(Collections.singletonList("00000000-0000-0000-0000-000000000000"));

rep.setWebAuthnPolicyPasswordlessRpEntityName("RP_ENTITY_NAME");
rep.setWebAuthnPolicyPasswordlessSignatureAlgorithms(Collections.singletonList("RS256"));
rep.setWebAuthnPolicyPasswordlessRpId("localhost");
rep.setWebAuthnPolicyPasswordlessAttestationConveyancePreference("Direct");
rep.setWebAuthnPolicyPasswordlessAuthenticatorAttachment("Platform");
rep.setWebAuthnPolicyPasswordlessRequireResidentKey("Yes");
rep.setWebAuthnPolicyPasswordlessUserVerificationRequirement("Required");
rep.setWebAuthnPolicyPasswordlessCreateTimeout(dummyInt);
rep.setWebAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister(true);
rep.setWebAuthnPolicyPasswordlessAcceptableAaguids(Collections.singletonList("00000000-0000-0000-0000-000000000000"));

adminClient.realms().create(rep);
getCleanup().addCleanup(() -> adminClient.realms().realm("attributes").remove());

RealmRepresentation rep2 = new RealmRepresentation();
rep2.setAttributes(Collections.singletonMap("frontendUrl", "http://localhost/frontEnd"));
adminClient.realm("attributes").update(rep2);

rep = adminClient.realm("attributes").toRepresentation();
assertEquals("DISPLAY_NAME", rep.getDisplayName());
assertEquals("DISPLAY_NAME_HTML", rep.getDisplayNameHtml());
assertEquals("RS256", rep.getDefaultSignatureAlgorithm());
assertTrue(rep.isBruteForceProtected());
assertTrue(rep.isPermanentLockout());
assertEquals(dummyInt, rep.getMaxFailureWaitSeconds());
assertEquals(dummyInt, rep.getWaitIncrementSeconds());
assertEquals(dummyLong, rep.getQuickLoginCheckMilliSeconds());
assertEquals(dummyInt, rep.getMinimumQuickLoginWaitSeconds());
assertEquals(dummyInt, rep.getMaxDeltaTimeSeconds());
assertEquals(dummyInt, rep.getFailureFactor());
assertEquals(dummyInt, rep.getActionTokenGeneratedByAdminLifespan());
assertEquals(dummyInt, rep.getActionTokenGeneratedByUserLifespan());
assertTrue(rep.getOfflineSessionMaxLifespanEnabled());
assertEquals(dummyInt, rep.getOfflineSessionMaxLifespan());

assertEquals("RP_ENTITY_NAME", rep.getWebAuthnPolicyRpEntityName());
assertEquals(Collections.singletonList("RS256"), rep.getWebAuthnPolicySignatureAlgorithms());
assertEquals("localhost", rep.getWebAuthnPolicyRpId());
assertEquals("Direct", rep.getWebAuthnPolicyAttestationConveyancePreference());
assertEquals("Platform", rep.getWebAuthnPolicyAuthenticatorAttachment());
assertEquals("Yes", rep.getWebAuthnPolicyRequireResidentKey());
assertEquals("Required", rep.getWebAuthnPolicyUserVerificationRequirement());
assertEquals(dummyInt, rep.getWebAuthnPolicyCreateTimeout());
assertTrue(rep.isWebAuthnPolicyAvoidSameAuthenticatorRegister());
assertEquals(Collections.singletonList("00000000-0000-0000-0000-000000000000"), rep.getWebAuthnPolicyAcceptableAaguids());

assertEquals("RP_ENTITY_NAME", rep.getWebAuthnPolicyPasswordlessRpEntityName());
assertEquals(Collections.singletonList("RS256"), rep.getWebAuthnPolicyPasswordlessSignatureAlgorithms());
assertEquals("localhost", rep.getWebAuthnPolicyPasswordlessRpId());
assertEquals("Direct", rep.getWebAuthnPolicyPasswordlessAttestationConveyancePreference());
assertEquals("Platform", rep.getWebAuthnPolicyPasswordlessAuthenticatorAttachment());
assertEquals("Yes", rep.getWebAuthnPolicyPasswordlessRequireResidentKey());
assertEquals("Required", rep.getWebAuthnPolicyPasswordlessUserVerificationRequirement());
assertEquals(dummyInt, rep.getWebAuthnPolicyPasswordlessCreateTimeout());
assertTrue(rep.isWebAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister());
assertEquals(Collections.singletonList("00000000-0000-0000-0000-000000000000"), rep.getWebAuthnPolicyPasswordlessAcceptableAaguids());
}

@Test
public void smtpPasswordSecret() {
RealmRepresentation rep = RealmBuilder.create().testEventListener().testMail().build();
Expand Down Expand Up @@ -563,6 +658,7 @@ public void updateRealmAttributes() {
rep.getAttributes().put("foo1", "bar1");
rep.getAttributes().put("foo2", "bar2");

rep.setWebAuthnPolicyRpEntityName("keycloak");
rep.setWebAuthnPolicyAcceptableAaguids(webAuthnPolicyAcceptableAaguids);
rep.setBruteForceProtected(true);
rep.setDisplayName("dn1");
Expand Down
0