use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.
the class UpdateUserLocaleAction method evaluateTriggers.
@Override
public void evaluateTriggers(RequiredActionContext context) {
String userRequestedLocale = context.getAuthenticationSession().getAuthNote(LocaleSelectorProvider.USER_REQUEST_LOCALE);
if (userRequestedLocale != null) {
LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
updater.updateUsersLocale(context.getUser(), userRequestedLocale);
} else {
String userLocale = context.getUser().getFirstAttribute(UserModel.LOCALE);
if (userLocale != null) {
LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
updater.updateLocaleCookie(userLocale);
} else {
LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
updater.expireLocaleCookie();
}
}
}
use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.
the class AccountFormService method forwardToPage.
private Response forwardToPage(String path, AccountPages page) {
if (auth != null) {
try {
auth.require(AccountRoles.MANAGE_ACCOUNT);
} catch (ForbiddenException e) {
return session.getProvider(LoginFormsProvider.class).setError(Messages.NO_ACCESS).createErrorPage(Response.Status.FORBIDDEN);
}
setReferrerOnPage();
UserSessionModel userSession = auth.getSession();
String tabId = session.getContext().getUri().getQueryParameters().getFirst(org.keycloak.models.Constants.TAB_ID);
if (tabId != null) {
AuthenticationSessionModel authSession = new AuthenticationSessionManager(session).getAuthenticationSessionByIdAndClient(realm, userSession.getId(), client, tabId);
if (authSession != null) {
String forwardedError = authSession.getAuthNote(ACCOUNT_MGMT_FORWARDED_ERROR_NOTE);
if (forwardedError != null) {
try {
FormMessage errorMessage = JsonSerialization.readValue(forwardedError, FormMessage.class);
account.setError(Response.Status.INTERNAL_SERVER_ERROR, errorMessage.getMessage(), errorMessage.getParameters());
authSession.removeAuthNote(ACCOUNT_MGMT_FORWARDED_ERROR_NOTE);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
}
}
String locale = session.getContext().getUri().getQueryParameters().getFirst(LocaleSelectorProvider.KC_LOCALE_PARAM);
if (locale != null) {
LocaleUpdaterProvider updater = session.getProvider(LocaleUpdaterProvider.class);
updater.updateUsersLocale(auth.getUser(), locale);
}
return account.createResponse(page);
} else {
return login(path);
}
}
use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.
the class LoginActionsService method processLocaleParam.
protected void processLocaleParam(AuthenticationSessionModel authSession) {
if (authSession != null && realm.isInternationalizationEnabled()) {
String locale = session.getContext().getUri().getQueryParameters().getFirst(LocaleSelectorProvider.KC_LOCALE_PARAM);
if (locale != null) {
authSession.setAuthNote(LocaleSelectorProvider.USER_REQUEST_LOCALE, locale);
LocaleUpdaterProvider localeUpdater = session.getProvider(LocaleUpdaterProvider.class);
localeUpdater.updateLocaleCookie(locale);
}
}
}
Aggregations