KEYCLOAK-2686 - Fix failing migration from 1.9.1 to 1.9.2.
Since the `Map` returned by `realm.getBrowserSecurityHeaders()` is unmodifiable we need to add the new header setting to a copy of the map which we then set on the realm.
This commit is contained in:
parent
5c98b8c6ae
commit
fa8af64098
1 changed files with 9 additions and 2 deletions
|
@ -18,10 +18,13 @@
|
||||||
package org.keycloak.migration.migrators;
|
package org.keycloak.migration.migrators;
|
||||||
|
|
||||||
import org.keycloak.migration.ModelVersion;
|
import org.keycloak.migration.ModelVersion;
|
||||||
import org.keycloak.models.BrowserSecurityHeaders;
|
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MigrateTo1_9_2 {
|
public class MigrateTo1_9_2 {
|
||||||
|
|
||||||
public static final ModelVersion VERSION = new ModelVersion("1.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) {
|
public void migrate(KeycloakSession session) {
|
||||||
for (RealmModel realm : session.realms().getRealms()) {
|
for (RealmModel realm : session.realms().getRealms()) {
|
||||||
if (realm.getBrowserSecurityHeaders() != null) {
|
if (realm.getBrowserSecurityHeaders() != null) {
|
||||||
realm.getBrowserSecurityHeaders().put("xFrameOptions", "nosniff");
|
|
||||||
|
Map<String, String> browserSecurityHeaders = new HashMap<>(realm.getBrowserSecurityHeaders());
|
||||||
|
browserSecurityHeaders.put("xFrameOptions", "nosniff");
|
||||||
|
|
||||||
|
realm.setBrowserSecurityHeaders(Collections.unmodifiableMap(browserSecurityHeaders));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue