KEYCLOAK-6115 Login fails if federated user is read-only and has selected a locale on the login screen

This commit is contained in:
Peter Skopek 2019-12-12 10:41:17 +01:00 committed by Stian Thorgersen
parent 946088d48d
commit 7a14661fce

View file

@ -16,12 +16,14 @@
*/
package org.keycloak.locale;
import org.jboss.logging.Logger;
import org.keycloak.OAuth2Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.util.CookieHelper;
import org.keycloak.storage.ReadOnlyException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriInfo;
@ -29,6 +31,8 @@ import java.util.Locale;
public class DefaultLocaleSelectorProvider implements LocaleSelectorProvider {
private static final Logger logger = Logger.getLogger(DefaultLocaleSelectorProvider.class);
protected static final String LOCALE_COOKIE = "KEYCLOAK_LOCALE";
protected static final String KC_LOCALE_PARAM = "kc_locale";
@ -153,7 +157,11 @@ public class DefaultLocaleSelectorProvider implements LocaleSelectorProvider {
protected void updateUsersLocale(UserModel user, String locale) {
if (!locale.equals(user.getFirstAttribute("locale"))) {
user.setSingleAttribute(UserModel.LOCALE, locale);
try {
user.setSingleAttribute(UserModel.LOCALE, locale);
} catch (ReadOnlyException e) {
logger.debug("Attempt to store 'locale' attribute to read only user model. Ignoring exception", e);
}
}
}