diff --git a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo1_9_2.java b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo1_9_2.java index 7c1f09722b..7eb1f075dd 100644 --- a/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo1_9_2.java +++ b/server-spi/src/main/java/org/keycloak/migration/migrators/MigrateTo1_9_2.java @@ -18,10 +18,13 @@ package org.keycloak.migration.migrators; import org.keycloak.migration.ModelVersion; -import org.keycloak.models.BrowserSecurityHeaders; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + public class MigrateTo1_9_2 { public static final ModelVersion VERSION = new ModelVersion("1.9.2"); @@ -29,7 +32,11 @@ public class MigrateTo1_9_2 { public void migrate(KeycloakSession session) { for (RealmModel realm : session.realms().getRealms()) { if (realm.getBrowserSecurityHeaders() != null) { - realm.getBrowserSecurityHeaders().put("xFrameOptions", "nosniff"); + + Map browserSecurityHeaders = new HashMap<>(realm.getBrowserSecurityHeaders()); + browserSecurityHeaders.put("xFrameOptions", "nosniff"); + + realm.setBrowserSecurityHeaders(Collections.unmodifiableMap(browserSecurityHeaders)); } } }